blib/lib/Dallycot/AST/BuildFilter.pm

filter: Statementstmt 91.0% 51 / 56 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 0.0% 0 / 2 totaltotal 86.5% 71 / 82 CC 4 SCAR 3.1
CC
4
Cov
87%
__ANON__
2.1
__ANON__
2.1
__ANON__
2.1
CRAP 1.4
« blib/lib/Dallycot/AST/Product.pm ↑ Summary blib/lib/Dallycot/AST/BuildMap.pm »
1 package Dallycot::AST::BuildFilter;
2 29 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Create lambda or filtered stream
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 Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Dallycot::Util qw(maybe_promise);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 29 ▶use List::Util qw(all any);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 29 ▶use Promises qw(deferred collect);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 sub to_rdf {
19 0 ▶ my($self, $model) = @_;
Subroutine to_rdf: not called CC=1 SCAR=6.9
Pod undocumented
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 25 ▶ my ( $self, $engine ) = @_;
Subroutine execute: called CC=1 SCAR=0.1
Pod undocumented
38  
39 25 my $d = deferred;
40  
41 return $engine->collect(@$self)->then(
42 sub {
43 20 ▶ my (@functions) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
44 20 my $stream = pop @functions;
45 20 return collect( map { maybe_promise( $_->is_lambda ) } @functions )->then(
46 sub {
47 19 ▶ my @flags = map {@$_} @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
48 19 ▶ if ( any { !$_ } @flags ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { not $_; } , @flags)) 0 19 19
49 0 croak "All but the last term in a filter must be lambdas.";
50 }
51 19 return ( \@functions, $stream );
52 }
53 20 );
54 }
55 )->then(
56 sub {
57 19 ▶ my ( $functions, $stream ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.1
58  
59 19 return collect( map { maybe_promise( $_->min_arity ) } @$functions )->then(
60 sub {
61 19 ▶ my (@arities) = map {@$_} @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
62 19 ▶ if ( any { 1 != $_ } @arities ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { 1 != $_; } , @arities)) 0 19 19
63 0 croak "All lambdas in a filter must have arity 1.";
64 }
65 19 return ( $functions, $stream );
66 }
67 19 );
68 }
69 )->then(
70 sub {
71 19 ▶ my ( $functions, $stream ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.2
72  
73 return maybe_promise( $stream->is_lambda )->then(
74 sub {
75 19 ▶ my ($flag) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.6
76 19 ▶ if ($flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag) { } 0 19 19
77 0 return $engine->make_filter( $engine->compose_filters( @$functions, $stream ) );
78 }
79 else {
80 19 return $stream->apply_filter( $engine, $engine->compose_filters(@$functions) );
81 }
82 }
83 19 );
84 }
85 25 );
86 }
87  
88 29 1;
« blib/lib/Dallycot/AST/Product.pm ↑ Summary blib/lib/Dallycot/AST/BuildMap.pm »