File Coverage

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


line stmt bran cond sub pod time code
1             package List::Objects::WithUtils::Hash::Typed;
2             $List::Objects::WithUtils::Hash::Typed::VERSION = '2.028003';
3 99     99   1105 use strictures 2;
  99         454  
  99         3264  
4              
5             require Role::Tiny;
6             Role::Tiny->apply_roles_to_package( __PACKAGE__,
7             qw/
8             List::Objects::WithUtils::Role::Hash
9             List::Objects::WithUtils::Role::Hash::Typed
10             /
11             );
12              
13 99     99   14638 use Exporter ();
  99         125  
  99         4017  
14             our @EXPORT = 'hash_of';
15              
16             sub import {
17 100     100   170 my $pkg = caller;
18 99     99   400 { no strict 'refs';
  99         114  
  99         10890  
  100         101  
19 100         256 ${"${pkg}::a"} = ${"${pkg}::a"}; ${"${pkg}::b"} = ${"${pkg}::b"};
  100         154  
  100         365  
  100         108  
  100         146  
  100         152  
20             }
21 100         5016 goto &Exporter::import
22             }
23              
24 6     6 1 1370 sub hash_of { __PACKAGE__->new(@_) }
25              
26             1;
27              
28              
29             =pod
30              
31             =head1 NAME
32              
33             List::Objects::WithUtils::Hash::Typed - Type-checking hash objects
34              
35             =head1 SYNOPSIS
36              
37             use List::Objects::WithUtils 'hash_of';
38              
39             use Types::Standard -all;
40              
41             my $arr = hash_of Int() => ( foo => 1, bar => 2 );
42              
43             =head1 DESCRIPTION
44              
45             These are type-checking hash objects; values are checked against the specified
46             type when the object is constructed or new elements are added.
47              
48             The first argument passed to the constructor should be a L type:
49              
50             use Types::Standard -all;
51             my $hash = hash_of Int() => ( foo => 1 );
52              
53             If the initial type-check fails, a coercion is attempted.
54              
55             This class consumes the following roles, which contain most of the relevant
56             documentation:
57              
58             L
59              
60             L
61              
62             Also see L, L
63              
64             =head2 hash_of
65              
66             Creates a new typed hash object.
67              
68             =head1 AUTHOR
69              
70             Jon Portnoy with significant contributions from Toby
71             Inkster (CPAN: TOBYINK)
72              
73             =cut