File Coverage

blib/lib/List/Objects/WithUtils/Role/Array/WithJunctions.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 20 20 100.0


line stmt bran cond sub pod time code
1             package List::Objects::WithUtils::Role::Array::WithJunctions;
2             $List::Objects::WithUtils::Role::Array::WithJunctions::VERSION = '2.028002';
3 208     208   84761 use strictures 2;
  208         989  
  208         6647  
4              
5 208     208   109919 use List::Objects::WithUtils::Array::Junction ();
  208         334  
  208         3550  
6              
7 208     208   850 use Role::Tiny;
  208         213  
  208         974  
8              
9             sub any_items {
10 67     67 1 55 List::Objects::WithUtils::Array::Junction::Any->new( @{ $_[0] } )
  67         151  
11             }
12              
13             sub all_items {
14 74     74 1 73 List::Objects::WithUtils::Array::Junction::All->new( @{ $_[0] } )
  74         188  
15             }
16              
17             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
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 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, 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 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 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
88              
89             =cut