blib/lib/CPAN/Audit/Installed.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 80.0% 24 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 84.5% 93 / 110 CC 19 SCAR 17.6
CC
19
Cov
89%
__ANON__
10.1
module_from_file
5.0
find
4.0
CRAP 5.8
« script/cpan-audit ↑ Summary lib/CPAN/Audit/Query.pm »
1 package CPAN::Audit::Installed;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 our $VERSION = "1.002";
8  
9 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 3 my( $class, %params ) = @_;
11 3 bless \%params, $class;
12 }
13  
14 3 ▶sub find {
Subroutine find: called CC=4 SCAR=13.9
Pod undocumented
15 3 my $self = shift;
16 3 my (@inc) = @_;
17  
18 3 ▶ @inc = @INC unless @inc;
Branch: 1 branch
BranchTrueFalseTotal
unless @inc 2 1 3
19 3 ▶ @inc = grep { defined && -d $_ } map { Cwd::realpath($_) } @inc;
Condition33%1/3
defined $_ && -d $_
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $_ && -d $_
defined $_ -d $_
Truth table33%1/3
A && B
A= defined $_B= -d $_
ABresult
0X0
100
111
20  
21 3 my %seen;
22 my @deps;
23 3 ▶ push @deps, { dist => 'perl', version => $] } if $self->{include_perl};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_perl"} 0 3 3
24  
25 File::Find::find(
26 {
27 24982 ▶ wanted => sub {
Subroutine __ANON__: called CC=10 SCAR=23.1
28 24982 my $path = $File::Find::name;
29 24982 ▶ if ( $path && -f $path && m/\.pm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path and -f $path and /\.pm$/) 3572 21410 24982
Condition83%5/6
$path and -f $path and /\.pm$/
!ll&&!rl&&r
2144192663572
$path and -f $path
!ll&&!rl&&r
0214422838
MC/DC66%2/3
$path and -f $path and /\.pm$/
$path -f $path /\.pm$/
Truth table75%3/4
A and B and C
A= $pathB= -f $pathC= /\.pm$/
ABCresult
0XX0
10X0
1100
1111
30 3572 ▶ return unless my $module = module_from_file($path);
Branch: 1 branch
BranchTrueFalseTotal
unless my $module = module_from_file($path) 24 3548 3572
31  
32 3548 ▶ return unless my $distname = $self->{db}->{module2dist}->{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless my $distname = $self->{"db"}{"module2dist"}{$module} 2629 919 3548
33  
34 919 my $dist = $self->{db}->{dists}->{$distname};
35 919 ▶ if ( $dist->{main_module} eq $module ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist->{"main_module"} eq $module) 105 814 919
36 105 ▶ return if $seen{$module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$module}++ 0 105 105
37  
38 105 ▶ return unless my $version = module_version($path);
Branch: 1 branch
BranchTrueFalseTotal
unless my $version = module_version($path) 0 105 105
39  
40 105 push @deps, { dist => $distname, version => $version };
41  
42 105 ▶ if ( $self->{cb} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cb"}) 52 53 105
43 52 $self->{cb}->(
44 {
45 path => $path,
46 distname => $distname,
47 version => $version
48 }
49 );
50 }
51 }
52 }
53 },
54 3 follow => 1,
55 follow_skip => 2,
56 },
57 @inc
58 );
59  
60 3 return @deps;
61 }
62  
63 105 ▶sub module_version {
Subroutine module_version: called CC=3 SCAR=11.6
Pod undocumented
64 105 require Module::Extract::VERSION;
65 105 my( $file ) = @_;
66  
67 105 my $version = Module::Extract::VERSION->parse_version_safely( $file );
68  
69 105 ▶ if( eval { $version->can('numify') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $version->can("numify") } }) 0 105 105
70 0 $version = $version->numify;
71 }
72  
73 105 ▶ return defined $version ? $version : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 105 0 105
74 }
75  
76 3572 ▶sub module_from_file {
Subroutine module_from_file: called CC=5 SCAR=16.1
Pod undocumented
77 3572 my ($path) = @_;
78 3572 my $module;
79  
80 3572 ▶ open my $fh, '<', $path or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or return 3572 0 3572
81 3572 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 24858 24 24882
82 24858 ▶ if ( $line =~ m/package\s+(.*?)\s*;/ms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /package\s+(.*?)\s*;/ms) 3548 21310 24858
83 3548 $module = $1;
84 3548 last;
85 }
86 }
87 3572 close $fh;
88  
89 3572 ▶ return unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 24 3548 3572
90 }
91  
92 14 1;
« script/cpan-audit ↑ Summary lib/CPAN/Audit/Query.pm »