blib/lib/Kelp/Base.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 92.8% 13 / 14 Conditioncond 77.7% 7 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 90.0% 90 / 100 CC 11 SCAR 11.0
CC
11
Cov
95%
import
5.0
__ANON__
5.0
attr
3.0
CRAP 3.0
« blib/lib/Kelp/Test/CookieJar.pm ↑ Summary blib/lib/Kelp/Test.pm »
1 package Kelp::Base;
2  
3 58 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 58 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 58 ▶use feature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 58 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 58 require namespace::autoclean;
9 58 require Kelp::Util;
10  
11 sub import
12 923 ▶{
Subroutine import: called CC=5 SCAR=16.1
13 923 my $class = shift;
14 923 my $caller = caller;
15  
16 # Do not import into inherited classes
17 923 ▶ return if $class ne __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $class ne __PACKAGE__ 177 746 923
18  
19 746 ▶ my $base = shift || $class;
Condition66%2/3
shift() || $class
l!l&&r!l&&!r
3743720
MC/DC0%0/2
shift() || $class
shift() $class
Truth table66%2/3
A || B
A= shift()B= $class
ABresult
1X1
011
000
20  
21 746 ▶ if ($base ne '-strict') {
Branch: 1 branch
BranchTrueFalseTotal
if ($base ne "-strict") 659 87 746
22 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 58 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 659 ▶ if ($base ne '-attr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($base ne "-attr") 658 1 659
26 658 Kelp::Util::load_package($base);
27 658 push @{"${caller}::ISA"}, $base;
28 }
29  
30 659 ▶ *{"${caller}::attr"} = sub { attr($caller, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32 659 namespace::autoclean->import(
33 -cleanee => $caller
34 );
35 }
36  
37 746 strict->import;
38 746 warnings->import;
39 746 feature->import(':5.10');
40 }
41  
42 sub new
43 1304 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
44 1304 my $self = shift;
45 1304 return bless {@_}, $self;
46 }
47  
48 sub attr
49 2843 ▶{
Subroutine attr: called CC=3 SCAR=11.0
Pod undocumented
50 2843 my ($class, $name, $default) = @_;
51  
52 2843 ▶ if (ref $default && ref $default ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $default and ref $default ne "CODE") 0 2843 2843
Condition66%2/3
ref $default and ref $default ne "CODE"
!ll&&!rl&&r
120616370
MC/DC0%0/2
ref $default and ref $default ne "CODE"
ref $default ref $default ne "CODE"
Truth table66%2/3
A and B
A= ref $defaultB= ref $default ne "CODE"
ABresult
0X0
100
111
53 0 croak "Default value for '$name' can not be a reference.";
54 }
55  
56 # Readonly attributes are marked with '-'
57 2843 my $readonly = $name =~ s/^\-//;
58  
59 # Remember if default is a function
60 2843 my $default_sub = ref $default eq 'CODE';
61  
62 {
63 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 58 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 2843 ▶ *{"${class}::$name"} = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
67 31666 ▶ return $_[0]->{$name} = $_[1] if @_ > 1 && !$readonly;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and not $readonly 4016 27650 31666
Condition100%3/3
@_ > 1 and not $readonly
!ll&&!rl&&r
2764824016
MC/DC100%2/2
@_ > 1 and not $readonly
@_ > 1 not $readonly
Truth table100%3/3
A and not(B)
A= @_ > 1B= not $readonly
ABresult
0X0
100
111
68 27650 ▶ return $_[0]->{$name} if exists $_[0]->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_[0]{$name} 24274 3376 27650
69 3376 ▶ return $_[0]->{$name} = $default_sub ? $default->($_[0]) : $default;
Branch: 1 branch
BranchTrueFalseTotal
$default_sub ? : 1773 1603 3376
70 2843 };
71 }
72 }
73  
74 58 1;
75  
76 __END__
« blib/lib/Kelp/Test/CookieJar.pm ↑ Summary blib/lib/Kelp/Test.pm »