t/Mbase_derived_main.pl

filter: Statementstmt 100% 48 / 48 Branchbran n/a Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 89.1% 66 / 74 CC 3 SCAR 2.4
CC
3
Cov
93%
new
2.3
new
2.1
BEGIN
1.0
CRAP 1.3
« lib/Package/Data/Inheritable.pm ↑ Summary
1 #!perl
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use lib qw( t t/lib ./lib ../lib );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Base;
8 2 ▶use base qw( Package::Data::Inheritable );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 Base->pkg_inheritable('$staticData1' => 1); # overidden in Derived
11 2 Base->pkg_inheritable('$staticData2' => 2); # untouched in Derived
12 2 Base->pkg_inheritable('$staticData3' => 3); # reassigned in Derived
13 }
14  
15 4 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
16 4 ▶ my $class = ref $_[0] || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
17  
18 4 bless {
19 instanceData1 => 1,
20 }, $class;
21 }
22  
23 4 ▶sub staticMethodA {
Subroutine staticMethodA: called CC=1 SCAR=0.0
24 4 print "- staticMethodA\n";
25 }
26  
27 2 ▶sub staticMethodB {
Subroutine staticMethodB: called CC=1 SCAR=0.0
28 2 print "- Base staticMethodB $staticData1\n";
29 }
30  
31 4 ▶sub staticDump {
Subroutine staticDump: called CC=1 SCAR=0.0
32 4 print "Base.staticDump()\n",
33 "\tstaticData1: $staticData1\n",
34 "\tstaticData2: $staticData2\n",
35 "\tstaticData3: $staticData3\n";
36 }
37 4 ▶sub instanceDump {
Subroutine instanceDump: called CC=1 SCAR=0.0
38 4 my $self = shift;
39 4 print "Base.instanceDump() ", ref $self, "\n",
40 "\tstaticData1: $staticData1\n",
41 "\tinstanceData1: $self->{instanceData1}\n";
42 }
43  
44  
45 ########################################
46 package Derived;
47 2 ▶use base qw( Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 inherit Base;
50  
51 2 Derived->pkg_inheritable('$staticData1' => '111');
52 };
53 2 $staticData3 = "333";
54  
55 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
56 2 ▶ my $class = ref $_[0] || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
57  
58 bless {
59 2 %{ $class->SUPER::new(@_) },
60 instanceData2 => "222",
61 }, $class;
62 }
63  
64  
65 2 ▶sub staticMethodB {
Subroutine staticMethodB: called CC=1 SCAR=0.0
66 2 print "- Derived staticMethodB $staticData1\n";
67 }
68  
69 2 ▶sub staticDumpB {
Subroutine staticDumpB: called CC=1 SCAR=0.0
70 2 print "Derived.staticDumpB()\n",
71 "\tstaticData1: $staticData1\n",
72 "\tstaticData2: $staticData2\n",
73 "\tstaticData3: $staticData3\n";
74 }
75 2 ▶sub instanceDumpB {
Subroutine instanceDumpB: called CC=1 SCAR=0.0
76 2 my $self = shift;
77 2 print "Derived.instanceDumpB() ", ref($self), "\n",
78 "\tstaticData1: $staticData1\n";
79 }
80  
81 ########################################
82 2 my $base = Base->new();
83 2 my $derived = Derived->new();
84  
85 # static methods defined in a base class always see the base class data
86 # even when invoked on a derived class
87 2 $base->staticMethodA();
88 2 $derived->staticMethodA();
89 2 $base->staticMethodB();
90 2 $derived->staticMethodB();
91  
92 2 $base->staticDump();
93 2 $base->instanceDump();
94 2 $derived->staticDump();
95 2 print "\n";
96 # even *instance* methods defined in a base class see the base class data
97 # even when invoked on a derived class
98 # *furthermore*, they don't see the derived instance data either
99 2 $derived->instanceDump();
100  
101 2 $derived->staticDumpB();
102 2 $derived->instanceDumpB();
103  
« lib/Package/Data/Inheritable.pm ↑ Summary