Minilla/Metadata.pm

filter: Statementstmt 29.1% 35 / 120 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 10 / 20 Podpod n/a totaltotal 22.9% 45 / 196 CC 28 SCAR 32.2
CC
28
Cov
20%
_build_authors
56.0
_build_license
56.0
_build_abstract
30.0
CRAP 25.1
« Minilla/ModuleMaker/ModuleBuildTiny.pm ↑ Summary Minilla/Git.pm »
1 package Minilla::Metadata;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Minilla::Util qw(slurp slurp_utf8 require_optional);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Minilla::License::Perl_5;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Pod::Escapes;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has [qw(abstract perl_version authors license)] => (
14 is => 'lazy',
15 );
16  
17 1 has '_license_name' => (
18 is => 'ro',
19 );
20  
21 1 has metadata => (
22 is => 'lazy',
23 handles => [qw(name version)],
24 );
25  
26 has source => (
27 is => 'rw',
28 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
29 0 ▶ defined $_[0] or Carp::confess("source should not be undef");
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or Carp::confess("source should not be undef") 0 0 0
30 0 ▶ -f $_[0] or Carp::confess("source file not found: '$_[0]'");
Branch: 1 branch
BranchTrueFalseTotal
-f $_[0] or Carp::confess("source file not found: '$_[0]'") 0 0 0
31 },
32 1 required => 1,
33 );
34  
35 1 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 0 ▶sub _build_metadata {
Subroutine _build_metadata: not called CC=1 SCAR=6.9
38 0 my $self = shift;
39 0 Module::Metadata->new_from_file($self->source, collect_pod => 1, decode_pod => 1);
40 }
41  
42 # Taken from Module::Install::Metadata
43 0 ▶sub _build_abstract {
Subroutine _build_abstract: not called CC=5 SCAR=34.0
44 0 my ($self) = @_;
45  
46 # find by EU::MM
47 {
48 0 require ExtUtils::MM_Unix;
49 0 my $abstract = bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($self->source);
50 0 ▶ return $abstract if $abstract;
Branch: 1 branch
BranchTrueFalseTotal
if $abstract 0 0 0
51 }
52 # Parsing pod with Module::Metadata
53 {
54 0 my $name = $self->metadata->pod('NAME');
55 0 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 0 0
56 0 $name =~ s/^\s+//gxsm;
57 0 $name =~ s/\s+$//gxsm;
58 0 my ($pkg, $abstract) = split /\s+-\s+/, $name, 2;
59 0 ▶ return $abstract if $abstract;
Branch: 1 branch
BranchTrueFalseTotal
if $abstract 0 0 0
60 }
61 }
62 # find dzil style '# ABSTRACT: '
63 {
64 0 ▶ if (slurp($self->source) =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m) {
Branch: 1 branch
BranchTrueFalseTotal
if (slurp($self->source) =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m) 0 0 0
65 0 return $1;
66 }
67 }
68 0 return;
69 }
70  
71 0 ▶sub _extract_perl_version {
Subroutine _extract_perl_version: not called CC=2 SCAR=17.9
72 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ / ^\s* (?:use|require) \s* (v?[\d_\.]+) \s* ; /imsx) { } 0 0 0
73 $_[0] =~ m/
74 ^\s*
75 (?:use|require) \s*
76 (v?[\d_\.]+)
77 \s* ;
78 /ixms
79 ) {
80 0 my $perl_version = $1;
81 0 $perl_version =~ s{_}{}g;
82 0 return $perl_version;
83 } else {
84 0 return;
85 }
86 }
87  
88 0 ▶sub _build_perl_version {
Subroutine _build_perl_version: not called CC=2 SCAR=17.9
89 0 my ($self) = @_;
90  
91 0 my $perl_version = _extract_perl_version(slurp($self->source));
92 0 ▶ if ($perl_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl_version) { } 0 0 0
93 0 return $perl_version;
94 } else {
95 0 return;
96 }
97 }
98  
99 0 ▶sub _build_authors {
Subroutine _build_authors: not called CC=7 SCAR=40.3
100 0 my ($self) = @_;
101  
102 0 my $content = slurp_utf8($self->source);
103 0 ▶ if ($content =~ m/
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / ^=head1 \s+ (?:authors?)\b \s* ([^\n]+) /mix or $content =~ / ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]+) /imsx) { } 0 0 0
Condition0%0/3
$content =~ / ^=head1 \s+ (?:authors?)\b \s* ([^\n]+) /mix or $content =~ / ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]+) /imsx
l!l&&r!l&&!r
000
MC/DC0%0/2
$content =~ / ^=head1 \s+ (?:authors?)\b \s* ([^\n]+) /mix or $content =~ / ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]+) /imsx
$content =~ / ^=head1 \s+ (?:authors?)\b \s* ([^\n]+) /mix $content =~ / ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]+) /imsx
Truth table0%0/3
A or B
A= $content =~ / ^=head1 \s+ (?:authors?)\b \s* ([^\n]+) /mixB= $content =~ / ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]+) /imsx
ABresult
1X1
011
000
104 ^=head1 \s+ (?:authors?)\b \s*
105 ([^\n]+)
106 /ixm || $content =~ m/
107 ^=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
108 .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
109 ([^\n]+)
110 /ixms) {
111 0 my $author = $1;
112  
113 0 $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }{
114 defined $2
115 ? chr($2)
116 : defined $Pod::Escapes::Name2character_number{$1}
117 ? chr($Pod::Escapes::Name2character_number{$1})
118 0 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
defined $2 ? : 0 0 0
defined $Pod::Escapes::Name2character_number{$1} ? : 0 0 0
119 0 warn "Unknown escape: E<$1>";
120 0 "E<$1>";
121 };
122 }gex;
123  
124 0 my @authors;
125 0 for (split /\n/, $author) {
126 0 chomp;
127 0 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
128 0 push @authors, $_;
129 }
130 0 return \@authors;
131 } else {
132 0 warn "Cannot determine author info from @{[ $_[0]->source ]}\n";
133 0 return undef;
134 }
135 }
136  
137  
138 #Stolen from M::B
139 0 ▶sub _is_perl5_license {
Subroutine _is_perl5_license: not called CC=2 SCAR=17.9
140 0 my $pod = shift;
141 0 my $matched;
142 0 ▶ return __extract_license(
Condition0%0/3
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) || __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
l!l&&r!l&&!r
000
MC/DC0%0/2
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) || __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
__extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx) __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
Truth table0%0/3
A || B
A= __extract_license(($matched) = $pod =~ / (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /msx)B= __extract_license(($matched) = $pod =~ / (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /msx)
ABresult
1X1
011
000
143 ($matched) = $pod =~ m/
144 (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
145 (=head \d.*|=cut.*|)\z
146 /xms
147 ) || __extract_license(
148 ($matched) = $pod =~ m/
149 (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
150 (=head \d.*|=cut.*|)\z
151 /xms
152 );
153 }
154  
155 0 ▶sub __extract_license {
Subroutine __extract_license: not called CC=4 SCAR=30.0
156 0 ▶ my $license_text = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $license_text = shift() or return 0 0 0
157 0 my @phrases = (
158 '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)',
159 '(?:under )?the terms of (?:perl|the perl programming language) itself',
160 'Artistic and GPL'
161 );
162 0 for my $pattern (@phrases) {
163 0 $pattern =~ s#\s+#\\s+#gs;
164 0 ▶ if ( $license_text =~ /\b$pattern\b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license_text =~ /\b$pattern\b/i) 0 0 0
165 0 return 1;
166 }
167 }
168 0 return 0;
169 }
170  
171 0 ▶sub _guess_license_class_by_name {
Subroutine _guess_license_class_by_name: not called CC=4 SCAR=30.0
172 0 my ($name) = @_;
173  
174 0 ▶ if ($name eq 'Perl_5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'Perl_5') { } 0 0 0
175 0 return 'Minilla::License::Perl_5'
176 } else {
177 0 my %license_map = (
178 'agpl_3' => 'Software::License::AGPL_3',
179 'apache_1_1' => 'Software::License::Apache_1_1',
180 'apache_2_0' => 'Software::License::Apache_2_0',
181 'artistic_1' => 'Software::License::Artistic_1_0',
182 'artistic_2' => 'Software::License::Artistic_2_0',
183 'bsd' => 'Software::License::BSD',
184 'unrestricted' => 'Software::License::CC0_1_0',
185 'custom' => 'Software::License::Custom',
186 'freebsd' => 'Software::License::FreeBSD',
187 'gfdl_1_2' => 'Software::License::GFDL_1_2',
188 'gfdl_1_3' => 'Software::License::GFDL_1_3',
189 'gpl_1' => 'Software::License::GPL_1',
190 'gpl_2' => 'Software::License::GPL_2',
191 'gpl_3' => 'Software::License::GPL_3',
192 'lgpl_2_1' => 'Software::License::LGPL_2_1',
193 'lgpl_3_0' => 'Software::License::LGPL_3_0',
194 'mit' => 'Software::License::MIT',
195 'mozilla_1_0' => 'Software::License::Mozilla_1_0',
196 'mozilla_1_1' => 'Software::License::Mozilla_1_1',
197 'open_source' => 'Software::License::Mozilla_2_0',
198 'restricted' => 'Software::License::None',
199 'openssl' => 'Software::License::OpenSSL',
200 'perl_5' => 'Software::License::Perl_5',
201 'open_source' => 'Software::License::PostgreSQL',
202 'qpl_1_0' => 'Software::License::QPL_1_0',
203 'ssleay' => 'Software::License::SSLeay',
204 'sun' => 'Software::License::Sun',
205 'zlib' => 'Software::License::Zlib',
206 );
207 0 ▶ if (my $klass = $license_map{lc $name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $klass = $license_map{lc $name}) { } 0 0 0
208 0 ▶ eval "require $klass; 1" or die "$klass is required for supporting $name license. But: $@"; ## no critic.
Branch: 1 branch
BranchTrueFalseTotal
eval "require $klass; 1" or die "$klass is required for supporting $name license. But: $@" 0 0 0
209 0 return $klass;
210 } else {
211 0 die "'$name' is not supported yet. Supported licenses are: " . join(', ', keys %license_map);
212 }
213 }
214 }
215  
216 0 ▶sub _build_license {
Subroutine _build_license: not called CC=7 SCAR=40.3
217 0 my ($self) = @_;
218  
219 0 my $pm_text = slurp($self->source);
220 0 ▶ my $holder = $self->authors ? $self->authors->[0] : 'Unknown';
Branch: 1 branch
BranchTrueFalseTotal
$self->authors ? : 0 0 0
221 0 ▶ if ($self->_license_name) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_license_name) { } 0 0 0
elsif (_is_perl5_license($pm_text)) { } 0 0 0
222 0 _guess_license_class_by_name($self->_license_name)->new({
223 holder => $holder,
224 });
225 } elsif (_is_perl5_license($pm_text)) {
226 0 require Minilla::License::Perl_5;
227 0 return Minilla::License::Perl_5->new({
228 holder => $holder,
229 });
230 } else {
231 0 ▶ if (eval "require Software::LicenseUtils; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require Software::LicenseUtils; 1') { } 0 0 0
232 0 my (@guesses) = Software::LicenseUtils->guess_license_from_pod($pm_text);
233 0 ▶ if (@guesses) {
Branch: 1 branch
BranchTrueFalseTotal
if (@guesses) { } 0 0 0
234 0 my $klass = $guesses[0];
235 0 ▶ eval "require $klass; 1" or die $@; ## no critic.
Branch: 1 branch
BranchTrueFalseTotal
eval "require $klass; 1" or die $@ 0 0 0
236 0 $klass->new({
237 holder => $holder,
238 });
239 } else {
240 0 warn "Cannot determine license info from @{[ $_[0]->source ]}\n";
241 0 require Minilla::License::Unknown;
242 0 return Minilla::License::Unknown->new({
243 holder => $holder,
244 });
245 }
246 } else {
247 0 warn "Software::License is needed when you want to use non Perl_5 license.\n";
248 0 require Minilla::License::Unknown;
249 0 return Minilla::License::Unknown->new({
250 holder => $holder,
251 });
252 }
253 }
254 }
255  
256 1 1;
257  
« Minilla/ModuleMaker/ModuleBuildTiny.pm ↑ Summary Minilla/Git.pm »