| 1 | package Dallycot::AST::Lambda; | ||||||||||||||||||||
| 2 | 29 | our $AUTHORITY = 'cpan:JSMITH'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | # ABSTRACT: Create a lambda value with a closure 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 | 29 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 29 | Readonly my $EXPRESSION => 0; | |||||||||||||||||||
| 17 | 29 | Readonly my $BINDINGS => 1; | |||||||||||||||||||
| 18 | 29 | Readonly my $BINDINGS_WITH_DEFAULTS => 2; | |||||||||||||||||||
| 19 | 29 | Readonly my $OPTIONS => 3; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||
| 22 | 1 | ▶ | my ( $self, $expr, $bindings, $bindings_with_defaults, $options ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 25 | 1 | ▶ | $bindings ||= []; | ||||||||||||||||||
|
Condition50%1/2
$bindings ||= []
MC/DC0%0/1
$bindings ||= []
$bindings
Truth table50%1/2
A
A= $bindings
| |||||||||||||||||||||
| 26 | 1 | ▶ | $bindings_with_defaults ||= []; | ||||||||||||||||||
|
Condition50%1/2
$bindings_with_defaults ||= []
MC/DC0%0/1
$bindings_with_defaults ||= []
$bindings_with_defaults
Truth table50%1/2
A
A= $bindings_with_defaults
| |||||||||||||||||||||
| 27 | 1 | ▶ | $options ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | return bless [ $expr, $bindings, $bindings_with_defaults, $options ] => $class; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub to_rdf { | ||||||||||||||||||||
| 33 | 2 | ▶ | my($self, $model) = @_; | ||||||||||||||||||
|
Subroutine
to_rdf: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 2 | my $bnode = $model -> bnode; | |||||||||||||||||||
| 36 | 2 | $model -> add_type($bnode, 'loc:Algorithm'); | |||||||||||||||||||
| 37 | 2 | $model -> add_expression($bnode, $self -> [$EXPRESSION]); | |||||||||||||||||||
| 38 | $model -> add_list( | ||||||||||||||||||||
| 39 | $bnode, 'loc:bindings', | ||||||||||||||||||||
| 40 | 3 | (map { $self -> _binding_rdf($model, $_) } @{$self->[$BINDINGS]}), | |||||||||||||||||||
| 41 | 2 | (map { $self -> _binding_rdf($model, @$_) } @{$self->[$BINDINGS_WITH_DEFAULTS]}) | |||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | 2 | foreach my $opt(keys %{$self->[$OPTIONS]}) { | |||||||||||||||||||
| 44 | $model -> add_option( | ||||||||||||||||||||
| 45 | $bnode, | ||||||||||||||||||||
| 46 | $opt, | ||||||||||||||||||||
| 47 | 0 | $self->[$OPTIONS]->{$opt}->to_rdf($model) | |||||||||||||||||||
| 48 | ); | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 2 | return $bnode; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | sub _binding_rdf { | ||||||||||||||||||||
| 54 | 3 | ▶ | my($self, $model, $label, $expr) = @_; | ||||||||||||||||||
|
Subroutine
_binding_rdf: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 3 | my $bnode = $model -> bnode; | |||||||||||||||||||
| 57 | 3 | $model -> add_type($bnode, 'loc:Binding'); | |||||||||||||||||||
| 58 | 3 | $model -> add_label($bnode, $label); | |||||||||||||||||||
| 59 | 3 | ▶ | if(defined $expr) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | $model -> add_expression($bnode, $expr); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 3 | return $bnode; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub child_nodes { | ||||||||||||||||||||
| 66 | 81 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
child_nodes: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||
| 67 | return $self->[$EXPRESSION], | ||||||||||||||||||||
| 68 | 0 | ▶ | ( map { $_->[1] } @{ $self->[$BINDINGS_WITH_DEFAULTS] || [] } ), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 81 | ▶ | ( values %{ $self->[$OPTIONS] || {} } ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub execute { | ||||||||||||||||||||
| 73 | 364 | ▶ | my ( $self, $engine ) = @_; | ||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 364 | my $d = deferred; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 364 | $d->resolve( $engine->make_lambda(@$self) ); | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 364 | return $d->promise; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 29 | 1; | |||||||||||||||||||