File Coverage

blib/lib/Daiku.pm
Criterion Covered Total %
statement 60 60 100.0
branch 14 16 87.5
condition 2 3 66.6
subroutine 14 14 100.0
pod 6 7 85.7
total 96 100 96.0


line stmt bran cond sub pod time code
1 19     19   704543 use strict;
  19         42  
  19         861  
2 19     19   90 use warnings FATAL => 'recursion';
  19         26  
  19         1369  
3              
4             package Daiku;
5 19     19   572 use 5.008001;
  19         57  
  19         965  
6             our $VERSION = '1.003';
7 19     19   6321 use Daiku::Registry;
  19         1613  
  19         662  
8 19     19   13705 use IPC::System::Simple ();
  19         246833  
  19         719  
9 19     19   173 use Exporter qw(import);
  19         29  
  19         11790  
10              
11             our @EXPORT = our @EXPORT_OK =
12             qw(desc task file rule sh namespace engine build);
13              
14             my %engine_for = ();
15              
16             sub _engine {
17 135     135   217 my ($caller_package) = @_;
18 135   66     1142 return ($engine_for{$caller_package} ||= Daiku::Registry->new());
19             }
20              
21             sub engine {
22 17     17 0 718 return _engine(caller(0));
23             }
24              
25             sub desc($) {
26 8     8 1 730 my $desc = shift;
27              
28 8         52 _engine(caller(0))->temporary_desc($desc);
29             }
30              
31             # task 'all' => ['a', 'b'];
32             # task 'all' => ['a', 'b'] => sub { ... };
33             sub task($$;&) {
34 45     45 1 2337 my %args;
35 45         114 $args{dst} = shift @_;
36 45 100       153 if (ref($_[-1]) eq 'CODE') {
37 42         83 $args{code} = pop @_;
38             }
39 45 100       109 if (@_) {
40 6         14 $args{deps} = shift @_;
41 6 100       37 $args{deps} = [$args{deps}] if !ref $args{deps};
42             }
43 45         283 my $engine = _engine(caller(0));
44 45         157 my $desc = $engine->clear_temporary_desc;
45 45 100       112 if (defined $desc) {
46 8         19 $args{desc} = $desc;
47             }
48 45         53 $args{dst} = join ':', @{ $engine->namespaces }, $args{dst};
  45         188  
49              
50 45         448 my $task = Daiku::Task->new( %args );
51 45         243 $engine->register($task);
52             }
53              
54             # file 'all' => ['a', 'b'];
55             # file 'all' => 'a';
56             # file 'all' => ['a', 'b'] => sub { ... };
57             sub file($$;&) {
58 14     14 1 2635 my %args;
59 14         40 $args{dst} = shift @_;
60 14 50       56 if (ref($_[-1]) eq 'CODE') {
61 14         33 $args{code} = pop @_;
62             }
63 14 100       42 if (@_) {
64 13         36 $args{deps} = shift @_;
65 13 100       58 $args{deps} = [$args{deps}] if !ref $args{deps};
66             }
67 14         229 my $file = Daiku::File->new( %args );
68 14         704 _engine(caller(0))->register($file);
69             }
70              
71             # rule '.c' => '.o' => sub { ... };
72             sub rule($$;&) {
73 9     9 1 840 my %args;
74 9         41 @args{qw/dst src code/} = @_;
75 9 50       37 delete $args{code} unless defined $args{code};
76 9         137 my $rule = Daiku::SuffixRule->new( %args );
77 9         74 _engine(caller(0))->register($rule);
78             }
79              
80             sub namespace($$) {
81 2     2 1 37 my ($namespace, $code) = @_;
82              
83 2         22 my $engine = _engine(caller(0));
84 2         5 push @{ $engine->namespaces }, $namespace;
  2         6  
85 2         4 $code->();
86 2         2 pop @{ $engine->namespaces };
  2         6  
87             }
88              
89             sub build {
90 40     40 1 87178 _engine(caller(0))->build(@_);
91             }
92              
93             *sh = *IPC::System::Simple::run;
94              
95              
96             1;
97             __END__