bin/perl-codemap

filter: Statementstmt 86.5% 77 / 89 Branchbran 52.6% 20 / 38 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 70.4% 112 / 159 CC 1 SCAR 0.0
CC
1
Cov
72%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/Perl/CodeMap.pm ↑ Summary
1 #!/usr/bin/env perl
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use FindBin qw($RealBin);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use lib "$RealBin/../lib"; # source checkout or build tree
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Pod::Usage qw(pod2usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Perl::CodeMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 my %options = (root => '.', output => 'perl-code-map.html', parser => 'auto', embed_source => 1);
13 6 my $root_set = 0;
14 GetOptions(
15 1 ▶ 'root=s' => sub { $options{root} = $_[1]; $root_set = 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 'o|output=s' => \$options{output},
17 'json=s' => \$options{json},
18 'from-json=s' => \$options{from_json},
19 'parser=s' => \$options{parser},
20 'embed-source!' => \$options{embed_source},
21 'max-source-bytes=i' => \$options{max_source_bytes},
22 'include-tests!' => \$options{include_tests},
23 'source-base=s' => \$options{source_base},
24 'name=s' => \$options{name},
25 'version' => \$options{version},
26 'help|h' => \$options{help},
27 'man' => \$options{man},
28 6 ▶) or pod2usage(-verbose => 0, -exitval => 2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("root=s", sub { $options{"root"} = $_[1]; $root_set = 1; } , "o|output=s", \$options{"output"}, "json=s", \$options{"json"}, "from-json=s", \$options{"from_json"}, "parser=s", \$options{"parser"}, "embed-source!", \$options{"embed_source"}, "max-source-bytes=i", \$options{"max_source_bytes"}, "include-tests!", \$options{"include_tests"}, "source-base=s", \$options{"source_base"}, "name=s", \$options{"name"}, "version", \$options{"version"}, "help|h", \$options{"help"}, "man", \$options{"man"}) or pod2usage("-verbose", 0, "-exitval", 2) 6 0 6
29 6 ▶if ($options{help}) { pod2usage(-verbose => 1, -exitval => 0); }
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"help"}) 2 4 6
30 4 ▶if ($options{man}) { pod2usage(-verbose => 2, -noperldoc => 1, -exitval => 0); }
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"man"}) 1 3 4
31 3 ▶if ($options{version}) { print "Perl CodeMap $Perl::CodeMap::VERSION\n"; exit 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"version"}) 1 2 3
32 2 my $cm = eval { Perl::CodeMap->new(%options) };
33 0 ▶if (!$cm) { print STDERR "perl-codemap: $@"; exit 2; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($cm) 0 2 2
34 2 my $data;
35 2 ▶if ($options{from_json}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'from_json'}) { } 1 1 2
36 eval {
37 1 ▶ open my $fh, '<:raw', $options{from_json} or die "Cannot read $options{from_json}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $options{"from_json"} or die qq[Cannot read $options{"from_json"}: $!\n] 1 0 1
38 1 local $/;
39 1 $data = JSON::PP->new->utf8(1)->decode(<$fh>);
40 1 close $fh;
41 die "Expected a CodeMap JSON object with a pkgs array\n"
42 1 ▶ unless ref($data) eq 'HASH' && ref($data->{pkgs}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY" 0 1 1
Condition33%1/3
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
ref $data eq "HASH" ref $data->{"pkgs"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $data eq "HASH"B= ref $data->{"pkgs"} eq "ARRAY"
ABresult
0X0
100
111
43 1 ▶ $data->{sources} ||= {};
Condition50%1/2
$data->{"sources"} ||= {}
l!l
10
MC/DC0%0/1
$data->{"sources"} ||= {}
$data->{"sources"}
Truth table50%1/2
A
A= $data->{"sources"}
Aresult
11
00
44 1 ▶ if (!$options{embed_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $options{'embed_source'}) { } 1 0 1
45 1 $data->{sources} = {};
46 } else {
47 my $root = $root_set ? $options{root}
48 0 ▶ : ((defined $data->{module} && -d $data->{module}) ? $data->{module} : undef);
Branch: 2 branches
BranchTrueFalseTotal
$root_set ? : 0 0 0
defined $data->{'module'} && -d $data->{'module'} ? : 0 0 0
Condition0%0/3
defined $data->{"module"} and -d $data->{"module"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data->{"module"} and -d $data->{"module"}
defined $data->{"module"} -d $data->{"module"}
Truth table0%0/3
A and B
A= defined $data->{"module"}B= -d $data->{"module"}
ABresult
0X0
100
111
49 0 ▶ $cm->hydrate_sources($data, $root) if defined $root;
Branch: 1 branch
BranchTrueFalseTotal
if defined $root 0 0 0
50 }
51 1 ▶ $data->{source} = $options{source_base} if defined $options{source_base};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"source_base"} 0 1 1
52 1 ▶ $data->{name} = $options{name} if defined $options{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"name"} 0 1 1
53 1 1;
54 0 ▶ } or do { print STDERR "perl-codemap: $@"; exit 2; };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { open my $fh, "<:raw", $options{"from_json"} or die qq[Cannot read $options{"from_json"}: $!\n]; local $/; $data = "JSON::PP"->new->utf8(1)->decode(readline $fh); close $fh; die "Expected a CodeMap JSON object with a pkgs array\n" unless ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"; $data->{"sources"} ||= {}; if (not $options{"embed_source"}) { $data->{"sources"} = {}; } else { my $root = $root_set ? $options{"root"} : (defined $data->{"module"} && -d $data->{"module"} ? $data->{"module"} : undef); $cm->hydrate_sources($data, $root) if defined $root; } ; $data->{"source"} = $options{"source_base"} if defined $options{"source_base"}; $data->{"name"} = $options{"name"} if defined $options{"name"}; 1 } } or do { print STDERR "perl-codemap: $@"; exit 2 } 1 0 1
55 } else {
56 1 $data = eval { $cm->analyze };
57 0 ▶ if (!$data) { print STDERR "perl-codemap: $@"; exit 2; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 1 1
58 }
59 2 ▶if (!@{$data->{pkgs}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$data->{"pkgs"};}) 0 2 2
60 0 print STDERR "perl-codemap: no Perl packages found under the selected source root\n";
61 0 exit 1;
62 }
63 2 my $ok = eval { $cm->write_report($data, output => $options{output}, json => $options{json}); 1 };
64 0 ▶if (!$ok) { print STDERR "perl-codemap: $@"; exit 2; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 2 2
65 2 my $fn_count = 0;
66 2 $fn_count += @{$_->{funcs}} for map { @{$_->{files}} } @{$data->{pkgs}};
67 2 print "Report: $options{output}\n";
68 2 print 'Packages: ', scalar(@{$data->{pkgs}}), " | Declarations: $fn_count",
69 2 ▶ ' | Embedded sources: ', scalar(keys %{$data->{sources} || {}}), "\n";
Condition50%1/2
$data->{'sources'} || {}
l!l
20
MC/DC0%0/1
$data->{'sources'} || {}
$data->{'sources'}
Truth table50%1/2
A
A= $data->{'sources'}
Aresult
11
00
70 print STDERR "Warning: lite parser is heuristic; install PPI for full structural extraction.\n"
71 2 ▶ if ($data->{parser} // '') eq 'lite';
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"parser"} // "") eq "lite" 2 0 2
Condition50%1/2
$data->{"parser"} // ""
l!l
20
MC/DC0%0/1
$data->{"parser"} // ""
$data->{"parser"}
Truth table50%1/2
A
A= $data->{"parser"}
Aresult
11
00
72 2 ▶print STDERR "Warning: $_\n" for @{$data->{warnings} || []};
Condition50%1/2
$data->{'warnings'} || []
l!l
20
MC/DC0%0/1
$data->{'warnings'} || []
$data->{'warnings'}
Truth table50%1/2
A
A= $data->{'warnings'}
Aresult
11
00
73  
74 __END__
« lib/Perl/CodeMap.pm ↑ Summary