| 1 | package List::Objects::WithUtils::Array::Junction; | ||||||||||
| 2 | 202 | $List::Objects::WithUtils::Array::Junction::VERSION = '2.028002'; | |||||||||
| 3 | ## no critic | ||||||||||
| 4 | |||||||||||
| 5 | { package | ||||||||||
| 6 | List::Objects::WithUtils::Array::Junction::Base; | ||||||||||
| 7 | 208 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 208 | ▶ | use parent 'List::Objects::WithUtils::Array'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | ▶ | '""' => sub { shift }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 202 | ▶ | ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | } | ||||||||||
| 26 | 202 | { package | |||||||||
| 27 | List::Objects::WithUtils::Array::Junction::All; | ||||||||||
| 28 | 202 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 202 | our @ISA = 'List::Objects::WithUtils::Array::Junction::Base'; | |||||||||
| 30 | |||||||||||
| 31 | sub num_eq { | ||||||||||
| 32 | 9 | ▶ | return regex_eq(@_) if ref $_[1] eq 'Regexp'; | ||||||||
|
Subroutine
num_eq: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 33 | 5 | for (@{ $_[0] }) | |||||||||
| 34 | 9 | ▶ | { return unless $_ == $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | ||||||||||
| 36 | 3 | } | |||||||||
| 37 | |||||||||||
| 38 | sub num_ne { | ||||||||||
| 39 | 9 | ▶ | return regex_ne(@_) if ref $_[1] eq 'Regexp'; | ||||||||
|
Subroutine
num_ne: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 40 | 5 | for (@{ $_[0] }) | |||||||||
| 41 | 11 | ▶ | { return unless $_ != $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 1 | ||||||||||
| 43 | 3 | } | |||||||||
| 44 | |||||||||||
| 45 | sub num_ge { | ||||||||||
| 46 | 9 | ▶ | return num_le( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_ge: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 47 | 6 | for (@{ $_[0] }) | |||||||||
| 48 | 14 | ▶ | { return unless $_ >= $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 1 | ||||||||||
| 50 | 4 | } | |||||||||
| 51 | |||||||||||
| 52 | sub num_gt { | ||||||||||
| 53 | 8 | ▶ | return num_lt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_gt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 54 | 6 | for (@{ $_[0] }) | |||||||||
| 55 | 12 | ▶ | { return unless $_ > $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | ||||||||||
| 57 | 3 | } | |||||||||
| 58 | |||||||||||
| 59 | sub num_le { | ||||||||||
| 60 | 9 | ▶ | return num_ge( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_le: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 61 | 6 | for (@{ $_[0] }) | |||||||||
| 62 | 14 | ▶ | { return unless $_ <= $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 1 | ||||||||||
| 64 | 4 | } | |||||||||
| 65 | |||||||||||
| 66 | sub num_lt { | ||||||||||
| 67 | 8 | ▶ | return num_gt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_lt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 68 | 5 | for (@{ $_[0] }) | |||||||||
| 69 | 11 | ▶ | { return unless $_ < $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | ||||||||||
| 71 | 2 | } | |||||||||
| 72 | |||||||||||
| 73 | sub str_eq { | ||||||||||
| 74 | 2 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
str_eq: called CC=3 SCAR=11.0
| |||||||||||
| 75 | 4 | ▶ | { return unless $_ eq $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 1 | ||||||||||
| 77 | 1 | } | |||||||||
| 78 | |||||||||||
| 79 | sub str_ne { | ||||||||||
| 80 | 2 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
str_ne: called CC=3 SCAR=11.0
| |||||||||||
| 81 | 3 | ▶ | { return unless $_ ne $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 1 | ||||||||||
| 83 | 1 | } | |||||||||
| 84 | |||||||||||
| 85 | sub str_ge { | ||||||||||
| 86 | 9 | ▶ | return str_le( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_ge: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 87 | 6 | for (@{ $_[0] }) | |||||||||
| 88 | 10 | ▶ | { return unless $_ ge $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 1 | ||||||||||
| 90 | 4 | } | |||||||||
| 91 | |||||||||||
| 92 | sub str_gt { | ||||||||||
| 93 | 9 | ▶ | return str_lt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_gt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 94 | 6 | for (@{ $_[0] }) | |||||||||
| 95 | 8 | ▶ | { return unless $_ gt $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 1 | ||||||||||
| 97 | 2 | } | |||||||||
| 98 | |||||||||||
| 99 | sub str_le { | ||||||||||
| 100 | 9 | ▶ | return str_ge( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_le: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 101 | 6 | for (@{ $_[0] }) | |||||||||
| 102 | 10 | ▶ | { return unless $_ le $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 1 | ||||||||||
| 104 | 4 | } | |||||||||
| 105 | |||||||||||
| 106 | sub str_lt { | ||||||||||
| 107 | 9 | ▶ | return str_gt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_lt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 108 | 6 | for (@{ $_[0] }) | |||||||||
| 109 | 8 | ▶ | { return unless $_ lt $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 1 | ||||||||||
| 111 | 2 | } | |||||||||
| 112 | |||||||||||
| 113 | sub regex_eq { | ||||||||||
| 114 | 4 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
regex_eq: called CC=3 SCAR=11.0
| |||||||||||
| 115 | 8 | ▶ | { return unless $_ =~ $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 1 | ||||||||||
| 117 | 2 | } | |||||||||
| 118 | |||||||||||
| 119 | sub regex_ne { | ||||||||||
| 120 | 4 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
regex_ne: called CC=3 SCAR=11.0
| |||||||||||
| 121 | 10 | ▶ | { return unless $_ !~ $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 1 | ||||||||||
| 123 | 2 | } | |||||||||
| 124 | |||||||||||
| 125 | sub bool { | ||||||||||
| 126 | 4 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
bool: called CC=3 SCAR=11.0
| |||||||||||
| 127 | 7 | ▶ | { return unless $_ } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 1 | ||||||||||
| 129 | 1 | } | |||||||||
| 130 | |||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 202 | { package | |||||||||
| 134 | List::Objects::WithUtils::Array::Junction::Any; | ||||||||||
| 135 | 202 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 136 | 202 | our @ISA = 'List::Objects::WithUtils::Array::Junction::Base'; | |||||||||
| 137 | |||||||||||
| 138 | sub num_eq { | ||||||||||
| 139 | 5 | ▶ | return regex_eq(@_) if ref $_[1] eq 'Regexp'; | ||||||||
|
Subroutine
num_eq: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 140 | 3 | for (@{ $_[0] }) | |||||||||
| 141 | 5 | ▶ | { return 1 if $_ == $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | () | ||||||||||
| 143 | 1 | } | |||||||||
| 144 | |||||||||||
| 145 | sub num_ne { | ||||||||||
| 146 | 4 | ▶ | return regex_eq(@_) if ref $_[1] eq 'Regexp'; | ||||||||
|
Subroutine
num_ne: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 147 | 3 | for (@{ $_[0] }) | |||||||||
| 148 | 5 | ▶ | { return 1 if $_ != $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | () | ||||||||||
| 150 | 1 | } | |||||||||
| 151 | |||||||||||
| 152 | sub num_ge { | ||||||||||
| 153 | 9 | ▶ | return num_le( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_ge: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 154 | 6 | for (@{ $_[0] }) | |||||||||
| 155 | 14 | ▶ | { return 1 if $_ >= $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | () | ||||||||||
| 157 | 2 | } | |||||||||
| 158 | |||||||||||
| 159 | sub num_gt { | ||||||||||
| 160 | 10 | ▶ | return num_lt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_gt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 161 | 7 | for (@{ $_[0] }) | |||||||||
| 162 | 16 | ▶ | { return 1 if $_ > $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | () | ||||||||||
| 164 | 2 | } | |||||||||
| 165 | |||||||||||
| 166 | sub num_le { | ||||||||||
| 167 | 9 | ▶ | return num_ge( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_le: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 168 | 6 | for (@{ $_[0] }) | |||||||||
| 169 | 10 | ▶ | { return 1 if $_ <= $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | () | ||||||||||
| 171 | 2 | } | |||||||||
| 172 | |||||||||||
| 173 | sub num_lt { | ||||||||||
| 174 | 9 | ▶ | return num_gt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
num_lt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 175 | 6 | for (@{ $_[0] }) | |||||||||
| 176 | 10 | ▶ | { return 1 if $_ < $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 177 | () | ||||||||||
| 178 | 2 | } | |||||||||
| 179 | |||||||||||
| 180 | sub str_eq { | ||||||||||
| 181 | 2 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
str_eq: called CC=3 SCAR=11.0
| |||||||||||
| 182 | 3 | ▶ | { return 1 if $_ eq $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | () | ||||||||||
| 184 | 1 | } | |||||||||
| 185 | |||||||||||
| 186 | sub str_ne { | ||||||||||
| 187 | 2 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
str_ne: called CC=3 SCAR=11.0
| |||||||||||
| 188 | 4 | ▶ | { return 1 if $_ ne $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 189 | () | ||||||||||
| 190 | 1 | } | |||||||||
| 191 | |||||||||||
| 192 | sub str_ge { | ||||||||||
| 193 | 9 | ▶ | return str_le( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_ge: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 194 | 6 | for (@{ $_[0] }) | |||||||||
| 195 | 8 | ▶ | { return 1 if $_ ge $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | () | ||||||||||
| 197 | 2 | } | |||||||||
| 198 | |||||||||||
| 199 | sub str_gt { | ||||||||||
| 200 | 10 | ▶ | return str_lt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_gt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 201 | 6 | for (@{ $_[0] }) | |||||||||
| 202 | 9 | ▶ | { return 1 if $_ gt $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 203 | () | ||||||||||
| 204 | 2 | } | |||||||||
| 205 | |||||||||||
| 206 | sub str_le { | ||||||||||
| 207 | 9 | ▶ | return str_ge( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_le: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 208 | 6 | for (@{ $_[0] }) | |||||||||
| 209 | 8 | ▶ | { return 1 if $_ le $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 210 | () | ||||||||||
| 211 | 2 | } | |||||||||
| 212 | |||||||||||
| 213 | sub str_lt { | ||||||||||
| 214 | 10 | ▶ | return str_gt( @_[0, 1] ) if $_[2]; | ||||||||
|
Subroutine
str_lt: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||
| 215 | 7 | for (@{ $_[0] }) | |||||||||
| 216 | 12 | ▶ | { return 1 if $_ lt $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 217 | () | ||||||||||
| 218 | 3 | } | |||||||||
| 219 | |||||||||||
| 220 | sub regex_eq { | ||||||||||
| 221 | 3 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
regex_eq: called CC=3 SCAR=11.0
| |||||||||||
| 222 | 5 | ▶ | { return 1 if $_ =~ $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 223 | () | ||||||||||
| 224 | 1 | } | |||||||||
| 225 | |||||||||||
| 226 | sub regex_ne { | ||||||||||
| 227 | 0 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
regex_ne: not called CC=3 SCAR=24.8
| |||||||||||
| 228 | 0 | ▶ | { return 1 if $_ !~ $_[1] } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 229 | () | ||||||||||
| 230 | 0 | } | |||||||||
| 231 | |||||||||||
| 232 | sub bool { | ||||||||||
| 233 | 3 | ▶ | for (@{ $_[0] }) | ||||||||
|
Subroutine
bool: called CC=3 SCAR=11.0
| |||||||||||
| 234 | 5 | ▶ | { return 1 if $_ } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 235 | () | ||||||||||
| 236 | 1 | } | |||||||||
| 237 | } | ||||||||||
| 238 | |||||||||||
| 239 | 202 | 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<Syntax::Keyword::Junction>. They provide the objects created by | ||||||||||
| 257 | the C<all_items> and C<any_items> methods defined by | ||||||||||
| 258 | L<List::Objects::WithUtils::Role::Array::WithJunctions>. | ||||||||||
| 259 | |||||||||||
| 260 | Only the junction types used by L<List::Objects::WithUtils> ('any' and 'all') | ||||||||||
| 261 | are implemented; nothing is exported. The C<~~> smart-match operator is not | ||||||||||
| 262 | supported. See L<Syntax::Keyword::Junction> if you were looking for a | ||||||||||
| 263 | stand-alone implementation with more features. | ||||||||||
| 264 | |||||||||||
| 265 | The junction objects produced are subclasses of | ||||||||||
| 266 | L<List::Objects::WithUtils::Array>. | ||||||||||
| 267 | |||||||||||
| 268 | See L<List::Objects::WithUtils::Role::Array::WithJunctions> for usage details. | ||||||||||
| 269 | |||||||||||
| 270 | =head2 Motivation | ||||||||||
| 271 | |||||||||||
| 272 | My original goal was to get L<Sub::Exporter> out of the | ||||||||||
| 273 | L<List::Objects::WithUtils> dependency tree; that one came along with | ||||||||||
| 274 | L<Syntax::Keyword::Junction>. | ||||||||||
| 275 | |||||||||||
| 276 | L<Perl6::Junction> 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<Perl6::Junction> by way of | ||||||||||
| 283 | L<Syntax::Keyword::Junction>; the original author is Carl Franks, based on the | ||||||||||
| 284 | Perl6 design documentation. | ||||||||||
| 285 | |||||||||||
| 286 | Adapted to L<List::Objects::WithUtils> by Jon Portnoy <avenj@cobaltirc.org> | ||||||||||
| 287 | |||||||||||
| 288 | =cut | ||||||||||