File Coverage

blib/lib/Syntax/Keyword/Junction/One.pm
Criterion Covered Total %
statement 125 125 100.0
branch 109 110 99.0
condition n/a
subroutine 19 19 100.0
pod 0 15 0.0
total 253 269 94.0


line stmt bran cond sub pod time code
1             package Syntax::Keyword::Junction::One;
2 12     12   218010 use strict;
  12         23  
  12         458  
3 12     12   59 use warnings;
  12         24  
  12         851  
4              
5             our $VERSION = '0.003009';
6              
7 12     12   68 use parent 'Syntax::Keyword::Junction::Base';
  12         25  
  12         72  
8              
9             BEGIN {
10 12     12   17151 if (Syntax::Keyword::Junction::Base::_WANT_SMARTMATCH) {
11             eval '#line '.(__LINE__+1).' "' . __FILE__.qq["\n] . <<'END_CODE' or die $@;
12             no if Syntax::Keyword::Junction::Base::_SMARTMATCH_WARNING_CATEGORY,
13             warnings => Syntax::Keyword::Junction::Base::_SMARTMATCH_WARNING_CATEGORY;
14              
15             sub match {
16             my ( $self, $other, $is_rhs ) = @_;
17              
18             my $count = 0;
19              
20             if ($is_rhs) {
21              
22             for (@$self) {
23             if ($other ~~ $_) {
24             return if $count;
25             $count = 1;
26             }
27             }
28              
29             return($count == 1);
30             }
31              
32             for (@$self) {
33             if ($_ ~~ $other) {
34             return if $count;
35             $count = 1;
36             }
37             }
38              
39             return($count == 1);
40             }
41              
42             1;
43             END_CODE
44             }
45             }
46              
47             sub num_eq {
48 17 100   17 0 131 return regex_eq(@_) if ref( $_[1] ) eq 'Regexp';
49              
50 12         31 my ( $self, $test ) = @_;
51 12         32 my $count = 0;
52              
53 12         32 for (@$self) {
54 27 100       85 if ( $_ == $test ) {
55 12 100       38 return if $count;
56 10         16 $count = 1;
57             }
58             }
59              
60 10 100       58 return 1 if $count;
61             }
62              
63             sub num_ne {
64 7 100   7 0 32 return regex_ne(@_) if ref( $_[1] ) eq 'Regexp';
65              
66 3         5 my ( $self, $test ) = @_;
67 3         5 my $count = 0;
68              
69 3         5 for (@$self) {
70 6 100       10 if ( $_ != $test ) {
71 3 100       9 return if $count;
72 2         2 $count = 1;
73             }
74             }
75              
76 2 100       8 return 1 if $count;
77             }
78              
79             sub num_ge {
80 17     17 0 36 my ( $self, $test, $switch ) = @_;
81              
82 17 100       44 return num_le( $self, $test ) if $switch;
83              
84 10         13 my $count = 0;
85              
86 10         46 for (@$self) {
87 29 100       44 if ( $_ >= $test ) {
88 11 100       30 return if $count;
89 8         9 $count = 1;
90             }
91             }
92              
93 7 100       36 return 1 if $count;
94             }
95              
96             sub num_gt {
97 12     12 0 22 my ( $self, $test, $switch ) = @_;
98              
99 12 100       22 return num_lt( $self, $test ) if $switch;
100              
101 8         11 my $count = 0;
102              
103 8         11 for (@$self) {
104 23 100       32 if ( $_ > $test ) {
105 8 100       19 return if $count;
106 6         9 $count = 1;
107             }
108             }
109              
110 6 100       20 return 1 if $count;
111             }
112              
113             sub num_le {
114 14     14 0 35 my ( $self, $test, $switch ) = @_;
115              
116 14 100       30 return num_ge( $self, $test ) if $switch;
117              
118 11         16 my $count = 0;
119              
120 11         19 for (@$self) {
121 23 100       40 if ( $_ <= $test ) {
122 11 100       25 return if $count;
123 9         12 $count = 1;
124             }
125             }
126              
127 9 100       49 return 1 if $count;
128             }
129              
130             sub num_lt {
131 12     12 0 18 my ( $self, $test, $switch ) = @_;
132              
133 12 100       25 return num_gt( $self, $test ) if $switch;
134              
135 8         8 my $count = 0;
136              
137 8         12 for (@$self) {
138 21 100       32 if ( $_ < $test ) {
139 8 100       15 return if $count;
140 6         7 $count = 1;
141             }
142             }
143              
144 6 100       22 return 1 if $count;
145             }
146              
147             sub str_eq {
148 3     3 0 7 my ( $self, $test ) = @_;
149 3         3 my $count = 0;
150              
151 3         5 for (@$self) {
152 6 100       12 if ( $_ eq $test ) {
153 3 100       6 return if $count;
154 2         4 $count = 1;
155             }
156             }
157              
158 2 100       7 return 1 if $count;
159             }
160              
161             sub str_ne {
162 4     4 0 10 my ( $self, $test ) = @_;
163 4         5 my $count = 0;
164              
165 4         9 for (@$self) {
166 9 100       22 if ( $_ ne $test ) {
167 4 100       11 return if $count;
168 3         5 $count = 1;
169             }
170             }
171              
172 3 100       14 return 1 if $count;
173             }
174              
175             sub str_ge {
176 11     11 0 30 my ( $self, $test, $switch ) = @_;
177              
178 11 100       67 return str_le( $self, $test ) if $switch;
179              
180 7         12 my $count = 0;
181              
182 7         20 for (@$self) {
183 13 100       34 if ( $_ ge $test ) {
184 7 100       25 return if $count;
185 5         13 $count = 1;
186             }
187             }
188              
189 5 100       34 return 1 if $count;
190             }
191              
192             sub str_gt {
193 11     11 0 35 my ( $self, $test, $switch ) = @_;
194              
195 11 100       38 return str_lt( $self, $test ) if $switch;
196              
197 7         14 my $count = 0;
198              
199 7         18 for (@$self) {
200 14 100       41 if ( $_ gt $test ) {
201 8 100       31 return if $count;
202 6         12 $count = 1;
203             }
204             }
205              
206 5 100       33 return 1 if $count;
207             }
208              
209             sub str_le {
210 10     10 0 26 my ( $self, $test, $switch ) = @_;
211              
212 10 100       35 return str_ge( $self, $test ) if $switch;
213              
214 7         13 my $count = 0;
215              
216 7         18 for (@$self) {
217 14 100       54 if ( $_ le $test ) {
218 5 100       18 return if $count;
219 4         7 $count = 1;
220             }
221             }
222              
223 6 100       45 return 1 if $count;
224             }
225              
226             sub str_lt {
227 12     12 0 40 my ( $self, $test, $switch ) = @_;
228              
229 12 100       52 return str_gt( $self, $test ) if $switch;
230              
231 8         17 my $count = 0;
232              
233 8         23 for (@$self) {
234 16 100       48 if ( $_ lt $test ) {
235 8 100       55 return if $count;
236 6         13 $count = 1;
237             }
238             }
239              
240 6 100       85 return 1 if $count;
241             }
242              
243             sub regex_eq {
244 5     5 0 12 my ( $self, $test, $switch ) = @_;
245              
246 5         11 my $count = 0;
247              
248 5         16 for (@$self) {
249 12 100       82 if ( $_ =~ $test ) {
250 8 100       36 return if $count;
251 5         9 $count = 1;
252             }
253             }
254              
255 2 50       15 return 1 if $count;
256             }
257              
258             sub regex_ne {
259 4     4 0 12 my ( $self, $test, $switch ) = @_;
260              
261 4         9 my $count = 0;
262              
263 4         9 for (@$self) {
264 11 100       72 if ( $_ !~ $test ) {
265 4 100       37 return if $count;
266 3         10 $count = 1;
267             }
268             }
269              
270 3 100       23 return 1 if $count;
271             }
272              
273             sub bool {
274 5     5 0 493 my ($self) = @_;
275 5         12 my $count = 0;
276              
277 5         13 for (@$self) {
278 11 100       32 if ($_) {
279 5 100       17 return if $count;
280 4         8 $count = 1;
281             }
282             }
283              
284 4 100       19 return 1 if $count;
285             }
286              
287             1;
288              
289             __END__
290              
291             =pod
292              
293             =encoding UTF-8
294              
295             =for :stopwords Arthur Axel "fREW" Schmidt Carl Franks
296              
297             =head1 BUGS
298              
299             Please report any bugs or feature requests on the bugtracker website
300             L<https://github.com/haarg/Syntax-Keyword-Junction/issues>
301              
302             When submitting a bug or request, please include a test-file or a
303             patch to an existing test-file that illustrates the bug or desired
304             feature.
305              
306             =head1 AUTHORS
307              
308             =over 4
309              
310             =item *
311              
312             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
313              
314             =item *
315              
316             Carl Franks
317              
318             =back
319              
320             =head1 COPYRIGHT AND LICENSE
321              
322             This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.
323              
324             This is free software; you can redistribute it and/or modify it under
325             the same terms as the Perl 5 programming language system itself.
326              
327             =cut