diff options
author | J Pipkin <j@dawnrazor.net> | 2013-01-03 04:50:59 -0600 |
---|---|---|
committer | J Pipkin <j@dawnrazor.net> | 2013-01-03 04:50:59 -0600 |
commit | 20a24ed881dd1f255c06db5cbc84308dde4c6fab (patch) | |
tree | 4e5e9ed00f6063bfe3362a1c5a59c89908f774fe /SBO-Lib/lib | |
parent | 9b5f214ff711cfba36d03c62dc3f9c8dbe5664c1 (diff) | |
download | sbotools2-20a24ed881dd1f255c06db5cbc84308dde4c6fab.tar.xz |
added get_installed_cpans() subroutine
Diffstat (limited to 'SBO-Lib/lib')
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index e06f124..b41fde2 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -850,3 +850,27 @@ sub get_readme_contents($) { close $fh; return $readme; } + +# return a list of perl modules installed via the CPAN +sub get_installed_cpans() { + my @locals; + for my $dir (@INC) { + push @locals, "$dir/perllocal.pod" if -f "$dir/perllocal.pod"; + } + my @contents; + for my $file (@locals) { + my $fh = open_read $file; + push @contents, grep {/Module|VERSION/} <$fh>; + close $fh; + } + my $mod_regex = qr/C<Module>\s+L<([^\|]+)/; + my $ver_regex = qr/C<VERSION:\s+([^>]+)>/; + my (@mods, @vers); + for my $line (@contents) { + push @mods, ($line =~ $mod_regex)[0]; + push @vers, ($line =~ $ver_regex)[0]; + } + my %cpans; + $cpans{$mods}[$_] = $vers[$_] for keys @mods; + return \%cpans; +} |