File Coverage

blib/lib/List/Objects/WithUtils/Array/Junction.pm
Criterion Covered Total %
statement 157 162 96.9
branch 98 100 98.0
condition n/a
subroutine 36 38 94.7
pod n/a
total 291 300 97.0


line stmt bran cond sub pod time code
1             package List::Objects::WithUtils::Array::Junction;
2             $List::Objects::WithUtils::Array::Junction::VERSION = '2.027002';
3             ## no critic
4              
5             { package
6             List::Objects::WithUtils::Array::Junction::Base;
7 205     205   2387 use strictures 2;
  205         1259  
  205         8007  
8 205     205   40898 use parent 'List::Objects::WithUtils::Array';
  205         1358  
  205         1048  
9             use overload
10             '==' => 'num_eq',
11             '!=' => 'num_ne',
12             '>=' => 'num_ge',
13             '>' => 'num_gt',
14             '<=' => 'num_le',
15             '<' => 'num_lt',
16             'eq' => 'str_eq',
17             'ne' => 'str_ne',
18             'ge' => 'str_ge',
19             'gt' => 'str_gt',
20             'le' => 'str_le',
21             'lt' => 'str_lt',
22             'bool' => 'bool',
23 0     0   0 '""' => sub { shift },
24 205     205   294014 ;
  205         190031  
  205         1997  
25             }
26             { package
27             List::Objects::WithUtils::Array::Junction::All;
28 205     205   55064 use strict; use warnings;
  205     205   376  
  205         4519  
  205         1002  
  205         364  
  205         182291  
29             our @ISA = 'List::Objects::WithUtils::Array::Junction::Base';
30              
31             sub num_eq {
32 9 100   9   35 return regex_eq(@_) if ref $_[1] eq 'Regexp';
33 5         7 for (@{ $_[0] })
  5         19  
34 9 100       30 { return unless $_ == $_[1] }
35             1
36 3         16 }
37              
38             sub num_ne {
39 9 100   9   49 return regex_ne(@_) if ref $_[1] eq 'Regexp';
40 5         7 for (@{ $_[0] })
  5         24  
41 11 100       37 { return unless $_ != $_[1] }
42             1
43 3         12 }
44              
45             sub num_ge {
46 9 100   9   36 return num_le( @_[0, 1] ) if $_[2];
47 6         8 for (@{ $_[0] })
  6         16  
48 14 100       43 { return unless $_ >= $_[1] }
49             1
50 4         16 }
51              
52             sub num_gt {
53 8 100   8   811 return num_lt( @_[0, 1] ) if $_[2];
54 6         11 for (@{ $_[0] })
  6         17  
55 12 100       40 { return unless $_ > $_[1] }
56             1
57 3         13 }
58              
59             sub num_le {
60 9 100   9   26 return num_ge( @_[0, 1] ) if $_[2];
61 6         7 for (@{ $_[0] })
  6         16  
62 14 100       41 { return unless $_ <= $_[1] }
63             1
64 4         18 }
65              
66             sub num_lt {
67 8 100   8   25 return num_gt( @_[0, 1] ) if $_[2];
68 5         6 for (@{ $_[0] })
  5         29  
69 11 100       36 { return unless $_ < $_[1] }
70             1
71 2         10 }
72              
73             sub str_eq {
74 2     2   3 for (@{ $_[0] })
  2         7  
75 4 100       14 { return unless $_ eq $_[1] }
76             1
77 1         3 }
78              
79             sub str_ne {
80 2     2   3 for (@{ $_[0] })
  2         6  
81 3 100       13 { return unless $_ ne $_[1] }
82             1
83 1         4 }
84              
85             sub str_ge {
86 9 100   9   29 return str_le( @_[0, 1] ) if $_[2];
87 6         9 for (@{ $_[0] })
  6         16  
88 10 100       38 { return unless $_ ge $_[1] }
89             1
90 4         15 }
91              
92             sub str_gt {
93 9 100   9   29 return str_lt( @_[0, 1] ) if $_[2];
94 6         7 for (@{ $_[0] })
  6         18  
95 8 100       39 { return unless $_ gt $_[1] }
96             1
97 2         10 }
98              
99             sub str_le {
100 9 100   9   30 return str_ge( @_[0, 1] ) if $_[2];
101 6         9 for (@{ $_[0] })
  6         13  
102 10 100       41 { return unless $_ le $_[1] }
103             1
104 4         18 }
105              
106             sub str_lt {
107 9 100   9   37 return str_gt( @_[0, 1] ) if $_[2];
108 6         9 for (@{ $_[0] })
  6         16  
109 8 100       35 { return unless $_ lt $_[1] }
110             1
111 2         17 }
112              
113             sub regex_eq {
114 4     4   5 for (@{ $_[0] })
  4         21  
115 8 100       86 { return unless $_ =~ $_[1] }
116             1
117 2         11 }
118              
119             sub regex_ne {
120 4     4   6 for (@{ $_[0] })
  4         11  
121 10 100       58 { return unless $_ !~ $_[1] }
122             1
123 2         10 }
124              
125             sub bool {
126 4     4   20 for (@{ $_[0] })
  4         12  
127 7 100       26 { return unless $_ }
128             1
129 1         4 }
130              
131             }
132              
133             { package
134             List::Objects::WithUtils::Array::Junction::Any;
135 205     205   1131 use strict; use warnings;
  205     205   355  
  205         4221  
  205         1064  
  205         404  
  205         181779  
136             our @ISA = 'List::Objects::WithUtils::Array::Junction::Base';
137              
138             sub num_eq {
139 5 100   5   20 return regex_eq(@_) if ref $_[1] eq 'Regexp';
140 3         4 for (@{ $_[0] })
  3         7  
141 5 100       19 { return 1 if $_ == $_[1] }
142             ()
143 1         5 }
144              
145             sub num_ne {
146 4 100   4   18 return regex_eq(@_) if ref $_[1] eq 'Regexp';
147 3         6 for (@{ $_[0] })
  3         7  
148 5 100       20 { return 1 if $_ != $_[1] }
149             ()
150 1         5 }
151              
152             sub num_ge {
153 9 100   9   29 return num_le( @_[0, 1] ) if $_[2];
154 6         9 for (@{ $_[0] })
  6         14  
155 14 100       46 { return 1 if $_ >= $_[1] }
156             ()
157 2         32 }
158              
159             sub num_gt {
160 10 100   10   487 return num_lt( @_[0, 1] ) if $_[2];
161 7         10 for (@{ $_[0] })
  7         18  
162 16 100       54 { return 1 if $_ > $_[1] }
163             ()
164 2         9 }
165              
166             sub num_le {
167 9 100   9   27 return num_ge( @_[0, 1] ) if $_[2];
168 6         8 for (@{ $_[0] })
  6         14  
169 10 100       36 { return 1 if $_ <= $_[1] }
170             ()
171 2         9 }
172              
173             sub num_lt {
174 9 100   9   25 return num_gt( @_[0, 1] ) if $_[2];
175 6         9 for (@{ $_[0] })
  6         15  
176 10 100       38 { return 1 if $_ < $_[1] }
177             ()
178 2         8 }
179              
180             sub str_eq {
181 2     2   3 for (@{ $_[0] })
  2         7  
182 3 100       12 { return 1 if $_ eq $_[1] }
183             ()
184 1         4 }
185              
186             sub str_ne {
187 2     2   4 for (@{ $_[0] })
  2         6  
188 4 100       16 { return 1 if $_ ne $_[1] }
189             ()
190 1         5 }
191              
192             sub str_ge {
193 9 100   9   27 return str_le( @_[0, 1] ) if $_[2];
194 6         9 for (@{ $_[0] })
  6         16  
195 8 100       32 { return 1 if $_ ge $_[1] }
196             ()
197 2         8 }
198              
199             sub str_gt {
200 10 100   10   32 return str_lt( @_[0, 1] ) if $_[2];
201 6         7 for (@{ $_[0] })
  6         16  
202 9 100       35 { return 1 if $_ gt $_[1] }
203             ()
204 2         9 }
205              
206             sub str_le {
207 9 100   9   26 return str_ge( @_[0, 1] ) if $_[2];
208 6         8 for (@{ $_[0] })
  6         16  
209 8 100       32 { return 1 if $_ le $_[1] }
210             ()
211 2         9 }
212              
213             sub str_lt {
214 10 100   10   27 return str_gt( @_[0, 1] ) if $_[2];
215 7         9 for (@{ $_[0] })
  7         18  
216 12 100       50 { return 1 if $_ lt $_[1] }
217             ()
218 3         13 }
219              
220             sub regex_eq {
221 3     3   4 for (@{ $_[0] })
  3         8  
222 5 100       38 { return 1 if $_ =~ $_[1] }
223             ()
224 1         5 }
225              
226             sub regex_ne {
227 0     0   0 for (@{ $_[0] })
  0         0  
228 0 0       0 { return 1 if $_ !~ $_[1] }
229             ()
230 0         0 }
231              
232             sub bool {
233 3     3   36 for (@{ $_[0] })
  3         8  
234 5 100       17 { return 1 if $_ }
235             ()
236 1         4 }
237             }
238              
239             1;
240              
241             =pod
242              
243             =for Pod::Coverage new
244              
245             =head1 NAME
246              
247             List::Objects::WithUtils::Array::Junction - Lightweight junction classes
248              
249             =head1 SYNOPSIS
250              
251             # See List::Objects::WithUtils::Role::Array::WithJunctions
252              
253             =head1 DESCRIPTION
254              
255             These are light-weight junction objects covering most of the functionality
256             provided by L. They provide the objects created by
257             the C and C methods defined by
258             L.
259              
260             Only the junction types used by L ('any' and 'all')
261             are implemented; nothing is exported. The C<~~> smart-match operator is not
262             supported. See L if you were looking for a
263             stand-alone implementation with more features.
264              
265             The junction objects produced are subclasses of
266             L.
267              
268             See L for usage details.
269              
270             =head2 Motivation
271              
272             My original goal was to get L out of the
273             L dependency tree; that one came along with
274             L.
275              
276             L would have done that for me. Unfortunately, that comes with
277             some unresolved RT bugs right now that are reasonably annoying (especially
278             warnings under perl-5.18.x).
279              
280             =head1 AUTHOR
281              
282             This code is originally derived from L by way of
283             L; the original author is Carl Franks, based on the
284             Perl6 design documentation.
285              
286             Adapted to L by Jon Portnoy
287              
288             =cut