| 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
| |||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | if ($options{help}) { pod2usage(-verbose => 1, -exitval => 0); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | if ($options{man}) { pod2usage(-verbose => 2, -noperldoc => 1, -exitval => 0); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | if ($options{version}) { print "Perl CodeMap $Perl::CodeMap::VERSION\n"; exit 0; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 2 | my $cm = eval { Perl::CodeMap->new(%options) }; | |||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (!$cm) { print STDERR "perl-codemap: $@"; exit 2; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 2 | my $data; | |||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ($options{from_json}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | eval { | ||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | open my $fh, '<:raw', $options{from_json} or die "Cannot read $options{from_json}: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $data eq "HASH" and ref $data->{"pkgs"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | $data->{sources} ||= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{"sources"} ||= {}
MC/DC0%0/1
$data->{"sources"} ||= {}
$data->{"sources"}
Truth table50%1/2
A
A= $data->{"sources"}
| |||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | if (!$options{embed_source}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $data->{"module"} and -d $data->{"module"}
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"}
| |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $cm->hydrate_sources($data, $root) if defined $root; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $data->{source} = $options{source_base} if defined $options{source_base}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $data->{name} = $options{name} if defined $options{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 1 | 1; | |||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | } or do { print STDERR "perl-codemap: $@"; exit 2; }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||||||
| 56 | 1 | $data = eval { $cm->analyze }; | |||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (!$data) { print STDERR "perl-codemap: $@"; exit 2; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if (!@{$data->{pkgs}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC0%0/1
$data->{'sources'} || {}
$data->{'sources'}
Truth table50%1/2
A
A= $data->{'sources'}
| |||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$data->{"parser"} // ""
MC/DC0%0/1
$data->{"parser"} // ""
$data->{"parser"}
Truth table50%1/2
A
A= $data->{"parser"}
| |||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | print STDERR "Warning: $_\n" for @{$data->{warnings} || []}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{'warnings'} || []
MC/DC0%0/1
$data->{'warnings'} || []
$data->{'warnings'}
Truth table50%1/2
A
A= $data->{'warnings'}
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||