line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::AST::BuildMap; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Create derivative stream through a mapping |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
12279
|
use strict; |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
712
|
|
7
|
23
|
|
|
23
|
|
95
|
use warnings; |
|
23
|
|
|
|
|
33
|
|
|
23
|
|
|
|
|
472
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
81
|
use utf8; |
|
23
|
|
|
|
|
26
|
|
|
23
|
|
|
|
|
102
|
|
10
|
23
|
|
|
23
|
|
431
|
use parent 'Dallycot::AST'; |
|
23
|
|
|
|
|
42
|
|
|
23
|
|
|
|
|
124
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1191
|
use Carp qw(croak); |
|
23
|
|
|
|
|
35
|
|
|
23
|
|
|
|
|
1042
|
|
13
|
23
|
|
|
23
|
|
109
|
use Dallycot::Util qw(maybe_promise); |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
896
|
|
14
|
23
|
|
|
23
|
|
159
|
use List::Util qw(all any); |
|
23
|
|
|
|
|
40
|
|
|
23
|
|
|
|
|
1331
|
|
15
|
23
|
|
|
23
|
|
102
|
use Promises qw(deferred collect); |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
112
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub to_rdf { |
18
|
0
|
|
|
0
|
0
|
|
my($self, $model) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $model -> apply( |
21
|
|
|
|
|
|
|
$model -> meta_uri('loc:build-map'), |
22
|
|
|
|
|
|
|
[ @$self ], |
23
|
|
|
|
|
|
|
{} |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub execute { |
28
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return $engine->collect(@$self)->then( |
31
|
|
|
|
|
|
|
sub { |
32
|
0
|
|
|
0
|
|
|
my (@functions) = @_; |
33
|
0
|
|
|
|
|
|
my $stream = pop @functions; |
34
|
0
|
|
|
|
|
|
return collect( map { maybe_promise( $_->is_lambda ) } @functions )->then( |
35
|
|
|
|
|
|
|
sub { |
36
|
0
|
|
|
|
|
|
my @flags = map {@$_} @_; |
|
0
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if ( any { !$_ } @flags ) { |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
croak "All but the last term in a mapping must be lambdas."; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
return ( \@functions, $stream ); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
)->then( |
45
|
|
|
|
|
|
|
sub { |
46
|
0
|
|
|
0
|
|
|
my ( $functions, $stream ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return collect( map { maybe_promise( $_->min_arity ) } @$functions )->then( |
49
|
|
|
|
|
|
|
sub { |
50
|
0
|
|
|
|
|
|
my (@arities) = map {@$_} @_; |
|
0
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( any { 1 != $_ } @arities ) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
croak "All lambdas in a mapping must have arity 1."; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
return ( $functions, $stream ); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
)->then( |
59
|
|
|
|
|
|
|
sub { |
60
|
0
|
|
|
0
|
|
|
my ( $functions, $stream ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return maybe_promise( $stream->is_lambda )->then( |
63
|
|
|
|
|
|
|
sub { |
64
|
0
|
|
|
|
|
|
my ($flag) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ($flag) { |
67
|
0
|
|
|
|
|
|
return $engine->make_map( $engine->compose_lambdas( @$functions, $stream ) ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
0
|
|
|
|
|
|
my $transform = $engine->compose_lambdas(@$functions); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $stream->apply_map( $engine, $transform ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |