| 1 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 5 | ▶ | use warnings FATAL => 'recursion'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | # This is .PHONY target. | ||||||||||
| 6 | package Daiku::Task; | ||||||||||
| 7 | 5 | ▶ | use File::stat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 5 | with 'Daiku::Role'; | |||||||||
| 11 | |||||||||||
| 12 | 5 | has dst => ( | |||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | isa => 'Str', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | ); | ||||||||||
| 17 | has deps => ( | ||||||||||
| 18 | is => 'rw', | ||||||||||
| 19 | isa => 'ArrayRef[Str]', | ||||||||||
| 20 | 5 | ▶ | default => sub { +[ ] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 5 | ); | |||||||||
| 22 | has code => ( | ||||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'CodeRef', | ||||||||||
| 25 | default => sub { | ||||||||||
| 26 | ▶ | sub { } | |||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 2 | ▶ | }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 5 | ); | |||||||||
| 29 | 5 | has desc => ( | |||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | isa => 'Maybe[Str]', | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | # @return affected things | ||||||||||
| 35 | sub build { | ||||||||||
| 36 | 7 | ▶ | my ($self, $target, @args) = @_; | ||||||||
|
Subroutine
build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 7 | $self->log("Building Task: $self->{dst}"); | |||||||||
| 38 | |||||||||||
| 39 | 7 | my $built = $self->_build_deps(); | |||||||||
| 40 | |||||||||||
| 41 | 7 | $self->code->($self, @args); | |||||||||
| 42 | 7 | $built++; | |||||||||
| 43 | |||||||||||
| 44 | 7 | return $built; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub match { | ||||||||||
| 48 | 37 | ▶ | my ($self, $target) = @_; | ||||||||
|
Subroutine
match: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 49 | 37 | ▶ | return 1 if $self->dst eq $target; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 30 | return 0; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | # @return the number of built tasks | ||||||||||
| 54 | sub _build_deps { | ||||||||||
| 55 | 7 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_deps: called CC=3 SCAR=11.2
| |||||||||||
| 56 | |||||||||||
| 57 | 7 | my $ret = 0; | |||||||||
| 58 | 7 | for my $target (@{$self->deps}) { | |||||||||
| 59 | 5 | my $task = $self->registry->find_task($target); | |||||||||
| 60 | 5 | ▶ | if ($task) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 5 | $ret += $task->build($target); | |||||||||
| 62 | } else { | ||||||||||
| 63 | 0 | die "I don't know to build '$target' depended by '$self->{dst}'\n"; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | 7 | return $ret; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 5 | ▶ | no Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||
| 71 | |||||||||||
| 72 | 5 | 1; | |||||||||
| 73 | __END__ | ||||||||||