Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comparing what Modules are Installed on Two DIfferent Versions of Perl?

by Plankton (Vicar)
on Nov 16, 2009 at 16:43 UTC ( #807515=perlquestion: print w/replies, xml ) Need Help??
Plankton has asked for the wisdom of the Perl Monks concerning the following question:

Dear Wise Monks,

I need to see the differences in the Perl modules installed in an old 5.6.1 Perl and a new 5.10.1 Perl. Is it as simple as simply listing the .pm files in the /perl-5.6.1/lib/5.6.1 directory and comparing that with the contents of the perl5/5.10.1 directory?

Or is there some Perl command line I could run?

Thanks!

Replies are listed 'Best First'.
Re: Comparing what Modules are Installed on Two DIfferent Versions of Perl?
by toolic (Bishop) on Nov 16, 2009 at 16:58 UTC
Re: Comparing what Modules are Installed on Two DIfferent Versions of Perl?
by Fletch (Chancellor) on Nov 16, 2009 at 17:50 UTC

    The CPAN module's autobundle might be of use (run it against both installs and then compare the PODs generated).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Comparing what Modules are Installed on Two DIfferent Versions of Perl?
by thunders (Priest) on Nov 16, 2009 at 20:07 UTC

    Here's a script I called "module_list.pl" I wrote it up a while back to do a quick inventory on different systems I maintained. It will give you a sorted list of all modules installed, if you give it a "-v" option it will also show the path to that modules location. Just call it with each version of perl installed and it should do the right thing.

    #!/usr/bin/perl use strict; use warnings; =pod =head1 module_list.pl prints a list of all available perl modules and their location on disk =cut package ModuleLookup; use File::Find; use File::Spec; use Cwd qw(cwd realpath); =head1 ModuleLookup Module used by module_list.pl to scan the system for installed perl mo +dules =cut #cached lookups my %_FILE_TO_CLASSNAME_CACHE; my %_PATH_CACHE; #absolute path of all modules in the system my @ABS_INC = grep { $_ ne cwd() } #remove working directory from p +ath map { _cached_rel2abs($_) } @INC; =head1 $lookup = ModuleLookup->new(); Returns a ModuleLookup object that can be used to find installed perl +modules =cut sub new { my $class = shift; my $self = {}; return bless $self, $class; } =head1 $modules = $lookup->perl_modules_on_system() Returns a hash reference containing all perl modules available in the +current environment keyed by class name =cut sub perl_modules_on_system { my $self = shift; return $self->perl_modules_in_paths(@ABS_INC); } =head1 $modules = $lookup->perl_modules_in_paths(@paths) Given a list of directory paths, returns a hash reference containing p +erl modules under those directories keyed by class name =cut sub perl_modules_in_paths { my ( $self, @paths ) = @_; my %perl_modules; my @valid_paths; for my $path (@paths) { if ( -l $path){ $path = realpath($path); } if ( !-d $path ) { warn("invalid path $path"); next; } push @valid_paths, $path; } find( sub { if ( $File::Find::name =~ /\.pm$/ ) { my $path = $File::Find::name; my $class = $self->classname_from_path($path); $perl_modules{$class} = $path; } }, @valid_paths ); return \%perl_modules; } =head1 $classname = $lookup->classname_from_path($path) Given a path to a perl module, returns the class name expected by B<us +e> =cut sub classname_from_path { my ( $self, $path ) = @_; #avoid looking up the same path multiple time (File::Spec::real2abs ca +n be expensive) my $full_path = _cached_rel2abs($path); if ( exists $_FILE_TO_CLASSNAME_CACHE{$full_path} ) { return $_FILE_TO_CLASSNAME_CACHE{$full_path}; } my $classpath = $self->classpath_from_fullpath($full_path); #convert path to module name ( my $classname = $classpath ) =~ s/\.pm//; $classname =~ s{/}{::}g; $_FILE_TO_CLASSNAME_CACHE{$full_path} = $classname; return $classname; } =head1 $classpath = $lookup->classpath_from_fullpath($path) Given a path to a perl module, returns a relative path minus the perl +include directory =cut sub classpath_from_fullpath { my ( $self, $full_path ) = @_; #Remove the perl include path from the directory. my $max_substr = 0; my $parent_dir; for my $inc_dir (@ABS_INC) { my $dir_index = index( $full_path, $inc_dir ); # In the case that one @INC directory is contained within anot +her # (i.e. /usr/lib/perl /usr/lib/perl/5.10.0) # we remove the longest path that matches if ( $dir_index >= 0 ) { if ( length($inc_dir) > $max_substr ) { $max_substr = length($inc_dir); $parent_dir = $inc_dir; } } } my $classpath = $full_path; if ($parent_dir) { $classpath =~ s{^$parent_dir/}{}; } return $classpath; } sub _cached_rel2abs { my $path = shift; if ( !exists $_PATH_CACHE{$path} ) { my $abs_path = File::Spec->rel2abs($path); $_PATH_CACHE{$path} = -l $abs_path ? realpath($abs_path) : $ab +s_path; } return $_PATH_CACHE{$path}; } 1; package main; use Getopt::Long; my %opts; GetOptions( \%opts, 'help','verbose' ); if ( $opts{help} ) { print <<"EOD"; Usage: $0 - prints a list of all available perl modules and their loca +tion on disk For more information: perldoc $0 EOD exit; } my $module_lookup = ModuleLookup->new(); my $modules = $module_lookup->perl_modules_on_system(); #send a simple report to STDOUT for my $module ( sort { lc($a) cmp lc($b) } keys %$modules ) { if($opts{verbose}){ printf( "%35s : %-40s\n", $module, $modules->{$module} ); } else { printf( "%s\n", $module); } } print scalar( keys %$modules ) . " perl modules installed on this syst +em\n"; 1;
Re: Comparing what Modules are Installed on Two DIfferent Versions of Perl?
by educated_foo (Vicar) on Nov 17, 2009 at 01:55 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://807515]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-10-23 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (125 votes). Check out past polls.

    Notices?