| 1 | package List::Objects::WithUtils::Role::Array::WithJunctions; | ||
| 2 | 202 | $List::Objects::WithUtils::Role::Array::WithJunctions::VERSION = '2.028002'; | |
| 3 | 208 | ▶ | use strictures 2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 208 | ▶ | use List::Objects::WithUtils::Array::Junction (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 202 | ▶ | use Role::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | sub any_items { | ||
| 10 | 67 | ▶ | List::Objects::WithUtils::Array::Junction::Any->new( @{ $_[0] } ) |
|
Subroutine
any_items: called CC=1 SCAR=0.0
Pod
documented
| |||
| 11 | } | ||
| 12 | |||
| 13 | sub all_items { | ||
| 14 | 74 | ▶ | List::Objects::WithUtils::Array::Junction::All->new( @{ $_[0] } ) |
|
Subroutine
all_items: called CC=1 SCAR=0.0
Pod
documented
| |||
| 15 | } | ||
| 16 | |||
| 17 | 202 | 1; | |
| 18 | |||
| 19 | =pod | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | List::Objects::WithUtils::Role::Array::WithJunctions - Add junctions | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | ## Via List::Objects::WithUtils::Array -> | ||
| 28 | use List::Objects::WithUtils 'array'; | ||
| 29 | |||
| 30 | my $array = array(qw/ a b c /); | ||
| 31 | |||
| 32 | if ( $array->any_items eq 'b' ) { | ||
| 33 | ... | ||
| 34 | } | ||
| 35 | |||
| 36 | if ( $array->all_items eq 'a' ) { | ||
| 37 | ... | ||
| 38 | } | ||
| 39 | |||
| 40 | if ( $array->any_items == qr/^b/ ) { | ||
| 41 | ... | ||
| 42 | } | ||
| 43 | |||
| 44 | ## As a Role -> | ||
| 45 | use Role::Tiny::With; | ||
| 46 | with 'List::Objects::WithUtils::Role::Array', | ||
| 47 | 'List::Objects::WithUtils::Role::Array::WithJunctions'; | ||
| 48 | |||
| 49 | =head1 DESCRIPTION | ||
| 50 | |||
| 51 | These methods supply overloaded L<List::Objects::WithUtils::Array::Junction> | ||
| 52 | objects that can be compared with values using normal Perl comparison | ||
| 53 | operators. | ||
| 54 | |||
| 55 | Regular expressions can be matched by providing a C<qr//> regular expression | ||
| 56 | object to the C<==> or C<!=> operators. | ||
| 57 | |||
| 58 | There is no support for the C<~~> experimental smart-match operator. | ||
| 59 | |||
| 60 | The junction objects returned are subclasses of | ||
| 61 | L<List::Objects::WithUtils::Array>, allowing manipulation of junctions (of | ||
| 62 | varying degrees of sanity) -- a simple case might be generating a new junction | ||
| 63 | out of an old junction: | ||
| 64 | |||
| 65 | my $list = array(3, 4, 5); | ||
| 66 | if ( (my $anyof = $list->any_items) > 2 ) { | ||
| 67 | my $incr = $anyof->map(sub { $_[0] + 1 })->all_items; | ||
| 68 | if ( $incr > 6 ) { | ||
| 69 | # ... | ||
| 70 | } | ||
| 71 | # Drop junction magic again: | ||
| 72 | my $plain = array( $incr->all ); | ||
| 73 | } | ||
| 74 | |||
| 75 | =head2 any_items | ||
| 76 | |||
| 77 | Returns the overloaded B<any> object for the current array; a comparison is | ||
| 78 | true if any items in the array satisfy the condition. | ||
| 79 | |||
| 80 | =head2 all_items | ||
| 81 | |||
| 82 | Returns the overloaded B<all> object for the current array; a comparison is | ||
| 83 | true only if all items in the array satisfy the condition. | ||
| 84 | |||
| 85 | =head1 AUTHOR | ||
| 86 | |||
| 87 | Jon Portnoy <avenj@cobaltirc.org> | ||
| 88 | |||
| 89 | =cut | ||