From 59cb3d350ec908206e4ac6784ff962b40e0d24ef Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Sat, 11 Sep 2010 23:24:46 +0200 Subject: [PATCH] list of modules in mobundle and other little changes --- mobundle | 113 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/mobundle b/mobundle index 5725c34..c415211 100755 --- a/mobundle +++ b/mobundle @@ -21,6 +21,7 @@ GetOptions( qw( usage help man version autoscan|scan|a! + autoscan-list|scan-list|l! body|b=s body-from|script|program|B=s head|h=s @@ -57,13 +58,39 @@ pod2usage( $config{head} = read_file($config{'head-from'}) if exists $config{'head-from'}; +# Get body +if (@ARGV) { + pod2usage( + message => "body and bare parameter are mutually exclusive", + -verbose => 99, + -sections => '' + ) if exists $config{body}; + pod2usage( + message => "body-from and bare parameter are mutually exclusive", + -verbose => 99, + -sections => '' + ) if exists($config{'body-from'}); + pod2usage( + message => "only one bare command line parameter is allowed", + -verbose => 99, + -sections => '' + ) if @ARGV > 1; + $config{'body-from'} = shift @ARGV; +} +if (exists $config{'body-from'}) { + pod2usage( + message => "body and body-from are mutually exclusive", + -verbose => 99, + -sections => '' + ) if exists $config{body}; + $config{body} = read_file($config{'body-from'}) +} pod2usage( - message => "body and body-from are mutually exclusive", + message => "one between body, body-from or bare parameter is needed", -verbose => 99, -sections => '' -) if exists($config{body}) && exists($config{'body-from'}); -$config{body} = read_file($config{'body-from'}) - if exists $config{'body-from'}; +) unless exists $config{body}; + if (exists $config{'head-from-body'}) { pod2usage( @@ -102,7 +129,7 @@ my %modules = map { } @{$config{modules}}; # Now autoscan if requested. Already-loaded modules will be skipped -if ($config{autoscan}) { +if ($config{autoscan} || $config{'autoscan-list'}) { require Module::ScanDeps; require File::Temp; require Config; @@ -112,22 +139,39 @@ if ($config{autoscan}) { print {$fh} $config{body}; $fh->close(); - my $filename = $fh->filename(); - my $deps_for = - Module::ScanDeps::scan_deps(files => [$filename], skip => {%modules}); - - my $priv = dir($Config::Config{privlib}); - my $arch = dir($Config::Config{archlib}); - while (my ($key, $mod) = each %$deps_for) { - # Restrict to modules... - next unless $mod->{type} eq 'module'; - - my $privPath = $priv->file($key)->as_foreign('Unix'); - my $archPath = $arch->file($key)->as_foreign('Unix'); - next if $mod->{file} eq $privPath || $mod->{file} eq $archPath; - - $modules{$key} = read_file($mod->{file}); - } ## end while (my ($key, $mod) = ... + my @filenames = $fh->filename(); + my %flag_for; + while (@filenames) { + my $filename = shift @filenames; + next if $flag_for{$filename}++; + my $deps_for = + Module::ScanDeps::scan_deps(files => [$filename], skip => {%modules}); + + my $priv = dir($Config::Config{privlib}); + my $arch = dir($Config::Config{archlib}); + while (my ($key, $mod) = each %$deps_for) { + next if exists $modules{$key}; + + # Restrict to modules... + next unless $mod->{type} eq 'module'; + + my $privPath = $priv->file($key)->as_foreign('Unix'); + my $archPath = $arch->file($key)->as_foreign('Unix'); + next if $mod->{file} eq $privPath || $mod->{file} eq $archPath; + + $modules{$key} = read_file($mod->{file}); + push @filenames, $mod->{file}; + } ## end while (my ($key, $mod) = ... + } + + if ($config{'autoscan-list'}) { + for my $path (sort keys %modules) { + (my $name = $path) =~ s/\.pm$//; + $name =~ s{/}{::}g; + print "$name\n"; + } + exit 0; + } } ## end if ($config{autoscan}) $config{modules} = \%modules; @@ -196,20 +240,29 @@ Ask the version number to the script itself, calling: mobundle [--usage] [--help] [--man] [--version] - mobundle [--autoscan|--scan|-a] [--body|-b ] + mobundle [--autoscan|--scan|-a] + [--autoscan-list|--scanlist|-l] + [--body|-b ] [--body-from|--script|--program|-B ] [--head|-h ] [--head-from|-H ] - [--head-from-body|-S ] [--head-from-paragraph|-P] - [--module|-m ] [--modules-from|-M ] - [--output|-o ] [--standard-head|-s] + [--head-from-body|-S ] + [--head-from-paragraph|-P] + [--module|-m ] + [--modules-from|-M ] + [--output|-o ] + [--standard-head|-s] =head1 EXAMPLES - shell$ mobundle -m Template::Perlish -B yourscript.pl + shell$ mobundle -m Template::Perlish yourscript.pl + + shell$ mobundle -m Template::Perlish --head '#!/path/to/perl' yscript.pl - shell$ mobundle -m Template::Perlish --head '#!/path/to/perl' -B yscript.pl + shell$ mobundle -m Acme::Laugh --head-from-paragraph laugh.pl - shell$ mobundle -m Acme::Laugh --head-from-paragraph -B laugh.pl + # This lists all the modules that mobundle would include with + # --autoscan|--scan|-a. Save it, trim it and you're done! + shell$ mobundle --autoscan-list laugh.pl =head1 DESCRIPTION @@ -342,6 +395,10 @@ When used with L, these modules are skipped during the scan. get a list of modules to bundle from the given filename. +=item --modules-list | -l + +print out a list of modules. + =item --usage print a concise usage line and exit. You can specify this option -- 2.11.4.GIT