blib/lib/Daiku/SuffixRule.pm

filter: Statementstmt 39.6% 25 / 63 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 2 totaltotal 26.7% 31 / 116 SCAR 46.1
CC
15
Cov
27%
_build_deps
90.0
__ANON__
12.0
build
12.0
CRAP 100.8
« blib/lib/Daiku/CLI.pm ↑ Summary blib/lib/Daiku/File.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings FATAL => 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Suffix Rule, same as Makefile.
6 # like '.c.o' in Makefile.
7 package Daiku::SuffixRule;
8 4 ▶use Time::HiRes 1.9701 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 with 'Daiku::Role';
11  
12 4 has src => (
13 is => 'ro',
14 required => 1,
15 );
16 4 has dst => (
17 is => 'ro',
18 isa => 'Str',
19 required => 1,
20 );
21 has code => (
22 is => 'ro',
23 isa => 'CodeRef',
24 default => sub {
25 ▶ sub { }
Subroutine __ANON__: not called CC=1 SCAR=0.0
26 0 ▶ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 4 );
28  
29 has _dst_regex => (
30 is => 'ro',
31 isa => 'Regexp',
32 default => sub {
33 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
34 0 my $dst = $self->dst;
35 0 ▶ ref $dst && ref $dst eq 'Regexp' ? $dst : qr/\Q$dst\E$/;
Branch: 1 branch
BranchTrueFalseTotal
ref $dst && ref $dst eq 'Regexp' ? : 0 0 0
Condition0%0/3
ref $dst and ref $dst eq "Regexp"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dst and ref $dst eq "Regexp"
ref $dst ref $dst eq "Regexp"
Truth table0%0/3
A and B
A= ref $dstB= ref $dst eq "Regexp"
ABresult
0X0
100
111
36 },
37 4 );
38  
39 sub match {
40 0 ▶ my ($self, $target) = @_;
Subroutine match: not called CC=1 SCAR=6.9
Pod undocumented
41 0 $target =~ $self->_dst_regex;
42 }
43  
44 sub build {
45 0 ▶ my ($self, $target) = @_;
Subroutine build: not called CC=3 SCAR=24.8
Pod undocumented
46 0 $self->log("Building SuffixRule: $target");
47 0 my ($built, $need_rebuild, $sources) = $self->_build_deps($target);
48  
49 0 ▶ if ($need_rebuild || !-f $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_rebuild or not -f $target) { } 0 0 0
Condition0%0/3
$need_rebuild or not -f $target
l!l&&r!l&&!r
000
MC/DC0%0/2
$need_rebuild or not -f $target
$need_rebuild not -f $target
Truth table0%0/3
A or not(B)
A= $need_rebuildB= not -f $target
ABresult
1X1
011
000
50 0 $built++;
51 0 $self->code->($self, $target, @$sources);
52 } else {
53 0 $self->debug("There is no reason to regenerate $target");
54 }
55 0 return $built;
56 }
57  
58 sub _build_deps {
59 0 ▶ my ($self, $target) = @_;
Subroutine _build_deps: not called CC=9 SCAR=45.0
60  
61 0 my $built = 0;
62 0 my $need_rebuild = 0;
63 0 my @sources;
64 0 for my $src (_flatten($self->src)) {
65 0 ▶ if ( (ref($src) || '') eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $src || '') eq 'CODE') { } 0 0 0
Condition0%0/2
ref $src || ''
l!l
00
MC/DC0%0/1
ref $src || ''
ref $src
Truth table0%0/2
A
A= ref $src
Aresult
11
00
66 0 my @add_sources = _flatten($src->($target));
67 0 push @sources, @add_sources;
68 }
69 else {
70 0 (my $source = $target) =~ s/@{[$self->_dst_regex]}/$src/;
71 0 push @sources, $source;
72 }
73 }
74  
75 0 for my $source (@sources) {
76 0 my $task = $self->registry->find_task($source);
77 0 ▶ if ($task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($task) { } 0 0 0
78 0 $built += $task->build($source);
79 0 ▶ if (-f $target && -f $source) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $target and -f $source) 0 0 0
Condition0%0/3
-f $target and -f $source
!ll&&!rl&&r
000
MC/DC0%0/2
-f $target and -f $source
-f $target -f $source
Truth table0%0/3
A and B
A= -f $targetB= -f $source
ABresult
0X0
100
111
80 0 ▶ $need_rebuild += 1 if _mtime($target) < _mtime($source);
Branch: 1 branch
BranchTrueFalseTotal
if _mtime($target) < _mtime($source) 0 0 0
81 }
82 } else {
83 0 die "I don't know to build '$source' depended by '$target'\n";
84 }
85 }
86  
87 0 return ($built, $need_rebuild, \@sources);
88 }
89  
90 sub _mtime {
91 0 ▶ my $fname = shift;
Subroutine _mtime: not called CC=1 SCAR=6.9
92 0 (Time::HiRes::stat($fname))[9];
93 }
94  
95 sub _flatten {
96 0 ▶ map { ref $_ && ref $_ eq 'ARRAY' ? _flatten(@{$_}) : $_ } @_;
Subroutine _flatten: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && ref $_ eq 'ARRAY' ? : 0 0 0
Condition0%0/3
ref $_ and ref $_ eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ and ref $_ eq "ARRAY"
ref $_ ref $_ eq "ARRAY"
Truth table0%0/3
A and B
A= ref $_B= ref $_ eq "ARRAY"
ABresult
0X0
100
111
97 }
98  
99 4 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 4 __PACKAGE__->meta->make_immutable;
101  
102 4 1;
103  
« blib/lib/Daiku/CLI.pm ↑ Summary blib/lib/Daiku/File.pm »