blib/lib/Dallycot/Value/ClosedRange.pm

filter: Statementstmt 69.1% 47 / 68 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 15 / 25 Podpod 0.0% 0 / 9 totaltotal 62.0% 67 / 108 CC 4 SCAR 5.0
CC
4
Cov
70%
__ANON__
3.0
_walk_tail
2.0
as_text
2.0
CRAP 1.6
« blib/lib/Dallycot/TextResolver.pm ↑ Summary blib/lib/Dallycot/Value/EmptyStream.pm »
1 package Dallycot::Value::ClosedRange;
2 30 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: A finite range of integers
5  
6 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # No RDF equivalent - finite list of items
10  
11 30 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use parent 'Dallycot::Value::Collection';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 30 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 30 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 30 Readonly my $FIRST => 0;
19 30 Readonly my $LAST => 1;
20 30 Readonly my $DIRECTION => 2;
21  
22 sub as_text {
23 0 ▶ my ($self) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod undocumented
24  
25 0 return $self->[$FIRST]->as_text . ".." . $self->[$LAST]->as_text;
26 }
27  
28 sub calculate_length {
29 0 ▶ my ( $self, $engine ) = @_;
Subroutine calculate_length: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 my $diff = $self->[$LAST]->value - $self->[$FIRST]->value;
32  
33 0 return Dallycot::Value::Numeric->new( $diff->babs + 1 );
34 }
35  
36 38 ▶sub is_defined { return 1 }
Subroutine is_defined: called CC=1 SCAR=0.0
Pod undocumented
37  
38 38 ▶sub is_empty {return}
Subroutine is_empty: called CC=1 SCAR=0.0
Pod undocumented
39  
40 sub calculate_reverse {
41 0 ▶ my ($self) = @_;
Subroutine calculate_reverse: not called CC=1 SCAR=6.9
Pod undocumented
42  
43 0 my $d = deferred;
44  
45 0 $d->resolve( bless [ $self->[$LAST], $self->[$FIRST], -$self->[$DIRECTION] ] => __PACKAGE__ );
46  
47 0 return $d->promise;
48 }
49  
50 0 ▶sub _type { return 'Range' }
Subroutine _type: not called CC=1 SCAR=6.9
51  
52 sub head {
53 35 ▶ my ($self) = @_;
Subroutine head: called CC=1 SCAR=0.0
Pod undocumented
54  
55 35 my $d = deferred;
56  
57 35 $d->resolve( $self->[$FIRST] );
58  
59 35 return $d->promise;
60 }
61  
62 sub tail {
63 34 ▶ my ( $self, $engine ) = @_;
Subroutine tail: called CC=1 SCAR=0.0
Pod undocumented
64  
65 return $self->[$FIRST]->is_equal( $engine, $self->[$LAST] )->then(
66 sub {
67 34 ▶ my ($f) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.1
68  
69 34 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 4 30 34
70 4 return Dallycot::Value::EmptyStream->new();
71 }
72 else {
73 30 my $next_p;
74 30 ▶ if ( $self->[$DIRECTION] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[$DIRECTION] > 0) { } 30 0 30
75 30 $next_p = $self->[$FIRST]->successor;
76 }
77 else {
78 0 $next_p = $self->[$FIRST]->predecessor;
79 }
80 $next_p->then(
81 sub {
82 30 ▶ my ($next) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
83 30 return bless [ $next, $self->[$LAST], $self->[$DIRECTION] ] => __PACKAGE__;
84 }
85 30 );
86 }
87 }
88 34 );
89 }
90  
91 sub _walk_tail {
92 2 ▶ my ( $self, $engine, $d, $count ) = @_;
Subroutine _walk_tail: called CC=2 SCAR=7.1
93  
94 2 ▶ if ( $count > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) { } 1 1 2
95 $self->tail($engine)->done(
96 sub {
97 1 ▶ my ($tail) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
98 1 $tail->_walk_tail( $engine, $d, $count - 1 );
99 },
100 sub {
101 0 ▶ $d->reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 }
103 1 );
104 }
105 else {
106 $self->head($engine)->done(
107 sub {
108 1 ▶ $d -> resolve(@_);
Subroutine __ANON__: called CC=1 SCAR=0.0
109 },
110 sub {
111 0 ▶ $d -> reject(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 }
113 1 );
114 }
115 }
116  
117 sub apply_map {
118 0 ▶ my ( $self, $engine, $transform ) = @_;
Subroutine apply_map: not called CC=1 SCAR=6.9
Pod undocumented
119  
120 return $engine->make_map($transform)->then(
121 sub {
122 0 ▶ my ($map_t) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
123  
124 0 return $map_t->apply( $engine, {}, $self );
125 }
126 0 );
127 }
128  
129 sub apply_filter {
130 0 ▶ my ( $self, $engine, $filter ) = @_;
Subroutine apply_filter: not called CC=1 SCAR=6.9
Pod undocumented
131  
132 return $engine->make_filter($filter)->then(
133 sub {
134 0 ▶ my ($filter_t) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
135  
136 0 return $filter_t->apply( $engine, {}, $self );
137 }
138 0 );
139 }
140  
141 30 1;
« blib/lib/Dallycot/TextResolver.pm ↑ Summary blib/lib/Dallycot/Value/EmptyStream.pm »