List/Objects/WithUtils/Array/Typed.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.6% 29 / 30 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
import
1.0
CRAP 1.0
« List/Objects/WithUtils/Hash/Immutable/Typed.pm ↑ Summary List/Objects/WithUtils/Hash.pm »
1 package List::Objects::WithUtils::Array::Typed;
2 93 $List::Objects::WithUtils::Array::Typed::VERSION = '2.028002';
3 99 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 93 require Role::Tiny;
6 93 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 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 93 our @EXPORT = 'array_of';
16  
17 sub import {
18 94 ▶ my $pkg = caller;
Subroutine import: called CC=1 SCAR=0.0
19 99 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 94 ${"${pkg}::a"} = ${"${pkg}::a"};
21 94 ${"${pkg}::b"} = ${"${pkg}::b"};
22 }
23 94 goto &Exporter::import
24 }
25  
26 5 ▶sub array_of { __PACKAGE__->new(@_) }
Subroutine array_of: called CC=1 SCAR=0.0
Pod undocumented
27  
28 93 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::Tiny> 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<List::Objects::WithUtils::Role::Array>
68  
69 L<List::Objects::WithUtils::Role::Array::WithJunctions>
70  
71 L<List::Objects::WithUtils::Role::Array::Typed>
72  
73 Also see L<Types::Standard>, L<List::Objects::Types>
74  
75 =head1 AUTHOR
76  
77 Jon Portnoy <avenj@cobaltirc.org> with significant contributions from Toby
78 Inkster (CPAN: TOBYINK)
79  
80 =cut
« List/Objects/WithUtils/Hash/Immutable/Typed.pm ↑ Summary List/Objects/WithUtils/Hash.pm »