Perlish/Smatch/Hash.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 93.5% 58 / 62 CC 14 SCAR 10.4
CC
14
Cov
94%
_HASH
4.0
_UNDEF
3.6
_SCALAR
3.0
CRAP 2.8
« Perlish/Smatch.pm ↑ Summary Perlish/Smatch/Array.pm »
1 package Switch::Perlish::Smatch::Hash;
2  
3 11 $VERSION = '1.0.0';
4  
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Switch::Perlish::Smatch 'smatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ## Provide a wrapper sub to test against values?
11 ## DESC - Check if $m exists as a key in %$t.
12 3 ▶sub _VALUE {
Subroutine _VALUE: called CC=1 SCAR=0.0
13 3 my($t, $m) = @_;
14 3 return exists $t->{$m};
15 }
16  
17 ## DESC - Check for an undefined value in %$t (better suggestions welcome).
18 1 ▶sub _UNDEF {
Subroutine _UNDEF: called CC=3 SCAR=12.7
19 1 my($t, $m) = @_;
20 !defined and return 1
21 1 ▶ for values %$t;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or return 1 0 1 1
22 0 return;
23 }
24  
25 ## DESC - Check if $m points to value in %$t.
26 2 ▶sub _SCALAR {
Subroutine _SCALAR: called CC=3 SCAR=11.0
27 2 my($t, $m) = @_;
28 \$_ == $m and return 1
29 2 ▶ for values %$t;
Branch: 1 branch
BranchTrueFalseTotal
\$_ == $m and return 1 1 1 2
30 1 return;
31 }
32  
33 ## DESC - Check if an element of @$m exists as a key of %$t.
34 2 ▶sub _ARRAY {
Subroutine _ARRAY: called CC=3 SCAR=11.0
35 2 my($t, $m) = @_;
36 exists $t->{$_} and return 1
37 2 ▶ for @$m;
Branch: 1 branch
BranchTrueFalseTotal
exists $t->{$_} and return 1 1 5 6
38 1 return;
39 }
40  
41 ## DESC - Check if a key =E<gt> value pair exists in both %$t and %$m.
42 4 ▶sub _HASH {
Subroutine _HASH: called CC=4 SCAR=13.9
43 4 my($t, $m) = @_;
44 exists $t->{$_} and smatch($t->{$_}, $m->{$_}) and return 1
45 4 ▶ for keys %$m;
Branch: 1 branch
BranchTrueFalseTotal
exists $t->{$_} and smatch($t->{$_}, $m->{$_}) and return 1 2 4 6
Condition66%2/3
exists $t->{$_} and smatch($t->{$_}, $m->{$_})
!ll&&!rl&&r
402
MC/DC50%1/2
exists $t->{$_} and smatch($t->{$_}, $m->{$_})
exists $t->{$_} smatch($t->{$_}, $m->{$_})
Truth table66%2/3
A and B
A= exists $t->{$_}B= smatch($t->{$_}, $m->{$_})
ABresult
0X0
100
111
46 2 return;
47 }
48  
49 ## DESC - Check if the return from &$m is a hash key of %$t.
50 2 ▶sub _CODE {
Subroutine _CODE: called CC=1 SCAR=0.0
51 2 my($t, $m) = @_;
52 2 return exists $t->{$m->()};
53 }
54  
55 ## DESC - Check if a key of %$t exists as a method of $m.
56 2 ▶sub _OBJECT {
Subroutine _OBJECT: called CC=3 SCAR=11.0
57 2 my($t, $m) = @_;
58 $m->can($_) and return 1
59 2 ▶ for keys %$t;
Branch: 1 branch
BranchTrueFalseTotal
$m->can($_) and return 1 1 3 4
60 1 return;
61 }
62  
63 ## DESC - Check if any keys from %$t match $m.
64 2 ▶sub _Regexp {
Subroutine _Regexp: called CC=3 SCAR=11.0
65 2 my($t, $m) = @_;
66 /$m/ and return 1
67 2 ▶ for keys %$t;
Branch: 1 branch
BranchTrueFalseTotal
/$m/ and return 1 1 2 3
68 1 return;
69 }
70  
71 11 Switch::Perlish::Smatch->register_package( __PACKAGE__, 'HASH' );
72  
73 11 1;
74  
75 =pod
76  
77 =head1 NAME
78  
79 Switch::Perlish::Smatch::Hash - The C<HASH> 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<HASH> comparator
88 category. For more information on the comparator implementation see.
89 L<Switch::Perlish::Smatch::Comparators/"Hash">.
90  
91 =head1 SEE. ALSO
92  
93 L<Switch::Perlish::Smatch>
94  
95 L<Switch::Perlish::Smatch::Comparators>
96  
97 =head1 AUTHOR
98  
99 Dan Brook C<< <mr.daniel.brook@gmail.com> >>
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
« Perlish/Smatch.pm ↑ Summary Perlish/Smatch/Array.pm »