blib/lib/Class/Data/ConfigHash.pm

filter: Statementstmt 92.6% 38 / 41 Branchbran 75.0% 9 / 12 Conditioncond 71.4% 10 / 14 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 81.7% 67 / 82 CC 14 SCAR 19.9
CC
14
Cov
85%
__merge_hashes
11.0
config
6.0
BEGIN
1.0
CRAP 7.3
↑ Summary
1 # $Id: /mirror/coderepos/lang/perl/Class-Data-ConfigHash/trunk/lib/Class/Data/ConfigHash.pm 69719 2008-08-27T02:20:26.319462Z daisuke $
2  
3 package Class::Data::ConfigHash;
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw(Class::Data::Inheritable);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our $VERSION = '0.00002';
8  
9 2 __PACKAGE__->mk_classdata(_config => {});
10  
11 16 ▶sub config {
Subroutine config: called CC=6 SCAR=17.9
Pod documented
12 16 my $self = shift;
13 16 my $config_sub = $self->can('_config');
14 16 ▶ my $config = $self->$config_sub() || {};
Condition50%1/2
$self->$config_sub || {}
l!l
160
MC/DC0%0/1
$self->$config_sub || {}
$self->$config_sub
Truth table50%1/2
A
A= $self->$config_sub
Aresult
11
00
15 16 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 11 16
16 5 ▶ my $newconfig = { %{@_ > 1 ? {@_} : ($_[0] || {})} };
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 3 2 5
Condition100%2/2
$_[0] or {}
l!l
11
MC/DC100%1/1
$_[0] or {}
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
17 5 $self->_config(
18 $self->merge_config_hashes( $config, $newconfig )
19 );
20 } else {
21 # this is a bit of a kludge, required to make
22 # __PACKAGE__->config->{foo} = 'bar';
23 # work in a subclass. Calling the Class::Data::Inheritable setter
24 # will create a new _config method in the current class if it's
25 # currently inherited from the superclass. So, the can() call will
26 # return a different subref in that case and that means we know to
27 # copy and reset the value stored in the class data.
28  
29 11 $self->_config( $config );
30  
31 11 ▶ if ((my $config_sub_now = $self->can('_config')) ne $config_sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $config_sub_now = $self->can("_config")) ne $config_sub) 1 10 11
32
33 1 $config = $self->merge_config_hashes( $config, {} );
34 1 $self->$config_sub_now( $config );
35 }
36 }
37 16 return $config;
38 }
39  
40 sub merge_config_hashes
41 6 ▶{
Subroutine merge_config_hashes: called CC=1 SCAR=0.0
Pod documented
42 6 my ($self, $lefthash, $righthash) = @_;
43 6 return __merge_hashes($lefthash, $righthash);
44 }
45  
46 sub __merge_hashes
47 6 ▶{
Subroutine __merge_hashes: called CC=9 SCAR=24.0
48 # XXX - If Catalyst is in effect, we might just as well use
49 # Catalyst::Utils::merge_hashes, I suppose.
50 6 my ( $lefthash, $righthash ) = @_;
51  
52 6 ▶ if ( !defined $righthash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $righthash) 0 6 6
53 0 return $lefthash;
54 }
55  
56 6 ▶ if ( !defined $lefthash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lefthash) 0 6 6
57 0 return $righthash;
58 }
59  
60 6 my %merged = %{$lefthash};
61 6 for my $key ( keys %{$righthash} ) {
62 6 ▶ my $right_ref = ( ref $righthash->{$key} || '' ) eq 'HASH';
Condition100%2/2
ref $righthash->{$key} || ''
l!l
15
MC/DC100%1/1
ref $righthash->{$key} || ''
ref $righthash->{$key}
Truth table100%2/2
A
A= ref $righthash->{$key}
Aresult
11
00
63 my $left_ref =
64 6 ▶ ( ( exists $lefthash->{$key} && ref $lefthash->{$key} ) || '' ) eq
Condition60%3/5
exists $lefthash->{$key} && ref $lefthash->{$key} || ''
l!l
06
exists $lefthash->{$key} and ref $lefthash->{$key}
!ll&&!rl&&r
240
MC/DC0%0/2
exists $lefthash->{$key} && ref $lefthash->{$key} || ''
exists $lefthash->{$key} ref $lefthash->{$key}
Truth table66%2/3
A and B
A= exists $lefthash->{$key}B= ref $lefthash->{$key}
ABresult
111
0X0
100
65 'HASH';
66 6 ▶ if ( $right_ref and $left_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right_ref and $left_ref) { } 0 6 6
Condition66%2/3
$right_ref and $left_ref
!ll&&!rl&&r
510
MC/DC0%0/2
$right_ref and $left_ref
$right_ref $left_ref
Truth table66%2/3
A and B
A= $right_refB= $left_ref
ABresult
0X0
100
111
67 $merged{$key} =
68 0 __merge_hashes( $lefthash->{$key}, $righthash->{$key} );
69 }
70 else {
71 6 $merged{$key} = $righthash->{$key};
72 }
73 }
74
75 6 return \%merged;
76 }
77  
78 2 1;
79  
80 __END__
↑ Summary