File Coverage

blib/lib/Specio/Library/Structured/Map.pm
Criterion Covered Total %
statement 35 35 100.0
branch 2 4 50.0
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 48 51 94.1


line stmt bran cond sub pod time code
1             package Specio::Library::Structured::Map;
2              
3 4     4   29 use strict;
  4         9  
  4         132  
4 4     4   24 use warnings;
  4         10  
  4         199  
5              
6             our $VERSION = '0.47';
7              
8 4     4   23 use Carp qw( confess );
  4         10  
  4         183  
9 4     4   24 use List::Util ();
  4         8  
  4         89  
10 4     4   24 use Specio::Library::Builtins;
  4         15  
  4         28  
11 4     4   32 use Specio::TypeChecks qw( does_role );
  4         8  
  4         1812  
12              
13             my $hashref = t('HashRef');
14              
15 4     4 0 26 sub parent {$hashref}
16              
17             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
18             sub _inline {
19 1     1   9 $hashref->inline_check( $_[1] );
20             }
21              
22             sub _parameterization_args_builder {
23 2     2   49 shift;
24 2         4 my $args = shift;
25              
26 2         9 for my $k (qw( key value )) {
27             does_role(
28 4 50       25 $args->{$k},
29             'Specio::Constraint::Role::Interface'
30             )
31             or confess
32             qq{The "$k" parameter passed to ->parameterize must be one or more objects which do the Specio::Constraint::Role::Interface role};
33              
34             confess
35             qq{The "$k" parameter passed to ->parameterize must be an inlinable constraint}
36 4 50       76 unless $args->{$k}->can_be_inlined;
37             }
38 2         28 return map { $_ => $args->{$_} } qw( key value );
  4         18  
39             }
40              
41             sub _name_builder {
42 2     2   11 my $self = shift;
43 2         4 my $p = shift;
44              
45             ## no critic (Subroutines::ProtectPrivateSubs)
46             return
47             'Map{ '
48             . $self->_name_or_anon( $p->{key} ) . ' => '
49 2         10 . $self->_name_or_anon( $p->{value} ) . ' }';
50             }
51              
52             sub _structured_inline_generator {
53 3     3   5 shift;
54 3         5 my $val = shift;
55 3         14 my %args = @_;
56              
57 3         7 my $code = <<'EOF';
58             (
59             ( %s )
60             && ( List::Util::all { %s } keys %%{ %s } )
61             && ( List::Util::all { %s } values %%{ %s } )
62             )
63             EOF
64              
65             return sprintf(
66             $code,
67             $hashref->_inline_check($val),
68             $args{key}->inline_check('$_'),
69             $val,
70 3         11 $args{value}->inline_check('$_'),
71             $val,
72             );
73             }
74              
75             1;
76              
77             # ABSTRACT: Guts of Map structured type
78              
79             __END__
80              
81             =pod
82              
83             =encoding UTF-8
84              
85             =head1 NAME
86              
87             Specio::Library::Structured::Map - Guts of Map structured type
88              
89             =head1 VERSION
90              
91             version 0.47
92              
93             =head1 DESCRIPTION
94              
95             There are no user facing parts here.
96              
97             =for Pod::Coverage .*
98              
99             =head1 SUPPORT
100              
101             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
102              
103             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
104              
105             =head1 SOURCE
106              
107             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
108              
109             =head1 AUTHOR
110              
111             Dave Rolsky <autarch@urth.org>
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             This software is Copyright (c) 2012 - 2021 by Dave Rolsky.
116              
117             This is free software, licensed under:
118              
119             The Artistic License 2.0 (GPL Compatible)
120              
121             The full text of the license can be found in the
122             F<LICENSE> file included with this distribution.
123              
124             =cut