| 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 | package Daiku::File; | ||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use File::stat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Time::HiRes 1.9701 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | with 'Daiku::Role'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | has dst => ( | |||||||||||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||||||||||
| 14 | isa => 'Str', | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | has deps => ( | ||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { +[] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 22 | 4 | ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | has code => ( | ||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | isa => 'CodeRef', | ||||||||||||||||||||||||||||
| 27 | default => sub { | ||||||||||||||||||||||||||||
| 28 | ▶ | sub { } | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | 4 | ); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub build { | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $self->log("Processing file: $self->{dst}"); | |||||||||||||||||||||||||||
| 36 | 0 | my ($built, $need_rebuild) = $self->_build_deps(); | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($need_rebuild || (!-f $self->dst)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$need_rebuild or not -f $self->dst
MC/DC0%0/2
$need_rebuild or not -f $self->dst
$need_rebuild
not -f $self->dst
Truth table0%0/3
A or not(B)
A= $need_rebuildB= not -f $self->dst
| |||||||||||||||||||||||||||||
| 38 | 0 | $self->log(" Building file: $self->{dst}($need_rebuild)"); | |||||||||||||||||||||||||||
| 39 | 0 | $built++; | |||||||||||||||||||||||||||
| 40 | 0 | $self->code->($self); | |||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||
| 42 | 0 | $self->debug("There is no reason to regenerate $self->{dst}"); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | return $built; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub match { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($self, $target) = @_; | ||||||||||||||||||||||||||
|
Subroutine
match: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return 1 if $self->dst eq $target; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | return 0; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # @return need rebuild | ||||||||||||||||||||||||||||
| 54 | sub _build_deps { | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_deps: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $built = 0; | |||||||||||||||||||||||||||
| 58 | 0 | my $need_rebuild = 0; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | for my $target (@{$self->deps || []}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | my $task = $self->registry->find_task($target); | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($task) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $built += $task->build($target); | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (-f $target) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $need_rebuild += $self->_check_need_rebuild($target); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||
| 67 | 0 | die "I don't know to build '$target' depended by '$self->{dst}'\n"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | return ($built, $need_rebuild); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub _check_need_rebuild { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my ($self, $target) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_check_need_rebuild: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $m1 = _mtime($target); | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | return 0 unless -f $self->dst; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $m2 = _mtime($self->dst); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return 1 if $m2 < $m1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | return 0; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub _mtime { | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $fname = shift; | ||||||||||||||||||||||||||
|
Subroutine
_mtime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 0 | (Time::HiRes::stat($fname))[9]; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 4 | ▶ | no Mouse; __PACKAGE__->meta->make_immutable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||