sourcecode
Sixtease
<code>
#!/usr/bin/perl
=pod
Run this script from the perllib directory, where vendor_perl and site_perl
directories reside. (in my case it's /usr/lib/perl5)
The script will output the modules (.pm files) located in both subdirs.
The branch (site_perl or vendor_perl) will be output for the older module
(which you thus might want to remove).
Set $PERLVERSION to whatever you have in both site_perl and vendor_perl.
=cut
use strict;
use warnings;
my $PERLVERSION = '5.8.8';
# print each element of a list on a separate line
$\ = $, = "\n";
my $s = 'site_perl';
my $v = 'vendor_perl';
my @pms = ();
# takes a list of dirnames that are in both branches
# returns a list of files that are in these dirs
# in both branches (the branch prefix is truncated)
sub common {
my @dirs = @_;
my @rv = ();
for my $dir (@dirs) {
my @site = glob("$s/$dir/*");
my @vendor = glob("$v/$dir/*");
s#^.*?/## for @site, @vendor;
push @rv, grep {my $s = $_; grep {$_ eq $s} @vendor} @site;
}
return @rv;
}
# initialization
# The array contains files that are in both branches
# of one level of the subtree hierarchy.
my @commons = common $PERLVERSION;
# store the modules common to both branches.
# Processes one level of subtree depth per iteration.
while (@commons) {
# store the modules - they will be output
push @pms, grep {m/\.pm$/} @commons;
# keep only directories for further traversal
@commons = grep {-d "$s/$_"} @commons;
# dive one level deeper
@commons = common @commons;
}
# Print the found modules.
# Try to figure out the version of each
# and print the older one.
# Don't print a branch if neither seems to be older.
for my $pm (@pms) {
# $spm -- site_perl PM
# $vpm -- vendor_perl PM
open my $spm, '<', "$s/$pm" or warn "Couldn't open $s/$pm";
open my $vpm, '<', "$v/$pm" or warn "Couldn't open $v/$pm";
# look for the version of each module
# $sV -- site_perl module's VERSION
# $vV -- vendor_perl module's VERSION
no warnings 'uninitialized';
my ($sV) = grep /\$VERSION\s*=/, <$spm>;
my ($vV) = grep /\$VERSION\s*=/, <$vpm>;
$sV =~ /\$VERSION\s*=\D*([\d.]+)/;
$sV = $1;
$vV =~ /\$VERSION\s*=\D*([\d.]+)/;
$vV = $1;
my $leadstr =
$sV > $vV ? "$v/" :
$sV < $vV ? " $s/" :
" " ;
print $leadstr . $pm;
}
</code>
Run this script from the perllib directory, where vendor_perl and site_perl directories reside. (in my case it's /usr/lib/perl5)
The script will output the modules (.pm files) located in both subdirs.
The branch (site_perl or vendor_perl) will be output for the older module
(which you thus might want to remove).
miscellaneous
Oldrich Kruza <Oldrich.Kruza@sixtease.net>
http://www.sixtease.net/