Perlish/Smatch/Object.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 1 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 92.1% 47 / 51 CC 3 SCAR 2.5
CC
3
Cov
94%
do_delegation
2.1
_OBJECT
2.0
BEGIN
1.0
CRAP 1.3
« Perlish/Smatch/Value.pm ↑ Summary Perlish/Smatch/Code.pm »
1 package Switch::Perlish::Smatch::Object;
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 Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ## DESC - Check if $t has $m as a method.
12 2 ▶sub _VALUE {
Subroutine _VALUE: called CC=1 SCAR=0.0
13 2 my($t, $m) = @_;
14 2 return $t->can($m);
15 }
16  
17 ## DESC - croak("Can't compare OBJECT with an undef") # Suggestions welcome.
18 1 ▶sub _UNDEF {
Subroutine _UNDEF: called CC=1 SCAR=0.0
19 1 croak("Can't compare OBJECT with an undef");
20 }
21  
22 ## DESC - Check if the $m points to the $t.
23 2 ▶sub _SCALAR {
Subroutine _SCALAR: called CC=1 SCAR=0.0
24 2 my($t, $m) = @_;
25 2 return $t == $$m;
26 }
27  
28 ## Just delegate back to the blessed type - This is a quite horrible
29 ## way to compare because it breaks encapsulation, but these are default cmps.
30 4 ▶sub do_delegation {
Subroutine do_delegation: called CC=2 SCAR=7.2
Pod undocumented
31 4 my($t, $m, $type) = @_;
32 4 ▶ return ( reftype($t) eq $type ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($t) eq $type ? : 4 0 4
33 Switch::Perlish::Smatch->dispatch($type => $type => $t, $m)
34 :
35 () );
36 }
37  
38 ## DESC - If the $t is a blessed ARRAY, delegate to the C<< ARRAY<=>ARRAY >> comparator.
39 2 ▶sub _ARRAY { do_delegation @_, 'ARRAY' }
Subroutine _ARRAY: called CC=1 SCAR=0.0
40  
41 ## DESC - If the $t is a blessed HASH, delegate to the C<< HASH<=>HASH >> comparator.
42 2 ▶sub _HASH { do_delegation @_, 'HASH' }
Subroutine _HASH: called CC=1 SCAR=0.0
43  
44 ## DESC - Call the $t on &$m i.e C<< $t->$m >>.
45 2 ▶sub _CODE {
Subroutine _CODE: called CC=1 SCAR=0.0
46 2 my($t, $m) = @_;
47 2 return $t->$m;
48 }
49  
50 ## DESC - Check if the $t->isa($m) or the same class (better suggestions welcome).
51 2 ▶sub _OBJECT {
Subroutine _OBJECT: called CC=2 SCAR=7.1
52 2 my($t, $m) = @_;
53 2 ▶ return( ref($t) eq ref($m) or $t->isa($m) );
Condition66%2/3
ref $t eq ref $m || $t->isa($m)
l!l&&r!l&&!r
101
MC/DC50%1/2
ref $t eq ref $m || $t->isa($m)
ref $t eq ref $m $t->isa($m)
Truth table66%2/3
A || B
A= ref $t eq ref $mB= $t->isa($m)
ABresult
1X1
011
000
54 }
55  
56 ## DESC - Match the class of $t against the $m.
57 2 ▶sub _Regexp {
Subroutine _Regexp: called CC=1 SCAR=0.0
58 2 my($t, $m) = @_;
59 2 return ref($t) =~ /$m/;
60 }
61  
62 11 Switch::Perlish::Smatch->register_package( __PACKAGE__, 'OBJECT' );
63  
64 11 1;
65  
66 =pod
67  
68 =head1 NAME
69  
70 Switch::Perlish::Smatch::Object - The C<OBJECT> comparatory category package.
71  
72 =head1 VERSION
73  
74 1.0.0 - Initial release.
75  
76 =head1 DESCRIPTION
77  
78 This package provides the default implementation for the C<OBJECT> comparator
79 category. For more information on the comparator implementation see.
80 L<Switch::Perlish::Smatch::Comparators/"Object">.
81  
82 =head1 SEE. ALSO
83  
84 L<Switch::Perlish::Smatch>
85  
86 L<Switch::Perlish::Smatch::Comparators>
87  
88 =head1 AUTHOR
89  
90 Dan Brook C<< <mr.daniel.brook@gmail.com> >>
91  
92 =head1 COPYRIGHT
93  
94 Copyright (c) 2006, Dan Brook. All Rights Reserved. This module is free
95 software. It may be used, redistributed and/or modified under the same
96 terms as Perl itself.
97  
98 =cut
« Perlish/Smatch/Value.pm ↑ Summary Perlish/Smatch/Code.pm »