File Coverage

blib/lib/Dallycot/AST/Condition.pm
Criterion Covered Total %
statement 12 45 26.6
branch 0 8 0.0
condition n/a
subroutine 4 12 33.3
pod 0 3 0.0
total 16 68 23.5


line stmt bran cond sub pod time code
1             package Dallycot::AST::Condition;
2             our $AUTHORITY = 'cpan:JSMITH';
3              
4             # ABSTRACT: Select an expression based on guards
5              
6 23     23   12776 use strict;
  23         40  
  23         885  
7 23     23   98 use warnings;
  23         32  
  23         485  
8              
9 23     23   86 use utf8;
  23         28  
  23         96  
10 23     23   419 use parent 'Dallycot::AST::LoopBase';
  23         32  
  23         102  
11              
12             sub to_rdf {
13 0     0 0   my($self, $model) = @_;
14              
15 0           my $bnode = $model -> bnode;
16 0           $model -> add_type($bnode, 'loc:GuardedSequence');
17 0           $model -> add_list($bnode, 'loc:expressions',
18             map {
19 0           $self->_case_to_rdf($model, $_)
20             } @$self
21             );
22              
23 0           return $bnode;
24             }
25              
26             sub _case_to_rdf {
27 0     0     my($self, $model, $cond) = @_;
28              
29 0           my $expr = $cond->[1]->to_rdf($model);
30 0 0         if(defined $cond->[0]) {
31 0           $expr = $model -> add_connection(
32             $expr,
33             'loc:guard',
34             $cond->[0]->to_rdf($model)
35             );
36             }
37 0           return $expr;
38             }
39              
40             sub child_nodes {
41 0     0 0   my ($self) = @_;
42              
43 0           return grep {defined} map { @{$_} } @{$self};
  0            
  0            
  0            
  0            
44             }
45              
46             sub process_loop {
47 0     0 0   my ( $self, $engine, $d, $condition, @expressions ) = @_;
48              
49 0 0         if ($condition) {
50 0 0         if ( defined $condition->[0] ) {
51             $engine->execute( $condition->[0], ['Boolean'] )->done(
52             sub {
53 0     0     my ($flag) = @_;
54 0 0         if ( $flag->value ) {
55             $engine->execute( $condition->[1] )->done(
56             sub {
57 0           $d->resolve(@_);
58             },
59             sub {
60 0           $d->reject(@_);
61             }
62 0           );
63             }
64             else {
65 0           $self->process_loop( $engine, $d, @expressions );
66             }
67             },
68             sub {
69 0     0     $d->reject(@_);
70             }
71 0           );
72             }
73             else {
74             $engine->execute( $condition->[1] )->done(
75             sub {
76 0     0     $d->resolve(@_);
77             },
78             sub {
79 0     0     $d->reject(@_);
80             }
81 0           );
82             }
83             }
84             else {
85 0           $d->resolve( $engine->UNDEFINED );
86             }
87              
88 0           return;
89             }
90              
91             1;