File Coverage

blib/lib/Dallycot/AST/Compose.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 4 0.0
condition n/a
subroutine 5 9 55.5
pod 0 2 0.0
total 20 44 45.4


line stmt bran cond sub pod time code
1             package Dallycot::AST::Compose;
2             our $AUTHORITY = 'cpan:JSMITH';
3              
4             # ABSTRACT: Compose lambdas into a new lambda
5              
6 23     23   12786 use strict;
  23         34  
  23         696  
7 23     23   83 use warnings;
  23         27  
  23         465  
8              
9 23     23   93 use utf8;
  23         163  
  23         101  
10 23     23   501 use parent 'Dallycot::AST';
  23         32  
  23         95  
11              
12 23     23   1092 use Promises qw(deferred);
  23         32  
  23         114  
13              
14             sub to_rdf {
15 0     0 0   my($self, $model) = @_;
16              
17 0           return $model -> apply(
18             $model -> meta_uri('loc:compose'),
19             [ @$self ],
20             {}
21             );
22             # my $bnode = $model -> bnode;
23             # $model -> add_type($bnode, 'loc:Composition');
24             # $model -> add_list($bnode, 'loc:expressions',
25             # map { $_ -> to_rdf($model) } @{$self}
26             # );
27             #
28             # return $bnode;
29             }
30              
31             sub execute {
32 0     0 0   my ( $self, $engine ) = @_;
33              
34 0           my $d = deferred;
35              
36             $engine->collect(@$self)->done(
37             sub {
38 0     0     my (@functions) = @_;
39 0 0         if ( grep { !$_->isa('Dallycot::Value::Lambda') } @functions ) {
  0 0          
  0            
40 0           $d->reject("All terms in a function composition must be lambdas");
41             }
42             elsif ( grep { 1 != $_->min_arity } @functions ) {
43 0           $d->reject("All lambdas in a function composition must have arity 1");
44             }
45             else {
46 0           $d->resolve( $engine->compose_lambdas(@functions) );
47             }
48             },
49             sub {
50 0     0     $d->reject(@_);
51             }
52 0           );
53              
54 0           return $d->promise;
55             }
56              
57             1;