File Coverage

blib/lib/Data/Rx/CoreType/map.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 8 62.5
condition 3 3 100.0
subroutine 7 7 100.0
pod 0 3 0.0
total 40 46 86.9


line stmt bran cond sub pod time code
1 1     1   3 use strict;
  1         1  
  1         24  
2 1     1   3 use warnings;
  1         1  
  1         30  
3             package Data::Rx::CoreType::map;
4             # ABSTRACT: the Rx //map type
5             $Data::Rx::CoreType::map::VERSION = '0.200007';
6 1     1   2 use parent 'Data::Rx::CoreType';
  1         1  
  1         3  
7              
8 1     1   35 use Scalar::Util ();
  1         1  
  1         175  
9              
10 54     54 0 110 sub subname { 'map' }
11              
12             sub guts_from_arg {
13 5     5 0 8 my ($class, $arg, $rx, $type) = @_;
14              
15 5 50       17 Carp::croak("unknown arguments to new") unless
16             Data::Rx::Util->_x_subset_keys_y($arg, { values => 1 });
17              
18 5 50       17 Carp::croak("no values constraint given") unless $arg->{values};
19              
20 5         35 return { value_constraint => $rx->make_schema($arg->{values}) };
21             }
22              
23             sub assert_valid {
24 61     61 0 2707 my ($self, $value) = @_;
25              
26 61 100 100     270 unless (! Scalar::Util::blessed($value) and ref $value eq 'HASH') {
27 43         168 $self->fail({
28             error => [ qw(type) ],
29             message => "found value is not a hashref",
30             value => $value,
31             });
32             }
33              
34 18         18 my @subchecks;
35 18 50       43 for my $key ($self->rx->sort_keys ? sort keys %$value : keys %$value) {
36 31         125 push @subchecks, [
37             $value->{ $key },
38             $self->{value_constraint},
39             { data_path => [ [$key, 'key'] ],
40             check_path => [ ['values', 'key' ] ],
41             },
42             ];
43             }
44              
45 18         57 $self->perform_subchecks(\@subchecks);
46              
47 10         35 return 1;
48             }
49              
50             1;
51              
52             __END__