File Coverage

blib/lib/Switch/Perlish/Smatch/Hash.pm
Criterion Covered Total %
statement 30 31 96.7
branch n/a
condition 13 15 86.6
subroutine 11 11 100.0
pod n/a
total 54 57 94.7


line stmt bran cond sub pod time code
1             package Switch::Perlish::Smatch::Hash;
2              
3             $VERSION = '1.0.0';
4              
5 11     11   63 use strict;
  11         21  
  11         381  
6 11     11   62 use warnings;
  11         20  
  11         324  
7              
8 11     11   73 use Switch::Perlish::Smatch 'smatch';
  11         15  
  11         12432  
9              
10             ## Provide a wrapper sub to test against values?
11             ## DESC - Check if $m exists as a key in %$t.
12             sub _VALUE {
13 3     3   6 my($t, $m) = @_;
14 3         24 return exists $t->{$m};
15             }
16              
17             ## DESC - Check for an undefined value in %$t (better suggestions welcome).
18             sub _UNDEF {
19 1     1   2 my($t, $m) = @_;
20             !defined and return 1
21 1   50     12 for values %$t;
22 0         0 return;
23             }
24              
25             ## DESC - Check if $m points to value in %$t.
26             sub _SCALAR {
27 2     2   5 my($t, $m) = @_;
28             \$_ == $m and return 1
29 2   100     16 for values %$t;
30 1         7 return;
31             }
32              
33             ## DESC - Check if an element of @$m exists as a key of %$t.
34             sub _ARRAY {
35 2     2   5 my($t, $m) = @_;
36             exists $t->{$_} and return 1
37 2   100     29 for @$m;
38 1         9 return;
39             }
40              
41             ## DESC - Check if a key =E value pair exists in both %$t and %$m.
42             sub _HASH {
43 4     4   7 my($t, $m) = @_;
44             exists $t->{$_} and smatch($t->{$_}, $m->{$_}) and return 1
45 4   66     55 for keys %$m;
      100        
46 2         16 return;
47             }
48              
49             ## DESC - Check if the return from &$m is a hash key of %$t.
50             sub _CODE {
51 2     2   5 my($t, $m) = @_;
52 2         8 return exists $t->{$m->()};
53             }
54              
55             ## DESC - Check if a key of %$t exists as a method of $m.
56             sub _OBJECT {
57 2     2   3 my($t, $m) = @_;
58             $m->can($_) and return 1
59 2   100     46 for keys %$t;
60 1         8 return;
61             }
62              
63             ## DESC - Check if any keys from %$t match $m.
64             sub _Regexp {
65 2     2   6 my($t, $m) = @_;
66             /$m/ and return 1
67 2   100     62 for keys %$t;
68 1         15 return;
69             }
70              
71             Switch::Perlish::Smatch->register_package( __PACKAGE__, 'HASH' );
72              
73             1;
74              
75             =pod
76              
77             =head1 NAME
78              
79             Switch::Perlish::Smatch::Hash - The C comparatory category package.
80              
81             =head1 VERSION
82              
83             1.0.0 - Initial release.
84              
85             =head1 DESCRIPTION
86              
87             This package provides the default implementation for the C comparator
88             category. For more information on the comparator implementation see.
89             L.
90              
91             =head1 SEE. ALSO
92              
93             L
94              
95             L
96              
97             =head1 AUTHOR
98              
99             Dan Brook C<< >>
100              
101             =head1 COPYRIGHT
102              
103             Copyright (c) 2006, Dan Brook. All Rights Reserved. This module is free
104             software. It may be used, redistributed and/or modified under the same
105             terms as Perl itself.
106              
107             =cut