| 1 | package LEOCHARRE::PMUsed; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | require Exporter; | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw(@ISA $VERSION @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||
| 8 | 1 | @EXPORT_OK =qw(module_is_installed find_code_files modules_used modules_used_scan_tree); | |||||||||||||||||||||||||||||
| 9 | 1 | %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 1 | $VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)/g; | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 1 | $LEOCHARRE::PMUsed::DEBUG = 0; | |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | sub DEBUG : lvalue {$LEOCHARRE::PMUsed::DEBUG} | ||||||||||||||||||||||||||||
|
Subroutine
DEBUG: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | sub debug { my $msg = shift; print STDERR " $msg\n" if DEBUG; } | ||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | sub module_is_installed { | ||||||||||||||||||||||||||||
|
Subroutine
module_is_installed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 18 | 6 | my $module = shift; | |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | $module or confess('missing argument to module_is_installed'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | if ( do { eval "require $module;" } ){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 22 | 4 | return 1; | |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||
| 24 | 2 | debug("Missing perl module: $module"); | |||||||||||||||||||||||||||||
| 25 | 2 | return 0; | |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub find_code_files { | ||||||||||||||||||||||||||||
|
Subroutine
find_code_files: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 30 | 2 | my $abs = shift; | |||||||||||||||||||||||||||||
| 31 | 2 | require File::Find::Rule; | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 2 | my $r = new File::Find::Rule(); | |||||||||||||||||||||||||||||
| 34 | 2 | $r->file; | |||||||||||||||||||||||||||||
| 35 | 2 | $r->name( qr/\.pl$|\.pm$|\.t$/ ); | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 2 | my @files = $r->in($abs); | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | #also find in bin, if usr/bin/perl type line is present in first 3 lines | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | if (-d "$abs/bin"){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 45 | 2 | debug('bin detected'); | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | opendir(DIR, "$abs/bin") or die($!); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 48 | 2 | my @bins = grep { -T "$abs/bin/$_" } readdir DIR; | |||||||||||||||||||||||||||||
| 49 | 2 | closedir DIR; | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 2 | debug('count in bin '.scalar @bins); | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 2 | BINFILES : for (@bins){ | |||||||||||||||||||||||||||||
| 54 | 4 | my $abs_bin= "$abs/bin/$_"; | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 4 | my $x =0; | |||||||||||||||||||||||||||||
| 57 | 4 | open(BIN,'<',$abs_bin); | |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | LINES : while(<BIN>){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | 8 | my $line = $_; | |||||||||||||||||||||||||||||
| 60 | 8 | ▶ | if ($line=~/#![\/A-Za-z]+bin\/perl\b/){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 61 | 2 | push @files, $abs_bin; | |||||||||||||||||||||||||||||
| 62 | 2 | close BIN; | |||||||||||||||||||||||||||||
| 63 | 2 | next BINFILES; | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | if (++$x > 3){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 0 | close BIN; | |||||||||||||||||||||||||||||
| 67 | 0 | next BINFILES; | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||
| 70 | 2 | close BIN; | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 2 | return \@files; | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 4 | ▶ | sub modules_used { | ||||||||||||||||||||||||||||
|
Subroutine
modules_used: called CC=15 SCAR=30.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 82 | 4 | my ($abs_code,$skip_t) = @_; | |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | (-f $abs_code) or carp("argument to modules_userd() [$abs_code] is not a file.") and return; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-f $abs_code || carp("argument to modules_userd() [$abs_code] is not a file.") && (return)
carp("argument to modules_userd() [$abs_code] is not a file.") and return
MC/DC0%0/2
-f $abs_code || carp("argument to modules_userd() [$abs_code] is not a file.") && (return)
-f $abs_code
carp("argument to modules_userd() [$abs_code] is not a file.")
Truth table33%1/3
A || B
A= -f $abs_codeB= carp("argument to modules_userd() [$abs_code] is not a file.")
| |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | 4 | my $lines = []; | |||||||||||||||||||||||||||||
| 87 | 4 | my $modules = {}; | |||||||||||||||||||||||||||||
| 88 | 4 | my $code; | |||||||||||||||||||||||||||||
| 89 | 4 | open(FILE,'<',$abs_code); | |||||||||||||||||||||||||||||
| 90 | 4 | ▶ | while(<FILE>){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 32 | push @$lines,$_; | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 4 | close FILE; | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 4 | LINE: for(@$lines){ | |||||||||||||||||||||||||||||
| 97 | 32 | my $line = $_; | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | 32 | $line=~s/#\s.+$//g; # take out comments | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 32 | ▶ | if ( $line=~/use base '([^\']+)'/ ){ | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 102 | 2 | my $module = $1; | |||||||||||||||||||||||||||||
| 103 | 2 | $modules->{$module}++; | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||
| 105 | elsif ( $line=~/use base qw\W([\s\w\:]+)\W/){ | ||||||||||||||||||||||||||||||
| 106 | 2 | my @mods = split(/\s/,$1); | |||||||||||||||||||||||||||||
| 107 | 2 | ▶ | map{ $modules->{$_}++ if $_=~/\w/ } @mods; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | elsif( $line=~/^use\s+([\w\:]+)[\s;]/s ){ | ||||||||||||||||||||||||||||||
| 112 | 12 | my $module = $1; | |||||||||||||||||||||||||||||
| 113 | 12 | $modules->{$module}++; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | elsif ($line=~/^[\W]*use\s+([\w\:]+)[\s;]/s){ | ||||||||||||||||||||||||||||||
| 116 | 0 | my $module = $1; | |||||||||||||||||||||||||||||
| 117 | 0 | $modules->{$module}++; | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 32 | ▶ | if ( $line=~/require\s+([\w\:]+)\s*;/s ){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 121 | 0 | my $module = $1; | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if( $module=~/\.pl$|\.pm$/ or $module=~/^\./ ){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module =~ /\.pl$|\.pm$/ or $module =~ /^\./
MC/DC0%0/2
$module =~ /\.pl$|\.pm$/ or $module =~ /^\./
$module =~ /\.pl$|\.pm$/
$module =~ /^\./
Truth table0%0/3
A or B
A= $module =~ /\.pl$|\.pm$/B= $module =~ /^\./
| |||||||||||||||||||||||||||||||
| 123 | # then skip, it's a include | ||||||||||||||||||||||||||||||
| 124 | 0 | next LINE; | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||
| 126 | 0 | $modules->{$module}++; | |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | # take out ones non wanted/needed | ||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | 4 | for my $module_name ( keys %$modules ){ | |||||||||||||||||||||||||||||
| 137 | 18 | ▶ | _module_name_is_in_t($module_name) and delete $modules->{$module_name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | # lousy hack | ||||||||||||||||||||||||||||||
| 142 | 4 | $modules->{'Devel::AssertEXE'}; | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||
| 144 | 4 | return $modules; | |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 18 | ▶ | sub _module_name_is_in_t { | ||||||||||||||||||||||||||||
|
Subroutine
_module_name_is_in_t: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||
| 150 | 18 | my $name = shift; | |||||||||||||||||||||||||||||
| 151 | 18 | $name=~s/\:\:/\//g; | |||||||||||||||||||||||||||||
| 152 | 18 | $name.='.pm'; | |||||||||||||||||||||||||||||
| 153 | 18 | ▶ | ( -e "./t/$name") ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub modules_used_scan_tree { | ||||||||||||||||||||||||||||
|
Subroutine
modules_used_scan_tree: called CC=12 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 157 | 1 | my $abs_dir = shift; | |||||||||||||||||||||||||||||
| 158 | 1 | my $skip_inclusive = shift; | |||||||||||||||||||||||||||||
| 159 | 1 | ▶ | $skip_inclusive ||= 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$skip_inclusive ||= 0
MC/DC0%0/1
$skip_inclusive ||= 0
$skip_inclusive
Truth table50%1/2
A
A= $skip_inclusive
| |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | my $codefiles = find_code_files($abs_dir) or warn("no code files found?") and return; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
(my $codefiles = find_code_files($abs_dir)) || warn('no code files found?') && (return)
warn "no code files found?" and return
MC/DC0%0/2
(my $codefiles = find_code_files($abs_dir)) || warn('no code files found?') && (return)
(my $codefiles = find_code_files($abs_dir))
warn "no code files found?"
Truth table33%1/3
A || B
A= (my $codefiles = find_code_files($abs_dir))B= warn "no code files found?"
| |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | # record which they are, so if they are used by others in this palce, we skip, | ||||||||||||||||||||||||||||||
| 164 | # that is, if we have lib/this and lib/that, we cont want to say we need either | ||||||||||||||||||||||||||||||
| 165 | 1 | my $skip = {}; | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 1 | for (@$codefiles){ # if we do 'for my $this (@$codefiles) it screws up | |||||||||||||||||||||||||||||
| 168 | 2 | my $path = $_; | |||||||||||||||||||||||||||||
| 169 | 2 | ▶ | $path=~s/\.pm$// or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 170 | 1 | $path=~s/^.+lib\///; | |||||||||||||||||||||||||||||
| 171 | 1 | $path=~s/\//\:\:/g; | |||||||||||||||||||||||||||||
| 172 | 1 | debug(" - summed to $path\n"); | |||||||||||||||||||||||||||||
| 173 | 1 | $skip->{$path}++; | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | 1 | my $all={}; | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | 1 | for(@$codefiles){ | |||||||||||||||||||||||||||||
| 179 | 2 | ▶ | my $modules = modules_used($_) or die; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | 2 | MUSED: for my $name (keys %$modules){ | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | #if we have in the tree, skip | ||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | if( $skip_inclusive and exists $skip->{$name}){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$skip_inclusive and exists $skip->{$name}
MC/DC0%0/2
$skip_inclusive and exists $skip->{$name}
$skip_inclusive
exists $skip->{$name}
Truth table33%1/3
A and B
A= $skip_inclusiveB= exists $skip->{$name}
| |||||||||||||||||||||||||||||||
| 185 | 0 | debug("$name is part of distro"); | |||||||||||||||||||||||||||||
| 186 | 0 | next MUSED; | |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | 9 | my $count = $modules->{$name}; | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | 9 | ▶ | if(defined $all->{$name}){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 192 | 2 | $count = $count + $all->{$name}; | |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | 9 | $all->{$name} = $count; | |||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | 1 | return $all; | |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | 1 | 1; | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||||