blib/lib/perl5i/2/Meta.pm

filter: Statementstmt 71.5% 63 / 88 Branchbran 53.3% 16 / 30 Conditioncond 27.2% 3 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 8 totaltotal 61.2% 98 / 160 SCAR 38.8
CC
23
Cov
64%
methods
156.0
super
7.1
linear_isa
3.0
CRAP 48.6
« blib/lib/perl5i/2/DateTime.pm ↑ Summary blib/lib/perl5i/0/DateTime.pm »
1 package perl5i::2::Meta;
2  
3 109 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 109 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 109 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Be very careful not to import anything.
8 109 require Carp::Fix::1_25;
9 109 require mro;
10  
11 109 require perl5i::2::Meta::Instance;
12 109 require perl5i::2::Meta::Class;
13 109 ▶use perl5i::2::autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub UNIVERSAL::mo {
16 # Be careful to pass through an alias, not a copy
17 210 ▶ return perl5i::2::Meta::Instance->new($_[0]);
Subroutine mo: called CC=1 SCAR=0.0
Pod undocumented
18 }
19  
20 sub UNIVERSAL::mc {
21 30 ▶ return perl5i::2::Meta::Class->new($_[0]);
Subroutine mc: called CC=1 SCAR=0.0
Pod undocumented
22 }
23  
24 sub new {
25 240 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
26 # Be careful to take a reference to an alias, not a copy
27 240 return bless \\$_[0], $class;
28 }
29  
30 sub ISA {
31 6 ▶ my $class = $_[0]->class;
Subroutine ISA: called CC=2 SCAR=6.9
Pod undocumented
32  
33 109 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶ return wantarray ? @{$class.'::ISA'} : \@{$class.'::ISA'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 1 6
35 }
36  
37 sub linear_isa {
38 13 ▶ my $self = shift;
Subroutine linear_isa: called CC=3 SCAR=11.0
Pod undocumented
39 13 my $class = $self->class;
40  
41 # get_linear_isa() does not return UNIVERSAL
42 13 my @extra;
43 13 ▶ @extra = qw(UNIVERSAL) unless $class eq 'UNIVERSAL';
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "UNIVERSAL" 12 1 13
44  
45 13 my $isa = [@{mro::get_linear_isa($class)}, @extra];
46 13 ▶ return wantarray ? @$isa : $isa;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 1 13
47 }
48  
49 sub methods {
50 0 ▶ my $self = shift;
Subroutine methods: not called CC=12 SCAR=50.5
Pod undocumented
51 0 ▶ my $opts = shift // {};
Condition0%0/2
shift() // {}
l!l
00
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
52 0 my $top = $self->class;
53  
54 0 my %exclude;
55  
56 0 state $defaults = {
57 with_UNIVERSAL => 0,
58 just_mine => 0,
59 };
60  
61 0 $opts = { %$defaults, %$opts };
62 0 $exclude{UNIVERSAL} = !$opts->{with_UNIVERSAL};
63  
64 0 ▶ my @classes = $opts->{just_mine} ? $self->class : $self->linear_isa;
Branch: 1 branch
BranchTrueFalseTotal
$$opts{'just_mine'} ? : 0 0 0
65  
66 0 my %all_methods;
67 0 for my $class (@classes) {
68 0 ▶ next if $exclude{$class} && $class ne $top;
Branch: 1 branch
BranchTrueFalseTotal
if $exclude{$class} and $class ne $top 0 0 0
Condition0%0/3
$exclude{$class} and $class ne $top
!ll&&!rl&&r
000
MC/DC0%0/2
$exclude{$class} and $class ne $top
$exclude{$class} $class ne $top
Truth table0%0/3
A and B
A= $exclude{$class}B= $class ne $top
ABresult
0X0
100
111
69  
70 0 my $sym_table = $class->mc->symbol_table;
71 0 for my $name (keys %$sym_table) {
72 0 my $glob = $sym_table->{$name};
73 0 ▶ next unless ref \$glob eq "GLOB";
Branch: 1 branch
BranchTrueFalseTotal
unless ref \$glob eq "GLOB" 0 0 0
74 0 ▶ next unless my $code = *{$glob}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
unless my $code = *{$glob;}{"CODE"} 0 0 0
75 0 my $sig = $code->signature;
76 0 ▶ next if $sig and !$sig->is_method;
Branch: 1 branch
BranchTrueFalseTotal
if $sig and not $sig->is_method 0 0 0
Condition0%0/3
$sig and not $sig->is_method
!ll&&!rl&&r
000
MC/DC0%0/2
$sig and not $sig->is_method
$sig not $sig->is_method
Truth table0%0/3
A and not(B)
A= $sigB= not $sig->is_method
ABresult
0X0
100
111
77 0 $all_methods{$name} = $class;
78 }
79 }
80  
81 0 ▶ return wantarray ? keys %all_methods : [keys %all_methods];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
82 }
83  
84 sub symbol_table {
85 1 ▶ my $self = shift;
Subroutine symbol_table: called CC=1 SCAR=0.0
Pod undocumented
86 1 my $class = $self->class;
87  
88 109 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
89 1 return \%{$class.'::'};
90 }
91  
92 # A single place to put the "method not found" error.
93 my $method_not_found = sub {
94 0 ▶ my $class = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 my $method = shift;
96  
97 0 Carp::Fix::1_25::croak(
98 sprintf q[Can't locate object method "%s" via package "%s"],
99 $method, $class
100 );
101 109 };
102  
103  
104 # caller() will return if its inside an eval, need to skip over those.
105 my $find_method = sub {
106 10 ▶ my $method;
Subroutine __ANON__: called CC=3 SCAR=11.0
107 10 my $height = 2;
108 10 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
(not defined $method or $method ne "(eval)") or do { do { $method = (caller $height)[3]; ++$height } } 3 10 13
Condition100%3/3
not defined $method or $method ne "(eval)"
l!l&&r!l&&!r
193
MC/DC100%2/2
not defined $method or $method ne "(eval)"
not defined $method $method ne "(eval)"
Truth table100%3/3
not(A) or B
A= not defined $methodB= $method ne "(eval)"
ABresult
1X1
011
000
109 13 $method = (caller($height))[3];
110 13 $height++;
111 } until( !defined $method or $method ne '(eval)' );
112  
113 10 return $method;
114 109 };
115  
116  
117 sub super {
118 10 ▶ my $self = shift;
Subroutine super: called CC=7 SCAR=19.6
Pod undocumented
119 10 my $class = $self->class;
120  
121 10 my $fq_method = $find_method->();
122 10 ▶ Carp::Fix::1_25::croak("super() called outside a method") unless $fq_method;
Branch: 1 branch
BranchTrueFalseTotal
unless $fq_method 1 9 10
123  
124 9 my($parent, $method) = $fq_method =~ /^(.*)::(\w+)$/;
125  
126 9 ▶ Carp::Fix::1_25::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa($parent) 1 8 9
127 sprintf qq["%s" is not a parent class of "%s"],
128 $parent, $class
129 ) unless $class->isa($parent);
130  
131 8 my @isa = $self->linear_isa();
132  
133 8 ▶ while(@isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (@isa) 12 0 12
134 12 my $class = shift @isa;
135 12 ▶ last if $class eq $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq $parent 8 4 12
136 }
137  
138 8 for (@isa) {
139 8 my $code = $_->can($method);
140 8 @_ = ($$$self, @_);
141 8 ▶ goto &$code if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 8 0 8
142 }
143  
144 0 $class->$method_not_found($method);
145 }
146  
147 109 1;
« blib/lib/perl5i/2/DateTime.pm ↑ Summary blib/lib/perl5i/0/DateTime.pm »