| 1 | package Dallycot::AST::Assign; | ||||||||||||||
| 2 | 29 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||
| 3 | |||||||||||||||
| 4 | # ABSTRACT: Store result of expression in environment | ||||||||||||||
| 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'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 29 | ▶ | use Promises qw(deferred); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | sub to_string { | ||||||||||||||
| 15 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | return $self->[0] . " := " . $self->[1]->to_string; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 104 | ▶ | sub is_declarative { return 1 } | ||||||||||||
|
Subroutine
is_declarative: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | sub identifier { | ||||||||||||||
| 23 | 56 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
identifier: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 56 | return $self->[0]; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | sub simplify { | ||||||||||||||
| 29 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
simplify: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | 0 | return bless [ $self -> [0], $self -> [1] -> simplify ] => __PACKAGE__; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | sub to_rdf { | ||||||||||||||
| 35 | 2 | ▶ | my($self, $model) = @_; | ||||||||||||
|
Subroutine
to_rdf: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | 2 | my $bnode = $self->[1]->to_rdf($model); | |||||||||||||
| 38 | |||||||||||||||
| 39 | 2 | $model -> add_symbol($self->[0], $bnode); | |||||||||||||
| 40 | |||||||||||||||
| 41 | 2 | return $bnode; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | sub execute { | ||||||||||||||
| 45 | 105 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||
|
Subroutine
execute: called CC=5 SCAR=19.8
Pod
undocumented
| |||||||||||||||
| 46 | |||||||||||||||
| 47 | 105 | my $d = deferred; | |||||||||||||
| 48 | |||||||||||||||
| 49 | 105 | my $registry = Dallycot::Registry->instance; | |||||||||||||
| 50 | |||||||||||||||
| 51 | 105 | ▶ | if ( $registry->has_assignment( '', $self->[0] ) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 52 | 0 | $d = $registry->get_assignment( '', $self->[0] ); | |||||||||||||
| 53 | 0 | ▶ | if ( $d->is_resolved ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 0 | $d = deferred; | |||||||||||||
| 55 | 0 | $d->reject('Core definitions may not be redefined.'); | |||||||||||||
| 56 | 0 | return $d->promise; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | elsif ( $engine->has_assignment( $self->[0] ) ) { | ||||||||||||||
| 60 | 92 | $d = $engine->get_assignment( $self->[0] ); | |||||||||||||
| 61 | 92 | ▶ | if ( $d->is_resolved ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 0 | $d = deferred; | |||||||||||||
| 63 | 0 | $d->reject( 'Unable to redefine ' . $self->[0] ); | |||||||||||||
| 64 | 0 | return $d->promise; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | else { | ||||||||||||||
| 68 | 13 | $d = $engine->add_assignment( $self->[0] ); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | $engine->execute( $self->[1] )->done( | ||||||||||||||
| 72 | sub { | ||||||||||||||
| 73 | 104 | ▶ | my ($result) = @_; | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||
| 74 | 104 | my $worked = eval { | |||||||||||||
| 75 | 104 | $engine->add_assignment( $self->[0], $result ); | |||||||||||||
| 76 | 104 | 1; | |||||||||||||
| 77 | }; | ||||||||||||||
| 78 | 104 | ▶ | if ($@) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 79 | 0 | $d->reject($@); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | elsif ( !$worked ) { | ||||||||||||||
| 82 | 0 | $d->reject( "Unable to assign to " . $self->[0] ); | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | else { | ||||||||||||||
| 85 | 104 | $d->resolve($result); | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | }, | ||||||||||||||
| 88 | sub { | ||||||||||||||
| 89 | 0 | ▶ | $d->reject(@_); | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 90 | } | ||||||||||||||
| 91 | 105 | ); | |||||||||||||
| 92 | |||||||||||||||
| 93 | 105 | return $d->promise; | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | 29 | 1; | |||||||||||||