line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::AST::BuildFilter; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Create lambda or filtered stream |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
12369
|
use strict; |
|
23
|
|
|
|
|
41
|
|
|
23
|
|
|
|
|
714
|
|
7
|
23
|
|
|
23
|
|
93
|
use warnings; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
534
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
125
|
use utf8; |
|
23
|
|
|
|
|
29
|
|
|
23
|
|
|
|
|
98
|
|
10
|
23
|
|
|
23
|
|
443
|
use parent 'Dallycot::AST'; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
103
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1058
|
use Carp qw(croak); |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
1144
|
|
13
|
23
|
|
|
23
|
|
117
|
use Dallycot::Util qw(maybe_promise); |
|
23
|
|
|
|
|
36
|
|
|
23
|
|
|
|
|
955
|
|
14
|
|
|
|
|
|
|
|
15
|
23
|
|
|
23
|
|
112
|
use List::Util qw(all any); |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
1277
|
|
16
|
23
|
|
|
23
|
|
119
|
use Promises qw(deferred collect); |
|
23
|
|
|
|
|
52
|
|
|
23
|
|
|
|
|
145
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub to_rdf { |
19
|
0
|
|
|
0
|
0
|
|
my($self, $model) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
return $model -> apply( |
22
|
|
|
|
|
|
|
$model -> meta_uri('loc:build-filter'), |
23
|
|
|
|
|
|
|
[ @$self ], |
24
|
|
|
|
|
|
|
{} |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# my $bnode = $model -> bnode; |
28
|
|
|
|
|
|
|
# $model -> add_type($bnode, 'loc:Filter'); |
29
|
|
|
|
|
|
|
# $model -> add_list($bnode, 'loc:expressions', |
30
|
|
|
|
|
|
|
# map { $_ -> to_rdf($model) } @{$self} |
31
|
|
|
|
|
|
|
# ); |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# return $bnode; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub execute { |
37
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $d = deferred; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return $engine->collect(@$self)->then( |
42
|
|
|
|
|
|
|
sub { |
43
|
0
|
|
|
0
|
|
|
my (@functions) = @_; |
44
|
0
|
|
|
|
|
|
my $stream = pop @functions; |
45
|
0
|
|
|
|
|
|
return collect( map { maybe_promise( $_->is_lambda ) } @functions )->then( |
46
|
|
|
|
|
|
|
sub { |
47
|
0
|
|
|
|
|
|
my @flags = map {@$_} @_; |
|
0
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ( any { !$_ } @flags ) { |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
croak "All but the last term in a filter must be lambdas."; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
return ( \@functions, $stream ); |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
)->then( |
56
|
|
|
|
|
|
|
sub { |
57
|
0
|
|
|
0
|
|
|
my ( $functions, $stream ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return collect( map { maybe_promise( $_->min_arity ) } @$functions )->then( |
60
|
|
|
|
|
|
|
sub { |
61
|
0
|
|
|
|
|
|
my (@arities) = map {@$_} @_; |
|
0
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( any { 1 != $_ } @arities ) { |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
croak "All lambdas in a filter must have arity 1."; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
return ( $functions, $stream ); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
)->then( |
70
|
|
|
|
|
|
|
sub { |
71
|
0
|
|
|
0
|
|
|
my ( $functions, $stream ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return maybe_promise( $stream->is_lambda )->then( |
74
|
|
|
|
|
|
|
sub { |
75
|
0
|
|
|
|
|
|
my ($flag) = @_; |
76
|
0
|
0
|
|
|
|
|
if ($flag) { |
77
|
0
|
|
|
|
|
|
return $engine->make_filter( $engine->compose_filters( @$functions, $stream ) ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
0
|
|
|
|
|
|
return $stream->apply_filter( $engine, $engine->compose_filters(@$functions) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |