blib/lib/Dist/Zilla/Util.pm

filter: Statementstmt 94.0% 63 / 67 Branchbran 76.6% 23 / 30 Conditioncond 27.2% 3 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 93.7% 15 / 16 Podpod 66.6% 2 / 3 totaltotal 79.8% 107 / 134 CC 20 SCAR 15.0
CC
20
Cov
82%
homedir
10.8
_handle_element_end
7.1
_global_config_root
5.7
CRAP 4.5
« blib/lib/Dist/Zilla/Plugin/GatherDir/Template.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Encoding.pm »
1 package Dist::Zilla::Util 6.040;
2 # ABSTRACT: random snippets of code that Dist::Zilla wants
3  
4 55 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 55 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 55 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 55 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 {
12 package
13 Dist::Zilla::Util::PEA;
14 55 @Dist::Zilla::Util::PEA::ISA = ('Pod::Simple');
15  
16 14 ▶ sub _new {
Subroutine _new: called CC=1 SCAR=0.0
17 14 my ($class, @args) = @_;
18 14 require Pod::Simple;
19 14 my $parser = $class->new(@args);
20 131 ▶ $parser->code_handler(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
21 131 my ($line, $line_number, $parser) = @_;
22 131 ▶ return if $parser->{abstract};
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"abstract"} 88 43 131
23  
24  
25 43 ▶ return $parser->{abstract} = $1
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#+\s*ABSTRACT:[ \t]*(\S.*)$/mu 7 36 43
26 if $line =~ /^\s*#+\s*ABSTRACT:[ \t]*(\S.*)$/m;
27 36 return;
28 14 });
29 14 return $parser;
30 }
31  
32 61 ▶ sub _handle_element_start {
Subroutine _handle_element_start: called CC=4 SCAR=13.9
33 61 my ($parser, $ele_name, $attr) = @_;
34  
35 61 ▶ if ($ele_name eq 'head1') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ele_name eq 'head1') { } 19 42 61
elsif ($ele_name eq 'Para') { } 17 25 42
elsif ($ele_name eq 'C') { } 4 21 25
36 19 $parser->{buffer} = "";
37 }
38 elsif ($ele_name eq 'Para') {
39 17 $parser->{buffer} = "";
40 }
41 elsif ($ele_name eq 'C') {
42 4 $parser->{in_C} = 1;
43 }
44  
45 61 return;
46 }
47  
48 61 ▶ sub _handle_element_end {
Subroutine _handle_element_end: called CC=7 SCAR=19.7
49 61 my ($parser, $ele_name, $attr) = @_;
50  
51 61 ▶ return if $parser->{abstract};
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"abstract"} 46 15 61
52 15 ▶ if ($ele_name eq 'head1') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ele_name eq 'head1') { } 7 8 15
elsif ($ele_name eq 'Para' and $parser->{'in_section'} eq 'NAME') { } 7 1 8
elsif ($ele_name eq 'C') { } 1 0 1
53 7 $parser->{in_section} = $parser->{buffer};
54 }
55 ▶ elsif ($ele_name eq 'Para' && $parser->{in_section} eq 'NAME' ) {
Condition66%2/3
$ele_name eq "Para" and $parser->{"in_section"} eq "NAME"
!ll&&!rl&&r
107
MC/DC50%1/2
$ele_name eq "Para" and $parser->{"in_section"} eq "NAME"
$ele_name eq "Para" $parser->{"in_section"} eq "NAME"
Truth table66%2/3
A and B
A= $ele_name eq "Para"B= $parser->{"in_section"} eq "NAME"
ABresult
0X0
100
111
56 7 ▶ if ($parser->{buffer} =~ /^(?:\S+\s+)+?-+\s+(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{"buffer"} =~ /^(?:\S+\s+)+?-+\s+(.+)$/su) 7 0 7
57 7 $parser->{abstract} = $1;
58 }
59 }
60 elsif ($ele_name eq 'C') {
61 1 delete $parser->{in_C};
62 }
63  
64 15 return;
65 }
66  
67 49 ▶ sub _handle_text {
Subroutine _handle_text: called CC=2 SCAR=6.9
68 49 my ($parser, $text) = @_;
69  
70 # The C<...> tags are expected to be preserved. MetaCPAN renders them.
71 49 ▶ if ($parser->{in_C}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{'in_C'}) { } 9 40 49
72 9 $parser->{buffer} .= "C<$text>";
73 }
74 else {
75 40 $parser->{buffer} .= $text;
76 }
77 49 return;
78 }
79 }
80  
81 #pod =method abstract_from_file
82 #pod
83 #pod This method, I<which is likely to change or go away>, tries to guess the
84 #pod abstract of a given file, assuming that it's Perl code. It looks for a POD
85 #pod C<=head1> section called "NAME" or a comment beginning with C<ABSTRACT:>.
86 #pod
87 #pod =cut
88  
89 55 ▶sub abstract_from_file {
Subroutine abstract_from_file: called CC=1 SCAR=0.0
Pod documented
90 8 my ($self, $file) = @_;
91 8 my $e = Dist::Zilla::Util::PEA->_new;
92  
93 8 $e->parse_string_document($file->content);
94  
95 8 return $e->{abstract};
96 }
97  
98 #pod =method expand_config_package_name
99 #pod
100 #pod my $pkg_name = Dist::Zilla::Util->expand_config_package_name($string);
101 #pod
102 #pod This method, I<which is likely to change or go away>, rewrites the given string
103 #pod into a package name.
104 #pod
105 #pod Prefixes are rewritten as follows:
106 #pod
107 #pod =for :list
108 #pod * C<=> becomes nothing
109 #pod * C<@> becomes C<Dist::Zilla::PluginBundle::>
110 #pod * C<%> becomes C<Dist::Zilla::Stash::>
111 #pod * otherwise, C<Dist::Zilla::Plugin::> is prepended
112 #pod
113 #pod =cut
114  
115 55 ▶use String::RewritePrefix 0.006 rewrite => {
Subroutine BEGIN: called CC=1 SCAR=0.0
116 -as => '_expand_config_package_name',
117 prefixes => {
118 '=' => '',
119 '@' => 'Dist::Zilla::PluginBundle::',
120 '%' => 'Dist::Zilla::Stash::',
121 '' => 'Dist::Zilla::Plugin::',
122 },
123 55 };
124  
125 708 ▶sub expand_config_package_name {
Subroutine expand_config_package_name: called CC=1 SCAR=0.0
Pod documented
126 708 shift; goto &_expand_config_package_name
127 }
128  
129 0 ▶sub homedir {
Subroutine homedir: not called CC=4 SCAR=23.7
Pod undocumented
130 0 ▶ $^O eq 'MSWin32' && "$]" < 5.016 ? $ENV{HOME} || $ENV{USERPROFILE} : (glob('~'))[0];
Subroutine BEGIN: called CC=1 SCAR=3.5
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' && "$]" < 5.016 ? : 0 0 0
Condition0%0/6
$^O eq "MSWin32" and "$]" < "5.016"
!ll&&!rl&&r
000
$ENV{"HOME"} or $ENV{"USERPROFILE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O eq "MSWin32" and "$]" < "5.016"
$^O eq "MSWin32" "$]" < "5.016"
MC/DC0%0/2
$ENV{"HOME"} or $ENV{"USERPROFILE"}
$ENV{"HOME"} $ENV{"USERPROFILE"}
Truth table0%0/3
A and B
A= $^O eq "MSWin32"B= "$]" < "5.016"
ABresult
0X0
100
111
Truth table0%0/3
A or B
A= $ENV{"HOME"}B= $ENV{"USERPROFILE"}
ABresult
1X1
011
000
131 }
132  
133 1 ▶sub _global_config_root {
Subroutine _global_config_root: called CC=3 SCAR=17.3
134 1 require Dist::Zilla::Path;
135 1 ▶ return Dist::Zilla::Path::path($ENV{DZIL_GLOBAL_CONFIG_ROOT}) if $ENV{DZIL_GLOBAL_CONFIG_ROOT};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DZIL_GLOBAL_CONFIG_ROOT"} 1 0 1
136  
137 0 my $homedir = homedir();
138 0 ▶ Carp::croak("couldn't determine home directory") if not $homedir;
Branch: 1 branch
BranchTrueFalseTotal
unless $homedir 0 0 0
139  
140 0 return Dist::Zilla::Path::path($homedir)->child('.dzil');
141 }
142  
143 2 ▶sub _assert_loaded_class_version_ok {
Subroutine _assert_loaded_class_version_ok: called CC=3 SCAR=11.0
144 2 my ($self, $pkg, $version) = @_;
145  
146 2 require CPAN::Meta::Requirements;
147 2 my $req = CPAN::Meta::Requirements->from_string_hash({
148 $pkg => $version,
149 });
150  
151 2 my $have_version = $pkg->VERSION;
152 2 ▶ unless ($req->accepts_module($pkg => $have_version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->accepts_module($pkg, $have_version)) 1 1 2
153 1 ▶ die( sprintf
Condition50%1/2
$have_version // "undef"
l!l
10
MC/DC0%0/1
$have_version // "undef"
$have_version
Truth table50%1/2
A
A= $have_version
Aresult
11
00
154 "%s version (%s) does not match required version: %s\n",
155 $pkg,
156 $have_version // 'undef',
157 $version,
158 );
159 }
160 }
161  
162 55 1;
163  
164 __END__
« blib/lib/Dist/Zilla/Plugin/GatherDir/Template.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Encoding.pm »