Dist/Dzpl/Parser.pm

filter: Statementstmt 91.1% 82 / 90 Branchbran 78.1% 25 / 32 Conditioncond 56.2% 9 / 16 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 81.3% 131 / 161 CC 27 SCAR 21.7
CC
27
Cov
84%
parse
15.2
_parse_prerequisite
11.4
_parse_author
5.0
CRAP 8.8
« Dist/Dzpl.pm ↑ Summary Dzpl.pm »
1 package Dist::Dzpl::Parser;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Dist::Zilla;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Dist::Zilla::Chrome::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Dist::Zilla::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub parse {
Subroutine parse: called CC=11 SCAR=27.2
Pod undocumented
13 1 my $self = shift;
14
15 1 my ( %zilla, @prerequisite );
16 1 ▶ while( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 1 6
17 5 local $_ = shift;
18 5 ▶ if ( m/\A(?:authors?|by)\z/ ) { $self->_parse_author( \%zilla, shift ) }
Branch: 6 branches
BranchTrueFalseTotal
if (/\A(?:authors?|by)\z/) { } 1 4 5
elsif (/\Acopyright\z/) { } 1 3 4
elsif (/\Alicense\z/) { } 1 2 3
elsif (/\Arequire\z/) { } 0 2 2
elsif (/\Arecommend\z/) { } 0 2 2
elsif (/\Aprefer\z/) { } 0 2 2
19 1 elsif ( m/\Acopyright\z/) { $self->_parse_copyright( \%zilla => shift ) }
20 1 elsif ( m/\Alicense\z/) { $self->_parse_license( \%zilla => shift ) }
21 0 elsif ( m/\Arequire\z/) { $self->_parse_prerequisite( \@prerequisite => require => shift ) }
22 0 elsif ( m/\Arecommend\z/) { $self->_parse_prerequisite( \@prerequisite => recommend => shift ) }
23 0 elsif ( m/\Aprefer\z/) { $self->_parse_prerequisite( \@prerequisite => prefer => shift ) }
24 2 else { $zilla{$_} = shift }
25 }
26  
27 1 ▶ $zilla{ chrome } ||= Dist::Zilla::Chrome::Term->new;
Condition33%1/3
$zilla{"chrome"} ||= "Dist::Zilla::Chrome::Term"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$zilla{"chrome"} ||= "Dist::Zilla::Chrome::Term"->new
$zilla{"chrome"} "Dist::Zilla::Chrome::Term"->new
Truth table33%1/3
A ||= B
A= $zilla{"chrome"}B= "Dist::Zilla::Chrome::Term"->new
ABresult
1X1
011
000
28 1 ▶ $zilla{ root } ||= '.';
Condition50%1/2
$zilla{"root"} ||= "."
l!l
01
MC/DC0%0/1
$zilla{"root"} ||= "."
$zilla{"root"}
Truth table50%1/2
A
A= $zilla{"root"}
Aresult
11
00
29  
30 1 my $zilla = Dist::Zilla->new( %zilla );
31 1 for my $prerequisite (@prerequisite) {
32 0 my ( $phase, $type, $manifest ) = @$prerequisite{qw/ phase type manifest /};
33 0 $phase = lc $phase;
34 0 $type = "${type}s";
35 0 $zilla->register_prereqs( { phase => $phase, type => $type }, @$manifest );
36 }
37  
38 1 return $zilla;
39 }
40  
41 6 ▶sub _parse_prerequisite {
Subroutine _parse_prerequisite: called CC=11 SCAR=24.4
42 6 my $self = shift;
43 6 my $stash = shift;
44 6 my $importance = shift;
45 6 my $input = shift;
46  
47 6 ▶ die "Missing input" unless defined $input && length $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input and length $input 0 6 6
Condition33%1/3
defined $input and length $input
!ll&&!rl&&r
006
MC/DC0%0/2
defined $input and length $input
defined $input length $input
Truth table33%1/3
A and B
A= defined $inputB= length $input
ABresult
0X0
100
111
48  
49 6 my @stash;
50 6 my $manifest = [];
51 6 push @stash, { phase => 'runtime', type => $importance, manifest => $manifest };
52 6 for my $line ( split m/\n/, $input ) {
53 21 s/^\s*//, s/\s*$// for $line;
54 21 ▶ next if $line =~ m/^#/ || $line !~ m/\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ or not $line =~ /\S/ 3 18 21
Condition66%2/3
$line =~ /^#/ or not $line =~ /\S/
l!l&&r!l&&!r
0318
MC/DC50%1/2
$line =~ /^#/ or not $line =~ /\S/
$line =~ /^#/ not $line =~ /\S/
Truth table66%2/3
A or not(B)
A= $line =~ /^#/B= not $line =~ /\S/
ABresult
1X1
011
000
55 18 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\@([\w\-]+):\z/ or $line =~ /\A\[([\w\-]+)\]\z/) { } 9 9 18
Condition66%2/3
$line =~ /\A\@([\w\-]+):\z/ or $line =~ /\A\[([\w\-]+)\]\z/
l!l&&r!l&&!r
099
MC/DC50%1/2
$line =~ /\A\@([\w\-]+):\z/ or $line =~ /\A\[([\w\-]+)\]\z/
$line =~ /\A\@([\w\-]+):\z/ $line =~ /\A\[([\w\-]+)\]\z/
Truth table66%2/3
A or B
A= $line =~ /\A\@([\w\-]+):\z/B= $line =~ /\A\[([\w\-]+)\]\z/
ABresult
1X1
011
000
56 $line =~ m/\A\@([\w\-]+):\z/ || # @Test:
57 $line =~ m/\A\[([\w\-]+)\]\z/ # [Test]
58 ) {
59 9 push @stash, { phase => lc $1, type => $importance, manifest => ( $manifest = [] ) };
60 }
61 else {
62 9 my ( $package, $version ) = split m/\s+/, $line, 2;
63 9 ▶ $package = $line unless defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 9 9
64 9 ▶ $version ||= 0;
Condition100%2/2
$version ||= 0
l!l
54
MC/DC100%1/1
$version ||= 0
$version
Truth table100%2/2
A
A= $version
Aresult
11
00
65 9 push @$manifest, ( $package => $version );
66 }
67 }
68  
69 6 push @$stash, grep { @{ $_->{manifest} } > 0 } @stash;
70 }
71  
72 2 ▶sub _parse_author {
Subroutine _parse_author: called CC=5 SCAR=16.2
73 2 my $self = shift;
74 2 my $zilla = shift;
75 2 my $input = shift;
76  
77 2 my @author;
78 2 ▶ if ( ref $input eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $input eq 'ARRAY') { } 0 2 2
elsif ($input =~ /\n/) { } 1 1 2
79 0 @author = @$input;
80 }
81 elsif ( $input =~ m/\n/ ) {
82 1 for my $line ( split m/\n/, $input ) {
83 4 local $_ = $line;
84 4 ▶ next unless m/\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 2 2 4
85 2 $line =~ s/^\s*//, s/\s*$//;
86 2 push @author, $line;
87 }
88 }
89 else {
90 1 @author = ($input);
91 }
92  
93 2 $zilla->{authors} = \@author;
94 }
95  
96 4 ▶sub _parse_copyright {
Subroutine _parse_copyright: called CC=2 SCAR=6.9
97 4 my $self = shift;
98 4 my $zilla = shift;
99 4 my $input = shift;
100  
101 4 ▶ if ( $input =~ m/\A\s*(\d{4})\s+(.+?)\s*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /\A\s*(\d{4})\s+(.+?)\s*\z/) { } 2 2 4
102 2 $zilla->{copyright_year} = $1;
103 2 $zilla->{copyright_holder} = $2;
104 }
105 else {
106 2 $zilla->{copyright_holder} = $input;
107 }
108 }
109  
110 4 ▶sub _parse_license {
Subroutine _parse_license: called CC=2 SCAR=7.0
111 4 my $self = shift;
112 4 my $zilla = shift;
113 4 my $input = shift;
114  
115 4 my $license = $input;
116 4 ▶ if ( $license =~ m/\APerl[\-_]?5/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license =~ /\APerl[\-_]?5/) 4 0 4
117 4 $license = 'Perl_5';
118 }
119  
120 4 $zilla->{license} = $license;
121  
122 }
123  
124 2 1;
125  
« Dist/Dzpl.pm ↑ Summary Dzpl.pm »