| 1 | |||||||||||||||||||||||||||||
| 2 | package Cucumber::TagExpressions::Node; | ||||||||||||||||||||||||||||
| 3 | 2 | $Cucumber::TagExpressions::Node::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | Cucumber::TagExpressions::Node - Cucumber Tag expression components | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | use Cucumber::TagExpressions; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | my $expr = Cucumber::TagExpressions->parse( '@a and @b' ); | ||||||||||||||||||||||||||||
| 13 | if ( $expr->evaluate( qw/x y z/ ) ) { | ||||||||||||||||||||||||||||
| 14 | say "The evaluation returned false"; | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | This module defines the components making up the tag expressions. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 METHODS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head2 evaluate( @tags ) | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Returns C<true> when the tag set specified in C<$tags> satisfies the | ||||||||||||||||||||||||||||
| 31 | condition(s) of the expression, C<false> otherwise. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | C<@tags> can be a list of tags to be used in the expression. It can | ||||||||||||||||||||||||||||
| 34 | also be a reference to a hash with the keys being the tags and the | ||||||||||||||||||||||||||||
| 35 | values being considered boolean values indicating whether the tag (key) | ||||||||||||||||||||||||||||
| 36 | is considered part of the tagset (true) or not (false). | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | die 'Abstract superclass; override "evaluate" method'; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head2 stringify | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Returns a string representation of the expression node. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub stringify { } | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 NODE CLASSES | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | package Cucumber::TagExpressions::LiteralNode { | |||||||||||||||||||||||||||
| 58 | 2 | $Cucumber::TagExpressions::LiteralNode::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 59 | =head2 Cucumber::TagExpressions::LiteralNode | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head3 DESCRIPTION | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | This node class returns C<true> if the literal tag is specified as part of | ||||||||||||||||||||||||||||
| 64 | the tag-list in the expression evaluation. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head3 ATTRIBUTES | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head4 tag | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | The tag to test presence for. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 76 | 2 | extends 'Cucumber::TagExpressions::Node'; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | has tag => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 83 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 83 | my ( $self, $tags ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 83 | return $tags->{ $self->tag }; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | return ($self->tag =~ s/([ ()\\])/\\$1/gr); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | package Cucumber::TagExpressions::AndNode { | |||||||||||||||||||||||||||
| 94 | 2 | $Cucumber::TagExpressions::AndNode::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 95 | =head2 Cucumber::TagExpressions::AndNode | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head3 DESCRIPTION | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | This node class type evaluates one or more sub-expressions ("terms") and | ||||||||||||||||||||||||||||
| 100 | returns C<false> if any of the terms does. It returns C<true> if all of | ||||||||||||||||||||||||||||
| 101 | the terms return C<true>. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head3 ATTRIBUTES | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head4 terms | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | The sub-expressions to evaluate. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 112 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 113 | 2 | extends 'Cucumber::TagExpressions::Node'; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | use List::Util qw( all reduce ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | has terms => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 24 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 24 | my ( $self, $tags ) = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 24 | ▶ | return all { $_->evaluate( $tags ) } @{ $self->terms }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | return | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | reduce { '( ' . $a . ' and ' . $b . ' )' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 130 | 0 | map { $_->stringify } | |||||||||||||||||||||||||||
| 131 | 0 | @{ $self->terms }; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 2 | package Cucumber::TagExpressions::OrNode { | |||||||||||||||||||||||||||
| 136 | 2 | $Cucumber::TagExpressions::OrNode::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 137 | =head2 Cucumber::TagExpressions::OrNode | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head3 DESCRIPTION | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | This node class type evaluates one or more sub-expressions ("terms") and | ||||||||||||||||||||||||||||
| 142 | returns C<true> if any of the terms does. It returns C<false> if all of | ||||||||||||||||||||||||||||
| 143 | the terms return C<false>. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head3 ATTRIBUTES | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head4 terms | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | The sub-expressions to evaluate. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 155 | 2 | extends 'Cucumber::TagExpressions::Node'; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | ▶ | use List::Util qw( any reduce ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 2 | has terms => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 34 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 34 | my ( $self, $tags ) = @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 34 | ▶ | return any { $_->evaluate( $tags ) } @{ $self->terms }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | return | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | reduce { '( ' . $a . ' or ' . $b . ' )' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 172 | 0 | map { $_->stringify } | |||||||||||||||||||||||||||
| 173 | 0 | @{ $self->terms }; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 2 | package Cucumber::TagExpressions::NotNode { | |||||||||||||||||||||||||||
| 178 | 2 | $Cucumber::TagExpressions::NotNode::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 179 | =head2 Cucumber::TagExpressions::NotNode | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head3 DESCRIPTION | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | This class wraps one of the other node class types, negating its | ||||||||||||||||||||||||||||
| 184 | result on evaluation. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head3 ATTRIBUTES | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head4 expression | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | The wrapped node class instance for which to negate the result. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 196 | 2 | extends 'Cucumber::TagExpressions::Node'; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 2 | has expression => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 19 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | 19 | my ( $self, $tags ) = @_; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 19 | return not $self->expression->evaluate( $tags ); | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($self->expression->isa('Cucumber::TagExpressions::AndNode') || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->expression->isa("Cucumber::TagExpressions::AndNode") or $self->expression->isa("Cucumber::TagExpressions::OrNode")
MC/DC0%0/2
$self->expression->isa("Cucumber::TagExpressions::AndNode") or $self->expression->isa("Cucumber::TagExpressions::OrNode")
$self->expression->isa("Cucumber::TagExpressions::AndNode")
$self->expression->isa("Cucumber::TagExpressions::OrNode")
Truth table0%0/3
A or B
A= $self->expression->isa("Cucumber::TagExpressions::AndNode")B= $self->expression->isa("Cucumber::TagExpressions::OrNode")
| |||||||||||||||||||||||||||||
| 209 | $self->expression->isa('Cucumber::TagExpressions::OrNode')) { | ||||||||||||||||||||||||||||
| 210 | # -- HINT: Binary Operators already have already '( ... )'. | ||||||||||||||||||||||||||||
| 211 | 0 | return 'not ' . $self->expression->stringify; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 0 | return 'not ( ' . $self->expression->stringify . ' )'; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 2 | package Cucumber::TagExpressions::ExpressionNode { | |||||||||||||||||||||||||||
| 218 | 2 | $Cucumber::TagExpressions::ExpressionNode::VERSION = '11.2.0'; | |||||||||||||||||||||||||||
| 219 | =head2 Cucumber::TagExpressions::ExpressionNode | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head3 DESCRIPTION | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | This class models the outer-most node in the tag expression; it wraps all | ||||||||||||||||||||||||||||
| 224 | other nodes and is the entry-point for tag expression evaluation. | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head3 ATTRIBUTES | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =head4 sub_expression | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | An instance of one of the other node class types. | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 235 | # 'use Moo' implies 'use strict; use warnings;' | ||||||||||||||||||||||||||||
| 236 | 2 | extends 'Cucumber::TagExpressions::Node'; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 2 | has sub_expression => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 48 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | 48 | my ( $self, @tags ) = @_; | |||||||||||||||||||||||||||
| 242 | my $tags = (ref $tags[0] and ref $tags[0] eq 'HASH') ? $tags[0] | ||||||||||||||||||||||||||||
| 243 | 48 | ▶ | : { map { $_ => 1 } @tags }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $tags[0] and ref $tags[0] eq "HASH"
MC/DC0%0/2
ref $tags[0] and ref $tags[0] eq "HASH"
ref $tags[0]
ref $tags[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $tags[0]B= ref $tags[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 48 | ▶ | return 1==1 if not defined $self->sub_expression; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 48 | return not not $self->sub_expression->evaluate( $tags ); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | return '' if not defined $self->sub_expression; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | return $self->sub_expression->stringify; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 2 | 1; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | __END__ | ||||||||||||||||||||||||||||