Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to clean-up an autobundle so it's really "auto-installable"

by sundialsvc4 (Abbot)
on Jun 16, 2011 at 19:07 UTC ( [id://910010]=note: print w/replies, xml ) Need Help??


in reply to How to clean-up an autobundle so it's really "auto-installable"

Well, they say that good Perl programmers are lazy.   Goody for the good ones.   Fortunately, I guess that programmers like me must be lazy, too.  

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; print STDERR "Scanning ...\n"; # find dependent things ... note 'scandeps' only considers modules. # note: do not say "*.pm" here or you won't look in subdirs # replace 'path_to_my_app_libs' with whatever is correct for you ... my @output = qx{scandeps.pl /path_to_my_app_libs/*}; my @keepers; # The output of interest is the module-name, found in single quotes foreach (@output) { chomp; next unless /^'([A-Z].*?)'/; push @keepers, $1; } print STDERR "Installing ...\n"; foreach (@keepers) { # The output is a little "wordy." # Omit hundreds o' things that we know are really parts of others. next if /^Date::Manip::TZ::/; next if /^Date::Manip::Offset::/; qx{cpanm $_}; # install it } # see if we got everything ... # (failure of some of these is not necessarily awful) foreach (@keepers) { print STDERR "require $_\n"; eval "require $_"; # magic necessary voodoo ... see 'perldo +c require' } print "Normal completion.\n";

At first I was seriously flummoxed by the fact that I did not get complete results.   It turns out that it is very important that the scandeps.pl command ends with “*” and not, as originally written, “*.pm”   (The first form omits subdirectories.)

This script requires App::cpanminus (for cpanm) and Module::ScanDeps (for scandeps.pl).

As written, it still does not make any improvements to the order in which things are attempted.   I took a brief look at the hashref returned by scan_deps() and it does look like it could be used more fully, i.e. in order to do that.   (No doubt, it already has...)

Replies are listed 'Best First'.
Re^2: How to clean-up an autobundle so it's really "auto-installable"
by Anonymous Monk on Jun 17, 2011 at 13:47 UTC
    Here is my version, takes bundle (or as cpanp names it, snapshot) file as argument
    #!/usr/bin/perl -- use strict; use warnings; use CPANPLUS::Internals::Utils ; use DBI; Main( @ARGV ); exit( 0 ); sub Main { my @snaps = @_; my %U; my $db = CPANPLUS::Internals::Utils->_home_dir . '\.cpanplus\db.sq +l'; warn "db is $db snaps is @snaps "; my $dbh = DBI->connect( qq!dbi:SQLite:dbname=$db!, undef, undef, { RaiseError => 1, PrintError => 1, }, ); my $sth = $dbh->prepare( q! select path, package from module where + module = ? ! ); for my $file ( @snaps ){ open my($fh), '<', $file or die; while(<$fh>){ if(/=head1 CONTENTS/.. /=head1 CONFIGURATION/){ if( /^(\w\S+)\s/ ){ my $module = $1; $sth->execute($module ); my($a,$p) = $sth->fetchrow_array; next unless $p and $a; $a =~ s!^authors/id/!!; next if $p =~ /^perl-5\./; next if $p =~ /^perl-5\./; my $pp = $p; $pp =~ s/-\d.\d.+$//; ## libwwwperl $U{$pp}="$a/$p"; #~ perl-5.10.1.tar.gz #~ perl-5.11.1.tar.bz2 #~ perl-5.12.3.tar.bz2 #~ perl-5.13.9.tar.gz } } } close $fh; } undef $sth; undef $dbh; print "\n\nsystem qw[ cpanp -d \n"; print " $U{$_}\n" for sort keys %U; print "\n\n];\n"; } __END__ system qw[ cpanp -d ... G/GB/GBARR/libnet-1.22.tar.gz G/GA/GAAS/libwww-perl-6.02.tar.gz ];
    I use cpanp -d to first download all the tarballs then later, offline, change -d to -i to install all the tarballs

      Sometimes the simple solution isn't pure Perl.

      cpanm `cat Snapshot_2014_12_29_00.pm|awk '/\:\:/{print $1}'`

      I suppose I could find a way to do that in Perl but awk is simple and fast. This certainly puts lots of extra modules on cpanm's list, but it knows how to figure this stuff out.

        Sometimes the simple solution isn't pure Perl.

        cpanp already knows how to install snapshots, there is no need for cpanm or awk here

      Sometimes the simple solution isn't pure Perl.

      cpanm `cat Snapshot_2014_12_29_00.pm|awk '/\:\:/{print $1}'`

      I suppose I could find a way to do that in Perl but awk is simple and fast. This certainly puts lots of extra modules on cpanm's list, but it knows how to figure this stuff out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://910010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-24 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found