File Coverage

blib/lib/Dallycot/AST/BuildList.pm
Criterion Covered Total %
statement 18 45 40.0
branch 0 2 0.0
condition n/a
subroutine 6 12 50.0
pod 0 2 0.0
total 24 61 39.3


line stmt bran cond sub pod time code
1             package Dallycot::AST::BuildList;
2             our $AUTHORITY = 'cpan:JSMITH';
3              
4             # ABSTRACT: Create stream-like collection with possible generator
5              
6 23     23   12184 use strict;
  23         45  
  23         1186  
7 23     23   98 use warnings;
  23         38  
  23         470  
8              
9 23     23   80 use utf8;
  23         35  
  23         99  
10 23     23   440 use parent 'Dallycot::AST';
  23         33  
  23         104  
11              
12 23     23   1485 use experimental qw(switch);
  23         37  
  23         151  
13              
14 23     23   2662 use Promises qw(deferred);
  23         49  
  23         139  
15              
16             sub to_rdf {
17 0     0 0   my($self, $model) = @_;
18              
19 0           return $model -> apply(
20             $model -> meta_uri('loc:build-list'),
21             [ @$self ],
22             {}
23             );
24             # my $bnode = $model -> bnode;
25             # $model -> add_type($bnode, 'loc:List');
26             # if(@$self) {
27             # $model -> add_list($bnode, 'loc:expressions',
28             # map { $_ -> to_rdf($model) } @$self
29             # );
30             # }
31              
32             # return $bnode;
33             }
34              
35             sub execute {
36 0     0 0   my ( $self, $engine ) = @_;
37              
38 0           my $d = deferred;
39              
40 0           my @expressions = @$self;
41 0           given ( scalar(@expressions) ) {
42 0           when (0) {
43 0           $d->resolve( Dallycot::Value::EmptyStream->new );
44             }
45 0           when (1) {
46             $engine->execute( $self->[0] )->done(
47             sub {
48 0     0     my ($result) = @_;
49 0           $d->resolve( Dallycot::Value::Stream->new($result) );
50             },
51             sub {
52 0     0     $d->reject(@_);
53             }
54 0           );
55             }
56 0           default {
57 0           my $last_expr = pop @expressions;
58 0           my $promise;
59 0 0         if ( $last_expr->isa('Dallycot::Value') ) {
60 0           push @expressions, $last_expr;
61             }
62             else {
63 0           $promise = $engine->make_lambda($last_expr);
64             }
65             $engine->collect(@expressions)->done(
66             sub {
67 0     0     my (@items) = @_;
68 0           my $result = Dallycot::Value::Stream->new( ( pop @items ), undef, $promise );
69 0           while (@items) {
70 0           $result = Dallycot::Value::Stream->new( ( pop @items ), $result );
71             }
72 0           $d->resolve($result);
73             },
74             sub {
75 0     0     $d->reject(@_);
76             }
77 0           );
78             }
79             }
80              
81 0           return $d->promise;
82             }
83              
84             1;