blib/lib/Class/ISA.pm

filter: Statementstmt 90.2% 37 / 41 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 77.3% 58 / 75 CC 10 SCAR 15.8
CC
10
Cov
77%
self_and_super_path
8.4
self_and_super_versions
3.2
super_path
2.0
CRAP 4.9
↑ Summary
1 package Class::ISA;
2 2 require 5;
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw($Debug $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $VERSION = '0.36';
6 2 ▶$Debug = 0 unless defined $Debug;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Class::ISA::Debug 2 0 2
7  
8 2 ▶use if $] >= 5.011, 'deprecate';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ###########################################################################
11  
12 0 ▶sub self_and_super_versions {
Subroutine self_and_super_versions: not called CC=2 SCAR=11.6
Pod documented
13 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 map {
15 0 ▶ $_ => (defined(${"$_\::VERSION"}) ? ${"$_\::VERSION"} : undef)
Branch: 1 branch
BranchTrueFalseTotal
defined ${"${_}::VERSION";} ? : 0 0 0
16 } self_and_super_path($_[0])
17 }
18  
19 # Also consider magic like:
20 # no strict 'refs';
21 # my %class2SomeHashr =
22 # map { defined(%{"$_\::SomeHash"}) ? ($_ => \%{"$_\::SomeHash"}) : () }
23 # Class::ISA::self_and_super_path($class);
24 # to get a hash of refs to all the defined (and non-empty) hashes in
25 # $class and its superclasses.
26 #
27 # Or even consider this incantation for doing something like hash-data
28 # inheritance:
29 # no strict 'refs';
30 # %union_hash =
31 # map { defined(%{"$_\::SomeHash"}) ? %{"$_\::SomeHash"}) : () }
32 # reverse(Class::ISA::self_and_super_path($class));
33 # Consider that reverse() is necessary because with
34 # %foo = ('a', 'wun', 'b', 'tiw', 'a', 'foist');
35 # $foo{'a'} is 'foist', not 'wun'.
36  
37 ###########################################################################
38 1 ▶sub super_path {
Subroutine super_path: called CC=2 SCAR=7.1
Pod documented
39 1 my @ret = &self_and_super_path(@_);
40 1 ▶ shift @ret if @ret;
Branch: 1 branch
BranchTrueFalseTotal
if @ret 1 0 1
41 1 return @ret;
42 }
43  
44 #--------------------------------------------------------------------------
45 1 ▶sub self_and_super_path {
Subroutine self_and_super_path: called CC=8 SCAR=21.3
Pod documented
46 # Assumption: searching is depth-first.
47 # Assumption: '' (empty string) can't be a class package name.
48 # Note: 'UNIVERSAL' is not given any special treatment.
49 1 ▶ return () unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
50  
51 1 my @out = ();
52  
53 1 my @in_stack = ($_[0]);
54 1 my %seen = ($_[0] => 1);
55  
56 1 my $current;
57 1 ▶ while(@in_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@in_stack) 7 1 8
58 7 ▶ next unless defined($current = shift @in_stack) && length($current);
Branch: 1 branch
BranchTrueFalseTotal
unless defined($current = shift @in_stack) and length $current 0 7 7
Condition33%1/3
defined($current = shift @in_stack) and length $current
!ll&&!rl&&r
007
MC/DC0%0/2
defined($current = shift @in_stack) and length $current
defined($current = shift @in_stack) length $current
Truth table33%1/3
A and B
A= defined($current = shift @in_stack)B= length $current
ABresult
0X0
100
111
59 7 ▶ print "At $current\n" if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::ISA::Debug 0 7 7
60 7 push @out, $current;
61 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
62 unshift @in_stack,
63 map
64 8 { my $c = $_; # copy, to avoid being destructive
65 8 ▶ substr($c,0,2) = "main::" if substr($c,0,2) eq '::';
Branch: 1 branch
BranchTrueFalseTotal
if substr($c, 0, 2) eq "::" 0 8 8
66 # Canonize the :: -> main::, ::foo -> main::foo thing.
67 # Should I ever canonize the Foo'Bar = Foo::Bar thing?
68 8 ▶ $seen{$c}++ ? () : $c;
Branch: 1 branch
BranchTrueFalseTotal
$seen{$c}++ ? : 2 6 8
69 }
70 7 @{"$current\::ISA"}
71 ;
72 # I.e., if this class has any parents (at least, ones I've never seen
73 # before), push them, in order, onto the stack of classes I need to
74 # explore.
75 }
76  
77 1 return @out;
78 }
79 #--------------------------------------------------------------------------
80 2 1;
81  
82 __END__
↑ Summary