blib/lib/Dallycot/AST.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 100% 4 / 4 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 10 totaltotal 76.1% 83 / 109 CC 7 SCAR 4.3
CC
7
Cov
89%
to_json
2.3
to_string
2.3
execute
2.1
CRAP 1.5
« blib/lib/Dallycot/Value/EmptyStream.pm ↑ Summary blib/lib/Dallycot/AST/ComparisonBase.pm »
1 package Dallycot::AST;
2 29 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Abstract type representing a syntax node
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 experimental qw(switch);
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 Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 use Module::Pluggable
17 29 require => 1,
18 sub_name => '_node_types',
19 29 ▶ search_path => 'Dallycot::AST';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 29 ▶use Dallycot::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 =head1 DESCRIPTION
24  
25 Dallycot::AST is an abstract class inherited by all of the AST classes:
26  
27 =over 4
28  
29 =item L<Apply|Dallycot::AST::Apply>
30  
31 =item L<Assign|Dallycot::AST::Assign>
32  
33 =item L<BuildFilter|Dallycot::AST::BuildFilter>
34  
35 =item L<BuildList|Dallycot::AST::BuildList>
36  
37 =item L<BuildMap|Dallycot::AST::BuildMap>
38  
39 =item L<BuildRange|Dallycot::AST::BuildRange>
40  
41 =item L<BuildVector|Dallycot::AST::BuildVector>
42  
43 =item L<Compose|Dallycot::AST::Compose>
44  
45 =item L<Defined|Dallycot::AST::Defined>
46  
47 =item L<Expr|Dallycot::AST::Expr>
48  
49 =item L<Fetch|Dallycot::AST::Fetch>
50  
51 =item L<ForwardWalk|Dallycot::AST::ForwardWalk>
52  
53 =item L<Head|Dallycot::AST::Head>
54  
55 =item L<Identity|Dallycot::AST::Identity>
56  
57 =item L<Index|Dallycot::AST::Index>
58  
59 =item L<Invert|Dallycot::AST::Invert>
60  
61 =item L<Lambda|Dallycot::AST::Lambda>
62  
63 =item L<LibraryFunction|Dallycot::AST::LibraryFunction>
64  
65 =item L<Modulus|Dallycot::AST::Modulus>
66  
67 =item L<Negation|Dallycot::AST::Negation>
68  
69 =item L<Placeholder|Dallycot::AST::Placeholder>
70  
71 =item L<Product|Dallycot::AST::Product>
72  
73 =item L<PropertyLit|Dallycot::AST::PropertyLit>
74  
75 =item L<Reciprocal|Dallycot::AST::Reciprocal>
76  
77 =item L<Reduce|Dallycot::AST::Reduce>
78  
79 =item L<Sequence|Dallycot::AST::Sequence>
80  
81 =item L<Sum|Dallycot::AST::Sum>
82  
83 =item L<Tail|Dallycot::AST::Tail>
84  
85 =item L<TypePromotion|Dallycot::AST::TypePromotion>
86  
87 =item L<Unique|Dallycot::AST::Unique>
88  
89 =item L<Zip|Dallycot::AST::Zip>
90  
91 =back
92  
93 Additional base classes inherit from this abstract class as well:
94  
95 =over 4
96  
97 =item L<ComparisonBase|Dallycot::AST::ComparisonBase>
98  
99 The base for the various comparison operations.
100  
101 =over 4
102  
103 =item L<Decreasing|Dallycot::AST::Decreasing>
104  
105 =item L<Equality|Dallycot::AST::Equality>
106  
107 =item L<Increasing|Dallycot::AST::Increasing>
108  
109 =item L<StrictlyDecreasing|Dallycot::AST::StrictlyDecreasing>
110  
111 =item L<StrictlyIncreasing|Dallycot::AST::StrictlyIncreasing>
112  
113 =back
114  
115 =item L<LoopBase|Dallycot::AST::LoopBase>
116  
117 The base for operations that loop through a series of options.
118  
119 =over 4
120  
121 =item L<All|Dallycot::AST::All>
122  
123 =item L<Any|Dallycot::AST::Any>
124  
125 =item L<Condition|Dallycot::AST::Condition>
126  
127 =item L<PropWalk|Dallycot::AST::PropWalk>
128  
129 =back
130  
131 =back
132  
133 =cut
134  
135 # use overload '""' => sub {
136 # shift->to_string
137 # };
138  
139 29 our @NODE_TYPES;
140  
141 =func node_types
142  
143 Returns a list of Perl packages that provide AST nodes.
144  
145 =cut
146  
147 82 ▶sub is_declarative {return}
Subroutine is_declarative: called CC=1 SCAR=0.0
Pod undocumented
148  
149 sub node_types {
150 30 ▶ return @NODE_TYPES if @NODE_TYPES;
Subroutine node_types: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @Dallycot::AST::NODE_TYPES 1 29 30
151 29 (@NODE_TYPES) = shift->_node_types;
152 29 return @NODE_TYPES;
153 }
154  
155 29 __PACKAGE__->node_types;
156  
157 sub new {
158 2 ▶ my ($class) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
159  
160 2 ▶ $class = ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
161  
162 2 return bless [] => $class;
163 }
164  
165 =method simplify
166  
167 Simplifies the node and any child nodes.
168  
169 =cut
170  
171 sub simplify {
172 1 ▶ my ($self) = @_;
Subroutine simplify: called CC=1 SCAR=0.0
Pod undocumented
173 1 return $self;
174 }
175  
176 =method check_for_common_mistakes
177  
178 Checks for any odd expressions given their context.
179  
180 Returns a list of warnings.
181  
182 =cut
183  
184 sub check_for_common_mistakes {
185 1 ▶ my ($self) = @_;
Subroutine check_for_common_mistakes: called CC=1 SCAR=0.4
Pod undocumented
186  
187 1 return map { $_->check_for_common_mistakes } $self->child_nodes;
188 }
189  
190 =method to_json
191  
192 Returns a Perl Hash containing the JSON-LD representation of the node and
193 any child nodes.
194  
195 =cut
196  
197 sub to_json {
198 1 ▶ my ($self) = @_;
Subroutine to_json: called CC=2 SCAR=8.1
Pod undocumented
199  
200 1 ▶ croak "to_json not defined for " . ( blessed($self) || $self );
Condition33%1/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
201 }
202  
203 =method to_string
204  
205 Returns a Perl string containing a pseudo-code representation of the node
206 and any child nodes. This string may not parse. It's intended for debugging
207 purposes.
208  
209 =cut
210  
211 sub to_string {
212 1 ▶ my ($self) = @_;
Subroutine to_string: called CC=2 SCAR=8.1
Pod undocumented
213  
214 1 ▶ croak "to_string not defined for " . ( blessed($self) || $self );
Condition33%1/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
215 }
216  
217 =method execute($engine)
218  
219 Executes the node using the provided engine. Returns a promise.
220  
221 =cut
222  
223 sub execute {
224 1 ▶ my ( $self, $engine ) = @_;
Subroutine execute: called CC=2 SCAR=7.4
Pod undocumented
225  
226 1 my $d = deferred;
227  
228 1 ▶ $d->reject( ( blessed($self) || $self ) . " is not a valid operation" );
Condition33%1/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
229  
230 1 return $d->promise;
231 }
232  
233 =method identifiers
234  
235 Returns a list of identifiers referenced in the current environment by this node.
236  
237 =cut
238  
239 2811 ▶sub identifiers { return () }
Subroutine identifiers: called CC=1 SCAR=0.0
Pod undocumented
240  
241 =method child_nodes
242  
243 Returns a list of child nodes.
244  
245 =cut
246  
247 sub child_nodes {
248 5067 ▶ my ($self) = @_;
Subroutine child_nodes: called CC=2 SCAR=6.9
Pod undocumented
249  
250 5067 ▶ return grep { blessed($_) && $_->isa(__PACKAGE__) } @{$self};
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->isa(__PACKAGE__) 2599 3333 5932
251 }
252  
253 29 1;
« blib/lib/Dallycot/Value/EmptyStream.pm ↑ Summary blib/lib/Dallycot/AST/ComparisonBase.pm »