Inkt.pm

filter: Statementstmt 25.7% 43 / 167 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 31.2% 10 / 32 Podpod 0.0% 0 / 11 totaltotal 17.7% 53 / 298 CC 33 SCAR 38.7
CC
33
Cov
18%
BUILD
182.0
_build_metadata
30.0
new_from_ini
30.0
CRAP 47.8
↑ Summary Inkt/Role/WriteMakefilePL.pm »
1 package Dist::Inkt;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $AUTHORITY = 'cpan:TOBYINK';
6 1 our $VERSION = '0.026';
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Types::Path::Tiny -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Path::Tiny 'path';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Path::Iterator::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Module::Runtime qw(use_package_optimistically);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub builder_id {
Subroutine builder_id: not called CC=1 SCAR=6.9
Pod undocumented
19 0 my $real_class = shift->_real_class;
20 0 sprintf('%s version %s', $real_class, $real_class->VERSION);
21 }
22  
23 0 ▶sub _real_class {
Subroutine _real_class: not called CC=1 SCAR=6.9
24 0 my $self = shift;
25 0 my ($real_class) = grep !/__ANON__/, Moose::Util::find_meta($self)->class_precedence_list;
26 0 $real_class;
27 }
28  
29 1 has name => (
30 is => 'ro',
31 isa => Str,
32 required => 1,
33 );
34  
35 1 has lead_module => (
36 is => 'ro',
37 isa => Str,
38 lazy => 1,
39 builder => '_build_lead_module',
40 );
41  
42 sub _build_lead_module
43 0 ▶{
Subroutine _build_lead_module: not called CC=1 SCAR=6.9
44 0 my $self = shift;
45 0 (my $name = $self->name) =~ s/-/::/g;
46 0 return $name;
47 }
48  
49 1 has version => (
50 is => 'ro',
51 isa => Str,
52 lazy => 1,
53 builder => '_build_version',
54 );
55  
56 sub _build_version
57 0 ▶{
Subroutine _build_version: not called CC=1 SCAR=6.9
58 0 my $self = shift;
59 0 my $mm = 'Module::Metadata'->new_from_module(
60 $self->lead_module,
61 inc => [$self->sourcefile('lib')],
62 );
63 0 return $mm->{version}{original};
64 }
65  
66 1 has rootdir => (
67 is => 'ro',
68 isa => AbsDir,
69 required => 1,
70 coerce => 1,
71 handles => {
72 sourcefile => 'child',
73 },
74 );
75  
76 1 has targetdir_pattern => (
77 is => 'ro',
78 isa => Str,
79 lazy => 1,
80 builder => '_build_targetdir_pattern',
81 );
82  
83 0 ▶sub _build_targetdir_pattern {
Subroutine _build_targetdir_pattern: not called CC=1 SCAR=6.9
84 0 '%(name)s-%(version)s'
85 }
86  
87 1 has targetdir => (
88 is => 'ro',
89 isa => Path,
90 lazy => 1,
91 coerce => 1,
92 builder => '_build_targetdir',
93 handles => {
94 targetfile => 'child',
95 cleartarget => 'remove_tree',
96 },
97 );
98  
99 sub _build_targetdir
100 0 ▶{
Subroutine _build_targetdir: not called CC=1 SCAR=6.9
101 0 my $self = shift;
102
103 0 require Text::sprintfn;
104 0 my $name = Text::sprintfn::sprintfn(
105 $self->targetdir_pattern,
106 {
107 name => $self->name,
108 version => $self->version,
109 },
110 );
111
112 0 $self->rootdir->child($name);
113 }
114  
115 1 has metadata => (
116 is => 'ro',
117 isa => InstanceOf['CPAN::Meta'],
118 lazy => 1,
119 builder => '_build_metadata',
120 );
121  
122 sub _build_metadata
123 0 ▶{
Subroutine _build_metadata: not called CC=5 SCAR=34.0
124 0 require CPAN::Meta;
125 0 my $self = shift;
126 0 my $meta = 'CPAN::Meta'->new({
127 name => $self->name,
128 version => $self->version,
129 no_index => { directory => [qw/ eg examples inc t xt /] },
130 generated_by => $self->builder_id,
131 dynamic_config => 0,
132 });
133 0 for (qw/ license author /) {
134 0 ▶ $meta->{$_} = [] if @{$meta->{$_}}==1 && $meta->{$_}[0] eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if @{$meta->{$_};} == 1 and $meta->{$_}[0] eq "unknown" 0 0 0
Condition0%0/3
@{$meta->{$_};} == 1 and $meta->{$_}[0] eq "unknown"
!ll&&!rl&&r
000
MC/DC0%0/2
@{$meta->{$_};} == 1 and $meta->{$_}[0] eq "unknown"
@{$meta->{$_};} == 1 $meta->{$_}[0] eq "unknown"
Truth table0%0/3
A and B
A= @{$meta->{$_};} == 1B= $meta->{$_}[0] eq "unknown"
ABresult
0X0
100
111
135 }
136 0 ▶ if ($self->sourcefile('meta/META.PL')->exists)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sourcefile("meta/META.PL")->exists) 0 0 0
137 {
138 0 local $_ = $meta;
139 0 my $filename = $self->sourcefile('meta/META.PL')->absolute->stringify;
140 0 do($filename);
141 }
142 0 return $meta;
143 }
144  
145 1 has project_uri => (
146 is => 'ro',
147 isa => Str,
148 lazy => 1,
149 builder => '_build_project_uri',
150 );
151  
152 sub _build_project_uri
153 0 ▶{
Subroutine _build_project_uri: not called CC=1 SCAR=6.9
154 0 my $self = shift;
155 0 sprintf('http://purl.org/NET/cpan-uri/dist/%s/project', $self->name);
156 }
157  
158 1 has targets => (
159 is => 'ro',
160 isa => ArrayRef[Str],
161 builder => '_build_targets',
162 );
163  
164 0 ▶sub _build_targets { [] }
Subroutine _build_targets: not called CC=1 SCAR=6.9
165  
166 has rights_for_generated_files => (
167 is => 'ro',
168 isa => HashRef[ArrayRef],
169 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 +{
171 0 COPYRIGHT => [ 'None' => 'public-domain' ],
172 };
173 },
174 1 );
175  
176 0 ▶sub _inherited_rights {}
Subroutine _inherited_rights: not called CC=1 SCAR=0.0
177  
178 sub new_from_ini
179 0 ▶{
Subroutine new_from_ini: not called CC=5 SCAR=34.0
Pod undocumented
180 0 my $self = shift;
181 0 my $ini = shift;
182 0 my (%args) = @_;
183
184 0 ▶ if (defined $ini)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ini) { } 0 0 0
185 {
186 0 $ini = File->assert_coerce($ini);
187 }
188 else
189 {
190 0 require Cwd;
191 0 $ini = path(Cwd::cwd)->child('dist.ini');
192 0 ▶ $ini->exists or confess("Could not find dist.ini; bailing out");
Branch: 1 branch
BranchTrueFalseTotal
$ini->exists or confess("Could not find dist.ini; bailing out") 0 0 0
193 }
194
195 0 my @lines = grep /^;;/, $ini->lines_utf8;
196 0 chomp @lines;
197
198 my %config = map {
199 0 s/(?:^;;\s*)|(?:\s*$)//g;
200 0 my ($key, $value) = split /\s*=\s*/, $_, 2;
201 0 $key => scalar(eval($value));
202 } @lines;
203
204 0 ▶ my $class = delete($config{class}) || 'Dist::Inkt::Profile::Simple';
Condition0%0/2
delete $config{'class'} || 'Dist::Inkt::Profile::Simple'
l!l
00
MC/DC0%0/1
delete $config{'class'} || 'Dist::Inkt::Profile::Simple'
delete $config{'class'}
Truth table0%0/2
A
A= delete $config{'class'}
Aresult
11
00
205
206 0 ▶ $config{rootdir} ||= $ini->dirname;
Condition0%0/3
$config{"rootdir"} ||= $ini->dirname
l!l&&r!l&&!r
000
MC/DC0%0/2
$config{"rootdir"} ||= $ini->dirname
$config{"rootdir"} $ini->dirname
Truth table0%0/3
A ||= B
A= $config{"rootdir"}B= $ini->dirname
ABresult
1X1
011
000
207
208 0 use_package_optimistically($class)->new(%config, %args);
209 }
210  
211 sub BUILD
212 0 ▶{
Subroutine BUILD: not called CC=13 SCAR=52.0
Pod undocumented
213 0 my $self = shift;
214 0 ▶ return if $self->{_already_built}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_already_built"}++ 0 0 0
215
216 0 $self->PopulateModel;
217 0 $self->PopulateMetadata;
218
219 0 my $die = 0;
220
221 0 my $l = $self->metadata->{license};
222 0 ▶ unless ($l and ref($l) eq 'ARRAY' and @$l and $l->[0] ne 'unknown')
Branch: 1 branch
BranchTrueFalseTotal
unless ($l and ref $l eq "ARRAY" and @$l and $l->[0] ne "unknown") 0 0 0
Condition0%0/9
$l and ref $l eq "ARRAY" and @$l and $l->[0] ne "unknown"
!ll&&!rl&&r
000
$l and ref $l eq "ARRAY" and @$l
!ll&&!rl&&r
000
$l and ref $l eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
$l and ref $l eq "ARRAY" and @$l and $l->[0] ne "unknown"
$l ref $l eq "ARRAY" @$l $l->[0] ne "unknown"
Truth table0%0/5
A and B and C and D
A= $lB= ref $l eq "ARRAY"C= @$lD= $l->[0] ne "unknown"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
223 {
224 0 $self->log("ERROR: licence unknown!");
225 0 $die++;
226 }
227
228 0 my $a = $self->metadata->{author};
229 0 ▶ unless ($a and ref($a) eq 'ARRAY' and @$a and $a->[0] ne 'unknown')
Branch: 1 branch
BranchTrueFalseTotal
unless ($a and ref $a eq "ARRAY" and @$a and $a->[0] ne "unknown") 0 0 0
Condition0%0/9
$a and ref $a eq "ARRAY" and @$a and $a->[0] ne "unknown"
!ll&&!rl&&r
000
$a and ref $a eq "ARRAY" and @$a
!ll&&!rl&&r
000
$a and ref $a eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
$a and ref $a eq "ARRAY" and @$a and $a->[0] ne "unknown"
$a ref $a eq "ARRAY" @$a $a->[0] ne "unknown"
Truth table0%0/5
A and B and C and D
A= $aB= ref $a eq "ARRAY"C= @$aD= $a->[0] ne "unknown"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
230 {
231 0 $self->log("ERROR: author unknown!");
232 0 $die++;
233 }
234
235 0 my $b = $self->metadata->{abstract};
236 0 ▶ unless (defined($b) and $b ne 'unknown')
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $b and $b ne "unknown") 0 0 0
Condition0%0/3
defined $b and $b ne "unknown"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $b and $b ne "unknown"
defined $b $b ne "unknown"
Truth table0%0/3
A and B
A= defined $bB= $b ne "unknown"
ABresult
0X0
100
111
237 {
238 0 $self->log("ERROR: abstract unknown!");
239 0 $die++;
240 }
241
242 0 ▶ die "Incomplete metadata; stopped" if $die;
Branch: 1 branch
BranchTrueFalseTotal
if $die 0 0 0
243 }
244  
245 0 ▶sub PopulateModel {}
Subroutine PopulateModel: not called CC=1 SCAR=0.0
Pod undocumented
246 0 ▶sub PopulateMetadata {}
Subroutine PopulateMetadata: not called CC=1 SCAR=0.0
Pod undocumented
247  
248 sub BuildTargets
249 0 ▶{
Subroutine BuildTargets: not called CC=5 SCAR=34.0
Pod undocumented
250 0 my $self = shift;
251
252 0 $self->cleartarget;
253 0 $self->targetdir->mkpath;
254
255 0 ▶ $self->Build_Files if $self->DOES('Dist::Inkt::Role::CopyFiles');
Branch: 1 branch
BranchTrueFalseTotal
if $self->DOES("Dist::Inkt::Role::CopyFiles") 0 0 0
256
257 0 for my $target (uniq @{ $self->targets })
258 {
259 0 ▶ next if $self->DOES('Dist::Inkt::Role::CopyFiles') && $target eq 'Files';
Branch: 1 branch
BranchTrueFalseTotal
if $self->DOES("Dist::Inkt::Role::CopyFiles") and $target eq "Files" 0 0 0
Condition0%0/3
$self->DOES("Dist::Inkt::Role::CopyFiles") and $target eq "Files"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->DOES("Dist::Inkt::Role::CopyFiles") and $target eq "Files"
$self->DOES("Dist::Inkt::Role::CopyFiles") $target eq "Files"
Truth table0%0/3
A and B
A= $self->DOES("Dist::Inkt::Role::CopyFiles")B= $target eq "Files"
ABresult
0X0
100
111
260
261 0 my $method = "Build_$target";
262 0 $self->$method;
263 }
264 }
265  
266 sub BuildManifest
267 0 ▶{
Subroutine BuildManifest: not called CC=2 SCAR=17.9
Pod undocumented
268 0 my $self = shift;
269
270 0 my $file = $self->targetfile('MANIFEST');
271 0 $self->log("Writing $file");
272 0 ▶ $self->rights_for_generated_files->{'MANIFEST'} ||= [
Condition0%0/2
$self->rights_for_generated_files->{"MANIFEST"} ||= ["None", "public-domain"]
l!l
00
MC/DC0%0/1
$self->rights_for_generated_files->{"MANIFEST"} ||= ["None", "public-domain"]
$self->rights_for_generated_files->{"MANIFEST"}
Truth table0%0/2
A
A= $self->rights_for_generated_files->{"MANIFEST"}
Aresult
11
00
273 'None', 'public-domain'
274 ];
275
276 0 my $rule = 'Path::Iterator::Rule'->new->file;
277 0 my $root = $self->targetdir;
278 0 my @files = map { path($_)->relative($root) } $rule->all($root);
279
280 0 $file->spew(map "$_\n", sort 'MANIFEST', @files);
281 }
282  
283 sub BuildTarball
284 0 ▶{
Subroutine BuildTarball: not called CC=3 SCAR=24.8
Pod undocumented
285 0 my $self = shift;
286 0 ▶ my $file = path($_[0] || sprintf('%s.tar.gz', $self->targetdir));
Condition0%0/3
$_[0] || sprintf('%s.tar.gz', $self->targetdir)
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] || sprintf('%s.tar.gz', $self->targetdir)
$_[0] sprintf('%s.tar.gz', $self->targetdir)
Truth table0%0/3
A || B
A= $_[0]B= sprintf('%s.tar.gz', $self->targetdir)
ABresult
1X1
011
000
287 0 $self->log("Writing $file");
288
289 0 require Archive::Tar;
290 0 my $tar = 'Archive::Tar'->new;
291
292 0 my $rule = 'Path::Iterator::Rule'->new->file;
293 0 my $root = $self->targetdir;
294 0 my $pfx = $root->basename;
295 0 for ($rule->all($root))
296 {
297 0 my $abs = path($_);
298 0 $tar->add_data( "$pfx/" . $abs->relative($root), $abs->slurp );
299 }
300
301 0 $tar->write($file, Archive::Tar::COMPRESS_GZIP());
302 }
303  
304 has should_compress => (
305 is => 'ro',
306 isa => Bool,
307 0 ▶ default => sub { !$ENV{PERL_DIST_INKT_NOTARBALL} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
308 1 );
309  
310 sub BuildAll
311 0 ▶{
Subroutine BuildAll: not called CC=2 SCAR=17.9
Pod undocumented
312 0 my $self = shift;
313 0 $self->BuildTargets;
314 0 $self->BuildManifest;
315 0 ▶ if ($self->should_compress) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->should_compress) 0 0 0
316 0 $self->BuildTarball;
317 0 $self->cleartarget;
318 }
319 }
320  
321 sub BuildTravisYml
322 0 ▶{
Subroutine BuildTravisYml: not called CC=5 SCAR=34.0
Pod undocumented
323 0 my $self = shift;
324
325 0 $self->log("Generating .travis.yml");
326 0 my $yml = $self->sourcefile(".travis.yml")->openw;
327
328 0 ▶ my $perl_ver = $self->metadata->{prereqs}{runtime}{requires}{perl} || '5.014';
Condition0%0/2
$self->metadata->{'prereqs'}{'runtime'}{'requires'}{'perl'} || '5.014'
l!l
00
MC/DC0%0/1
$self->metadata->{'prereqs'}{'runtime'}{'requires'}{'perl'} || '5.014'
$self->metadata->{'prereqs'}{'runtime'}{'requires'}{'perl'}
Truth table0%0/2
A
A= $self->metadata->{'prereqs'}{'runtime'}{'requires'}{'perl'}
Aresult
11
00
329
330 0 print {$yml} "language: perl\n";
331 0 print {$yml} "perl:\n";
332 0 for my $v (8, 10, 12, 14, 16, 18, 20)
333 {
334 0 my $formatted = sprintf("5.%03d000", $v);
335 0 ▶ $formatted = '5.008001' if $formatted eq '5.008000';
Branch: 1 branch
BranchTrueFalseTotal
if $formatted eq "5.008000" 0 0 0
336
337 0 ▶ if ($formatted ge $perl_ver)
Branch: 1 branch
BranchTrueFalseTotal
if ($formatted ge $perl_ver) 0 0 0
338 {
339 0 print {$yml} " - \"5.$v\"\n";
340 }
341 }
342
343 0 my $class = $self->_real_class;
344
345 ## no Test::Tabs
346
347 0 print {$yml} <<"TAIL";
348 matrix:
349 include:
350 - perl: 5.18.2
351 env: COVERAGE=1
352 before_install:
353 - export DIST_INKT_PROFILE="$class"
354 - git clone git://github.com/tobyink/perl-travis-helper
355 - source perl-travis-helper/init
356 - build-perl
357 - perl -V
358 - build-dist
359 - cd \$BUILD_DIR
360 install:
361 - cpan-install --toolchain
362 - cpan-install --deps
363 - cpan-install --coverage
364 before_script:
365 - coverage-setup
366 script:
367 - prove -l \$(test-dirs)
368 after_success:
369 - coverage-report
370  
371 TAIL
372  
373 ## use Test::Tabs
374
375 0 return;
376 }
377  
378 sub log
379 0 ▶{
Subroutine log: not called CC=1 SCAR=6.9
Pod undocumented
380 0 my $self = shift;
381 0 my ($fmt, @args) = @_;
382 0 printf STDERR "$fmt\n", @args;
383 }
384  
385 1 1;
386  
387 __END__
↑ Summary Inkt/Role/WriteMakefilePL.pm »