File Coverage

blib/lib/Data/Object/Role/Code.pm
Criterion Covered Total %
statement 30 30 100.0
branch 7 10 70.0
condition n/a
subroutine 15 15 100.0
pod 0 7 0.0
total 52 62 83.8


line stmt bran cond sub pod time code
1             # ABSTRACT: A Code Object Role for Perl 5
2             package Data::Object::Role::Code;
3              
4 19     19   104218 use 5.010;
  19         63  
  19         937  
5 19     19   4517 use Data::Object::Role;
  19         40  
  19         183  
6              
7 19     19   5797 use Data::Object 'codify';
  19         32  
  19         7744  
8              
9             map with($_), our @ROLES = qw(
10             Data::Object::Role::Defined
11             Data::Object::Role::Detract
12             Data::Object::Role::Output
13             Data::Object::Role::Ref
14             Data::Object::Role::Type
15             );
16              
17             our $VERSION = '0.20'; # VERSION
18              
19             sub call {
20 27     27 0 50 my ($code, @arguments) = @_;
21 27         103 return $code->(@arguments);
22             }
23              
24             sub curry {
25 2     2 0 6 my ($code, @arguments) = @_;
26 2     2   10 return sub { $code->(@arguments, @_) };
  2         9  
27             }
28              
29             sub rcurry {
30 1     1 0 3 my ($code, @arguments) = @_;
31 1     1   8 return sub { $code->(@_, @arguments) };
  1         7  
32             }
33              
34             sub compose {
35 1     1 0 3 my ($code, $next, @arguments) = @_;
36 1 50       3 $next = codify $next if !ref $next;
37 1     1   7 return curry(sub { $next->($code->(@_)) }, @arguments);
  1         4  
38             }
39              
40             sub disjoin {
41 1     1 0 1 my ($code, $next) = @_;
42 1 50       3 $next = codify $next if !ref $next;
43 1 100   5   9 return sub { $code->(@_) || $next->(@_) };
  5         9  
44             }
45              
46             sub conjoin {
47 1     1 0 4 my ($code, $next) = @_;
48 1 50       9 $next = codify $next if !ref $next;
49 1 100   10   10 return sub { $code->(@_) && $next->(@_) };
  10         3808  
50             }
51              
52             sub next {
53 10     10 0 26 goto &call;
54             }
55              
56             1;
57              
58             __END__