blib/lib/Dallycot/AST/Index.pm

filter: Statementstmt 86.2% 44 / 51 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 78.5% 11 / 14 Podpod 0.0% 0 / 2 totaltotal 79.2% 61 / 77 CC 6 SCAR 6.2
CC
6
Cov
82%
_do_next_index
3.2
__ANON__
2.3
execute
2.1
CRAP 1.9
« blib/lib/Dallycot/Value/OpenRange.pm ↑ Summary blib/lib/Dallycot/AST/Compose.pm »
1 package Dallycot::AST::Index;
2 29 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Select value at given index in collection-like value
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 sub to_rdf {
15 1 ▶ my($self, $model) = @_;
Subroutine to_rdf: called CC=2 SCAR=7.1
Pod undocumented
16  
17 1 my @exprs = @$self;
18  
19 1 my $node = $model -> apply(
20 $model -> meta_uri('loc:index'),
21 [ $exprs[0], $exprs[1] ]
22 );
23  
24 1 shift @exprs; shift @exprs;
25  
26 1 ▶ while(@exprs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exprs) 0 1 1
27 0 $node = $model -> apply(
28 $model -> meta_uri('loc:index'),
29 [ $node, shift @exprs ]
30 );
31 }
32
33 1 return $node;
34 }
35  
36 sub execute {
37 103 ▶ my ( $self, $engine ) = @_;
Subroutine execute: called CC=2 SCAR=7.2
Pod undocumented
38  
39 103 my $d = deferred;
40  
41 103 my @expressions = @$self;
42  
43 103 ▶ if (@expressions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@expressions) { } 103 0 103
44 $engine->execute( shift @expressions )->done(
45 sub {
46 103 ▶ my ($root) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
47 103 $self->_do_next_index(
48 $engine, $d,
49 root => $root,
50 indices => \@expressions
51 );
52 },
53 sub {
54 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 }
56 103 );
57 }
58 else {
59 0 $d->reject('missing expressions');
60 }
61  
62 103 return $d->promise;
63 }
64  
65 sub _do_next_index {
66 206 ▶ my ( $self, $engine, $d, %state ) = @_;
Subroutine _do_next_index: called CC=3 SCAR=11.6
67 my ( $root, $index_expr, @indices )
68 206 ▶ = ( $state{root}, @{ $state{indices} || [] } );
Branch: 1 branch
BranchTrueFalseTotal
$state{"indices"} or [] 0 206 206
69  
70 206 ▶ if ($index_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index_expr) { } 103 103 206
71 $engine->execute($index_expr)->done(
72 sub {
73 103 ▶ my ($index) = @_;
Subroutine __ANON__: called CC=2 SCAR=8.1
74  
75 103 ▶ if ( $index->isa('Dallycot::Value::Numeric') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index->isa('Dallycot::Value::Numeric')) { } 103 0 103
76 103 $index = $index->value;
77 }
78 else {
79 0 $d->reject("Vector indices must be numeric");
80 0 return;
81 }
82 $root->value_at( $engine, $index )->done(
83 sub {
84 103 ▶ $self->_do_next_index(
Subroutine __ANON__: called CC=1 SCAR=0.0
85 $engine, $d,
86 root => $_[0],
87 indices => \@indices
88 );
89 },
90 sub {
91 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 }
93 103 );
94 },
95 sub {
96 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 }
98 103 );
99 }
100 else {
101 103 $d->resolve($root);
102 }
103  
104 206 return;
105 }
106  
107 29 1;
« blib/lib/Dallycot/Value/OpenRange.pm ↑ Summary blib/lib/Dallycot/AST/Compose.pm »