blib/lib/Test/BDD/Cucumber/Model/TagSpec.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 90.4% 57 / 63 CC 9 SCAR 11.1
CC
9
Cov
90%
_matches
6.1
filter
2.0
__ANON__
2.0
CRAP 3.0
« lib/Test/BDD/Cucumber/Harness/TermColor.pm ↑ Summary examples/calculator/lib/Calculator.pm »
1 28 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Test::BDD::Cucumber::Model::TagSpec 0.87;
5  
6 =head1 NAME
7  
8 Test::BDD::Cucumber::Model::TagSpec - Encapsulates tag selectors
9  
10 =head1 VERSION
11  
12 version 0.87
13  
14 =head1 STATUS
15  
16 DEPRECATED - This module's functionality has been superseded by
17 L<Cucumber::TagExpressions>. A module published by the Cucumber
18 project, with cross-implementation tests to achieve overall consistency.
19  
20 =head1 DESCRIPTION
21  
22 Try and deal with the crazy-sauce tagging mechanism in a sane
23 way.
24  
25 =cut
26  
27 28 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 ▶use List::Util qw( all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 28 ▶use Types::Standard qw( ArrayRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 =head1 OVERVIEW
32  
33 Cucumber tags are all sortsa crazy. This appears to be a direct result of trying
34 to shoe-horn the syntax in to something you can use on the command line. Because
35 'Cucumber' is the name of a gem, application, language, methodology etc etc etc
36 look of disapproval.
37  
38 Here is some further reading on how it's meant to work:
39 L<https://github.com/cucumber/cucumber/wiki/Tags>. This is obviously a little
40 insane.
41  
42 Here's how they work here, on a code level: You pass in a list of lists that
43 look like Lisp expressions, with a function: C<and>, C<or>, or C<not>. You can
44 nest these to infinite complexity, but the parser is pretty inefficient, so
45 don't do that. The C<not> function accepts only one argument.
46  
47 I<eg>:
48  
49 @important AND @billing: C<<[and => 'important', 'billing']>>
50  
51 (@billing OR @WIP) AND @important: C<<[ and => [ or => 'billing', 'wip' ], 'important' ]>>
52  
53 Skipping both @todo and @wip tags: C<<[ and => [ not => 'todo' ], [ not => 'wip' ] ]>>
54  
55 =head1 ATTRIBUTES
56  
57 =head2 tags
58  
59 An arrayref representing a structure like the above.
60  
61 TagSet->new({
62 tags => [ and => 'green', 'blue', [ or => 'red', 'yellow' ], [ not => 'white' ] ]
63 })
64  
65 =cut
66  
67 0 ▶has 'tags' => ( is => 'rw', isa => ArrayRef, default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
68  
69 =head1 METHODS
70  
71 =head2 filter
72  
73 Filter a list of Scenarios by the value of C<tags>
74  
75 my @matched = $tagset->filter( @scenarios );
76  
77 If C<tags> is empty, no filtering is done.
78  
79 =cut
80  
81 13 ▶sub filter {
Subroutine filter: called CC=2 SCAR=6.9
Pod documented
82 13 my ( $self, @scenarios ) = @_;
83 13 ▶ return @scenarios unless @{ $self->tags };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->tags;} 0 13 13
84  
85 return grep {
86 13 my @tags = @{ $_->tags };
87 60 my $scenario = { map { $_ => 1 } @tags };
88  
89 60 _matches( $scenario, $self->tags );
90 } @scenarios;
91 }
92  
93 112 ▶sub _matches {
Subroutine _matches: called CC=6 SCAR=18.0
94 112 my ( $scenario, $tagspec ) = @_;
95 112 my ( $mode, @tags ) = @$tagspec;
96  
97 112 ▶ if ( $mode eq 'and' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq 'and') { } 59 53 112
elsif ($mode eq 'or') { } 27 26 53
elsif ($mode eq 'not') { } 26 0 26
98 81 ▶ return all {
Subroutine __ANON__: called CC=2 SCAR=6.9
99 81 ▶ ref $_ ? _matches( $scenario, $_ ) : $scenario->{$_}
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 37 44 81
100 59 } @tags;
101 }
102 elsif ( $mode eq 'or' ) {
103 46 ▶ return any {
Subroutine __ANON__: called CC=2 SCAR=6.9
104 46 ▶ ref $_ ? _matches( $scenario, $_ ) : $scenario->{$_}
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 5 41 46
105 27 } @tags;
106 }
107 elsif ( $mode eq 'not' ) {
108 26 ▶ die "'not' expects exactly one tag argument; found @tags"
Branch: 1 branch
BranchTrueFalseTotal
unless @tags == 1 0 26 26
109 unless @tags == 1;
110  
111 return
112 not (ref $tags[0]
113 ? _matches( $scenario, $tags[0] )
114 26 ▶ : $scenario->{$tags[0]}
Branch: 1 branch
BranchTrueFalseTotal
ref $tags[0] ? : 10 16 26
115 );
116 }
117 else {
118 0 die "Unexpected tagspec operator '$mode'";
119 }
120 }
121  
122 28 1;
« lib/Test/BDD/Cucumber/Harness/TermColor.pm ↑ Summary examples/calculator/lib/Calculator.pm »