File Coverage

blib/lib/System/Introspector/Probe/Perls.pm
Criterion Covered Total %
statement 30 36 83.3
branch 11 16 68.7
condition 4 12 33.3
subroutine 5 6 83.3
pod 0 1 0.0
total 50 71 70.4


line stmt bran cond sub pod time code
1             package System::Introspector::Probe::Perls;
2 1     1   43236 use Moo;
  1         17344  
  1         7  
3              
4 1         874 use System::Introspector::Util qw(
5             transform_exceptions
6             handle_from_command
7             fail
8 1     1   2735 );
  1         4  
9              
10             has root => (
11             is => 'ro',
12             default => sub { '/' },
13             );
14              
15             sub gather {
16 1     1 0 1374 my ($self) = @_;
17             return transform_exceptions {
18 1     1   5 my @configs = $self->_find_possible_perl_configs;
19 1         10 my %found;
20             my %seen;
21 1         3 for my $config (@configs) {
22             my $info = transform_exceptions {
23 2         8 return $self->_gather_info($config);
24 2         19 };
25 2 50 33     29 next if $info
      33        
26             and $info->{config}{sitelibexp}
27             and $seen{$info->{config}{sitelibexp}}++;
28 2 50       12 $found{$config} = $info
29             if defined $info;
30             }
31 1         8 return { perls => \%found };
32 1         14 };
33             }
34              
35             sub _gather_info {
36 2     2   6 my ($self, $config) = @_;
37 2 50       136 open my $fh, '<', $config
38             or fail "Unable to determine '$config': $!";
39 2         33 my $first_line = <$fh>;
40             return undef
41 2 50 33     26 unless defined $first_line and $first_line =~ m{^#.+configpm};
42 2         3 my %info;
43             my $is_info;
44             LINE:
45 2         11 while (defined( my $line = <$fh> )) {
46 202 100       391 if ($line =~ m{tie\s+\%Config}) {
47 2         97 $is_info++;
48 2         12 next LINE;
49             }
50 200         185 chomp $line;
51 200 100       801 if ($line =~ m{^\s*([a-z0-9_]+)\s*=>\s*'(.*)',\s*$}i) {
    100          
52 42         212 $info{$1} = $2;
53             }
54             elsif ($line =~ m{^\s*([a-z0-9_]+)\s*=>\s*undef,$}i) {
55 4         22 $info{$1} = undef;
56             }
57             }
58             return {
59 2 50 33     60 (defined $info{scriptdir} and $info{version})
60             ? (executable => join('/', $info{scriptdir}, 'perl' . $info{version}))
61             : (),
62             config => \%info,
63             };
64             }
65              
66             sub _find_possible_perl_configs {
67 0     0     my ($self) = @_;
68 0           (my $root = $self->root) =~ s{/$}{};
69 0           my $handle = handle_from_command sprintf
70             q{locate --regex '^%s/.*/Config.pm$'}, $root;
71 0           my @lines = <$handle>;
72 0           chomp @lines;
73 0           return @lines;
74             }
75              
76             1;
77              
78             __END__