lib/Badger/Prototype.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 55.5% 5 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 85.4% 53 / 62 CC 7 SCAR 12.4
CC
7
Cov
91%
prototype
6.0
has_prototype
2.0
BEGIN
1.0
CRAP 3.5
« lib/Badger/Log.pm ↑ Summary lib/Badger/Codec/Chain.pm »
1 #========================================================================
2 #
3 # Badger::Prototype
4 #
5 # DESCRIPTION
6 # Base class module for a protoype class that has a default instance
7 # that can be created on demand.
8 #
9 # AUTHOR
10 # Andy Wardley <abw@wardley.org>
11 #
12 #========================================================================
13  
14 package Badger::Prototype;
15  
16 use Badger::Class
17 70 base => 'Badger::Base',
18 version => 0.01,
19 debug => 0,
20 constants => 'PKG REFS ONCE',
21 70 ▶ words => 'PROTOTYPE';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 sub prototype {
24 6022 ▶ my $class = shift;
Subroutine prototype: called CC=6 SCAR=17.9
Pod documented
25 6022 ▶ return $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 4095 1927 6022
26 70 ▶ no strict REFS;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 70 ▶ no warnings ONCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
28
29 1927 ▶ if (@_ == 1 && ! defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and not defined $_[0]) { } 1 1926 1927
elsif (@_) { } 1 1925 1926
Condition66%2/3
@_ == 1 and not defined $_[0]
!ll&&!rl&&r
192601
MC/DC50%1/2
@_ == 1 and not defined $_[0]
@_ == 1 not defined $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not defined $_[0]
ABresult
0X0
100
111
30 # if only a single undef argument is provided, then clear any
31 # prototype from $PROTOTYPE and return a reference to it.
32 1 my $proto = ${$class.PKG.PROTOTYPE};
33 1 undef ${$class.PKG.PROTOTYPE};
34 1 return $proto;
35 }
36 elsif (@_) {
37 # if any other arguments are provided then it forces us to create
38 # a new prototype with the fresh configuration options.
39 1 undef ${$class.PKG.PROTOTYPE};
40 }
41
42 # return the cached value (assuming we didn't just clear it) or create
43 # a new one (if we did, or if there wasn't a previous value)
44 1926 ▶ return ${$class.PKG.PROTOTYPE} ||= $class->new(@_);
Condition66%2/3
${$class . '::' . "PROTOTYPE";} ||= $class->new(@_)
l!l&&r!l&&!r
18111150
MC/DC0%0/2
${$class . '::' . "PROTOTYPE";} ||= $class->new(@_)
${$class . '::' . "PROTOTYPE";} $class->new(@_)
Truth table66%2/3
A ||= B
A= ${$class . '::' . "PROTOTYPE";}B= $class->new(@_)
ABresult
1X1
011
000
45 }
46  
47 sub has_prototype {
48 2 ▶ my $self = shift;
Subroutine has_prototype: called CC=2 SCAR=7.0
Pod documented
49 2 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
50 70 ▶ no strict REFS;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 70 ▶ no warnings ONCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 defined ${$class.PKG.PROTOTYPE};
53 }
54
55  
56 70 1;
57  
58 __END__
« lib/Badger/Log.pm ↑ Summary lib/Badger/Codec/Chain.pm »