| 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
Condition0%0/3
ref $dst and ref $dst eq "Regexp"
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"
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$need_rebuild or not -f $target
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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/2
ref $src || ''
MC/DC0%0/1
ref $src || ''
ref $src
Truth table0%0/2
A
A= ref $src
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | 0 | $built += $task->build($source); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (-f $target && -f $source) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $target and -f $source
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
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $need_rebuild += 1 if _mtime($target) < _mtime($source); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $_ and ref $_ eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||