File Coverage

blib/lib/List/Objects/WithUtils/Array/Typed.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 24 25 96.0


line stmt bran cond sub pod time code
1             package List::Objects::WithUtils::Array::Typed;
2             $List::Objects::WithUtils::Array::Typed::VERSION = '2.028003';
3 99     99   1074 use strictures 2;
  99         425  
  99         3176  
4              
5             require Role::Tiny;
6             Role::Tiny->apply_roles_to_package( __PACKAGE__,
7             qw/
8             List::Objects::WithUtils::Role::Array
9             List::Objects::WithUtils::Role::Array::WithJunctions
10             List::Objects::WithUtils::Role::Array::Typed
11             /,
12             );
13              
14 99     99   14750 use Exporter ();
  99         126  
  99         4144  
15             our @EXPORT = 'array_of';
16              
17             sub import {
18 100     100   171 my $pkg = caller;
19 99     99   457 { no strict 'refs';
  99         116  
  99         10959  
  100         109  
20 100         322 ${"${pkg}::a"} = ${"${pkg}::a"};
  100         149  
  100         302  
21 100         93 ${"${pkg}::b"} = ${"${pkg}::b"};
  100         197  
  100         159  
22             }
23 100         4940 goto &Exporter::import
24             }
25              
26 5     5 0 964 sub array_of { __PACKAGE__->new(@_) }
27              
28             1;
29              
30             =pod
31              
32             =for Pod::Coverage array_of
33              
34             =head1 NAME
35              
36             List::Objects::WithUtils::Array::Typed - Type-checking array objects
37              
38             =head1 SYNOPSIS
39              
40             use List::Objects::WithUtils 'array_of';
41              
42             use Types::Standard -all;
43             use List::Objects::Types -all;
44              
45             my $arr = array_of( Int() => 1 .. 10 );
46             $arr->push('foo'); # dies, failed type check
47             $arr->push(11 .. 15); # ok
48              
49             my $arr_of_arrs = array_of( ArrayObj );
50             $arr_of_arrs->push([], []); # ok, coerces to ArrayObj
51              
52             =head1 DESCRIPTION
53              
54             These are type-checking array objects; elements are checked against the
55             specified type when the object is constructed or new elements are added.
56              
57             The first argument passed to the constructor should be a L type:
58              
59             use Types::Standard -all;
60             my $arr = array_of Str() => qw/foo bar baz/;
61              
62             If the initial type-check fails, a coercion is attempted.
63              
64             This class consumes the following roles, which contain most of the relevant
65             documentation:
66              
67             L
68              
69             L
70              
71             L
72              
73             Also see L, L
74              
75             =head1 AUTHOR
76              
77             Jon Portnoy with significant contributions from Toby
78             Inkster (CPAN: TOBYINK)
79              
80             =cut