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