line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::AST::Lambda; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Create a lambda value with a closure environment |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
12392
|
use strict; |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
698
|
|
7
|
23
|
|
|
23
|
|
94
|
use warnings; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
458
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
77
|
use utf8; |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
95
|
|
10
|
23
|
|
|
23
|
|
524
|
use parent 'Dallycot::AST'; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
124
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1200
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
37
|
|
|
23
|
|
|
|
|
116
|
|
13
|
|
|
|
|
|
|
|
14
|
23
|
|
|
23
|
|
4103
|
use Readonly; |
|
23
|
|
|
|
|
37
|
|
|
23
|
|
|
|
|
10518
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly my $EXPRESSION => 0; |
17
|
|
|
|
|
|
|
Readonly my $BINDINGS => 1; |
18
|
|
|
|
|
|
|
Readonly my $BINDINGS_WITH_DEFAULTS => 2; |
19
|
|
|
|
|
|
|
Readonly my $OPTIONS => 3; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
0
|
|
my ( $self, $expr, $bindings, $bindings_with_defaults, $options ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
0
|
|
|
|
my $class = ref $self || $self; |
25
|
0
|
|
0
|
|
|
|
$bindings ||= []; |
26
|
0
|
|
0
|
|
|
|
$bindings_with_defaults ||= []; |
27
|
0
|
|
0
|
|
|
|
$options ||= {}; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return bless [ $expr, $bindings, $bindings_with_defaults, $options ] => $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub to_rdf { |
33
|
0
|
|
|
0
|
0
|
|
my($self, $model) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $bnode = $model -> bnode; |
36
|
0
|
|
|
|
|
|
$model -> add_type($bnode, 'loc:Algorithm'); |
37
|
0
|
|
|
|
|
|
$model -> add_expression($bnode, $self -> [$EXPRESSION]); |
38
|
0
|
|
|
|
|
|
$model -> add_list( |
39
|
|
|
|
|
|
|
$bnode, 'loc:bindings', |
40
|
0
|
|
|
|
|
|
(map { $self -> _binding_rdf($model, $_) } @{$self->[$BINDINGS]}), |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
(map { $self -> _binding_rdf($model, @$_) } @{$self->[$BINDINGS_WITH_DEFAULTS]}) |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
); |
43
|
0
|
|
|
|
|
|
foreach my $opt(keys %{$self->[$OPTIONS]}) { |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$model -> add_option( |
45
|
|
|
|
|
|
|
$bnode, |
46
|
|
|
|
|
|
|
$opt, |
47
|
|
|
|
|
|
|
$self->[$OPTIONS]->{$opt}->to_rdf($model) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return $bnode; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _binding_rdf { |
54
|
0
|
|
|
0
|
|
|
my($self, $model, $label, $expr) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $bnode = $model -> bnode; |
57
|
0
|
|
|
|
|
|
$model -> add_type($bnode, 'loc:Binding'); |
58
|
0
|
|
|
|
|
|
$model -> add_label($bnode, $label); |
59
|
0
|
0
|
|
|
|
|
if(defined $expr) { |
60
|
0
|
|
|
|
|
|
$model -> add_expression($bnode, $expr); |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
return $bnode; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub child_nodes { |
66
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
67
|
0
|
|
|
|
|
|
return $self->[$EXPRESSION], |
68
|
0
|
0
|
|
|
|
|
( map { $_->[1] } @{ $self->[$BINDINGS_WITH_DEFAULTS] || [] } ), |
|
0
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
( values %{ $self->[$OPTIONS] || {} } ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub execute { |
73
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $d = deferred; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$d->resolve( $engine->make_lambda(@$self) ); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $d->promise; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |