File Coverage

blib/lib/Daiku/Role.pm
Criterion Covered Total %
statement 39 39 100.0
branch 4 8 50.0
condition n/a
subroutine 11 11 100.0
pod 0 4 0.0
total 54 62 87.1


line stmt bran cond sub pod time code
1 20     20   8070 use strict;
  20         34  
  20         806  
2 20     20   92 use warnings;
  20         25  
  20         553  
3 20     20   74 use utf8;
  20         29  
  20         127  
4              
5             package Daiku::Role;
6 20     20   9283 use Mouse::Role;
  20         15547  
  20         69  
7 20     20   4116 use Scalar::Util qw/blessed/;
  20         30  
  20         1242  
8 20     20   98 use Carp ();
  20         29  
  20         5726  
9              
10             requires 'build';
11             requires 'match';
12              
13             has registry => (
14             is => 'rw',
15             isa => 'Maybe[Daiku::Registry]',
16             weak_ref => 1,
17             );
18              
19             sub clone {
20 1     1 0 7 my $self = shift;
21              
22 1         2 my %args;
23 1         5 for my $attr ($self->meta->get_attribute_list) {
24 5         32 $args{$attr} = $self->$attr;
25             }
26 1         4 return $self->meta->name->new(%args);
27             }
28              
29             sub log {
30 184     184 0 275 my ($class, @msg) = @_;
31 184         22093 print "[LOG] @msg\n";
32             }
33              
34             sub debug {
35 102     102 0 158 my ($class, @msg) = @_;
36 102 50       313 print "[LOG][DBG] @msg\n" if $ENV{DAIKU_DEBUG};
37             }
38              
39             sub merge {
40 2     2 0 4 my ($self, $task) = @_;
41 2 50       6 return unless $task;
42              
43 2 50       53 Carp::croak("Cannot merge defferent type task: $task")
44             if blessed($self) ne blessed($task);
45              
46 2 50       14 if ($self->can('deps')) {
47 2         3 unshift @{$self->deps}, @{$task->deps};
  2         10  
  2         7  
48             }
49              
50 2         6 my $orig_code = $self->code();
51 2         5 my $other_code = $task->code();
52             $self->code(sub {
53 2     2   6 $other_code->(@_);
54 2         39 $orig_code->(@_);
55 2         16 });
56             }
57              
58             1;
59