Elive/DAO/_Base.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 70.0% 7 / 10 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 11 / 11 Podpod 25.0% 1 / 4 totaltotal 88.4% 69 / 78 CC 8 SCAR 7.9
CC
8
Cov
92%
debug
3.5
__ANON__
3.0
connection
3.0
CRAP 2.2
« Elive.pm ↑ Summary Elive/Entity/Role.pm »
1 package Elive::DAO::_Base;
2 37 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 37 ▶use parent qw{Class::Data::Inheritable};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Elive::DAO::_Base - Base class for DAO objects
9  
10 =cut
11  
12 37 our $DEBUG;
13 BEGIN {
14 37 ▶ $DEBUG = $ENV{ELIVE_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
15 }
16  
17 sub debug {
18 3301 ▶ my ($class, $level) = @_;
Subroutine debug: called CC=3 SCAR=12.5
Pod undocumented
19  
20 3301 ▶ if (defined $level) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) 0 3301 3301
21 0 $DEBUG = $level;
22 }
23  
24 3301 ▶ return $DEBUG || 0;
Condition50%1/2
$Elive::DAO::_Base::DEBUG || 0
l!l
03301
MC/DC0%0/1
$Elive::DAO::_Base::DEBUG || 0
$Elive::DAO::_Base::DEBUG
Truth table50%1/2
A
A= $Elive::DAO::_Base::DEBUG
Aresult
11
00
25 }
26  
27 sub _refaddr {
28 4604 ▶ my $self = shift;
Subroutine _refaddr: called CC=1 SCAR=0.0
29 4604 return Scalar::Util::refaddr( $self );
30 }
31  
32 37 our %Meta_Data;
33  
34 #
35 # create metadata properties. NB this will be stored inside out to
36 # ensure our object is an exact image of the data.
37 #
38  
39 =head2 has_metadata
40  
41 Associate an inside-out property with objects of a given class.
42  
43 =cut
44  
45 sub has_metadata {
46  
47 175 ▶ my $class = shift;
Subroutine has_metadata: called CC=2 SCAR=6.9
Pod documented
48 175 my $accessor = shift;
49  
50 175 my $accessor_fun = $class->can($accessor);
51  
52 175 ▶ unless ($accessor_fun) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($accessor_fun) 175 0 175
53  
54 37 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 $accessor_fun = sub {
57 3311 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
58 3311 ▶ my $ref = $self->_refaddr
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $self->_refaddr or return 0 3311 3311
59 or return;
60  
61 3311 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1206 2105 3311
62 1206 $Meta_Data{ $ref }{ $accessor } = $_[0];
63 }
64  
65 3311 return $Meta_Data{ $ref }{ $accessor };
66 175 };
67  
68 175 *{$class.'::'.$accessor} = $accessor_fun;
69 }
70  
71 175 return $accessor_fun;
72 }
73  
74 37 __PACKAGE__->mk_classdata('_connection');
75 37 __PACKAGE__->has_metadata('_object_connection');
76  
77 sub connection {
78 576 ▶ my $self = shift;
Subroutine connection: called CC=3 SCAR=11.0
Pod undocumented
79 576 my $connection;
80 576 ▶ $connection = $self->_object_connection(@_)
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 435 141 576
81 if ref $self;
82 576 ▶ $connection ||= $self->_connection(@_);
Condition100%3/3
$connection ||= $self->_connection(@_)
l!l&&r!l&&!r
43512318
MC/DC100%2/2
$connection ||= $self->_connection(@_)
$connection $self->_connection(@_)
Truth table100%3/3
A ||= B
A= $connectionB= $self->_connection(@_)
ABresult
1X1
011
000
83 576 return $connection;
84 }
85  
86 sub DEMOLISH {
87 1272 ▶ my $self = shift;
Subroutine DEMOLISH: called CC=1 SCAR=0.0
Pod undocumented
88 1272 delete $Meta_Data{ $self->_refaddr };
89 1272 return;
90 }
91  
92 37 1;
« Elive.pm ↑ Summary Elive/Entity/Role.pm »