DB/Registry.pm

filter: Statementstmt 86.7% 72 / 83 Branchbran 65.2% 30 / 46 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 81.2% 13 / 16 Podpod 81.8% 9 / 11 totaltotal 72.4% 129 / 178 CC 32 SCAR 23.5
CC
32
Cov
75%
add_entries
21.1
add_entry
10.7
delete_entry
6.0
CRAP 10.4
« DB/Cache.pm ↑ Summary DB/Registry/Entry.pm »
1 package Rose::DB::Registry;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 17 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 ▶use Rose::DB::Registry::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶use Rose::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 our @ISA = qw(Rose::Object);
11  
12 17 our $VERSION = '0.728';
13  
14 17 our $Debug = 0;
15  
16 #
17 # Object data
18 #
19  
20 use Rose::Object::MakeMethods::Generic
21 17 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 17 'scalar' =>
23 [
24 qw(error)
25 ],
26  
27 'scalar --get_set_init' =>
28 [
29 'hash',
30 'parent',
31 ],
32 17 );
33  
34 #
35 # Object methods
36 #
37  
38 35 ▶sub init_hash { {} }
Subroutine init_hash: called CC=1 SCAR=0.0
Pod undocumented
39 0 ▶sub init_parent { 'Rose::DB' }
Subroutine init_parent: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 sub add_entries
42 228 ▶{
Subroutine add_entries: called CC=17 SCAR=30.5
Pod documented
43 228 my($self) = shift;
44  
45 # Smuggle parent in with an otherwise nonsensical arrayref arg
46 228 ▶ my $parent = shift->[0] if(ref $_[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 226 2 228
47 228 ▶ $parent ||= $self->parent;
Condition66%2/3
$parent ||= $self->parent
l!l&&r!l&&!r
22620
MC/DC0%0/2
$parent ||= $self->parent
$parent $self->parent
Truth table66%2/3
A ||= B
A= $parentB= $self->parent
ABresult
1X1
011
000
48  
49 228 my $entries = $self->hash;
50  
51 228 my @added;
52  
53 228 foreach my $item (@_)
54 {
55 228 my($domain, $type, $entry);
56  
57 228 ▶ if(ref $item eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'HASH') { } 228 0 228
elsif (ref $item and $item->isa('Rose::DB::Registry::Entry')) { } 0 0 0
58 {
59 228 ▶ if($entry = delete $item->{'entry'})
Branch: 1 branch
BranchTrueFalseTotal
if ($entry = delete $item->{'entry'}) { } 2 226 228
60 {
61 2 $domain = delete $item->{'domain'};
62 2 $type = delete $item->{'type'};
63  
64 2 ▶ if(keys(%$item))
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$item) 0 2 2
65 {
66 0 Carp::croak "If an 'entry' parameter is passed, no other ",
67 "parameters (other than 'domain' and 'type') ",
68 "may be passed";
69 }
70 }
71 else
72 {
73 226 $entry = Rose::DB::Registry::Entry->new(%$item);
74 }
75 }
76 ▶ elsif(ref $item && $item->isa('Rose::DB::Registry::Entry'))
Condition0%0/3
ref $item and $item->isa("Rose::DB::Registry::Entry")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $item and $item->isa("Rose::DB::Registry::Entry")
ref $item $item->isa("Rose::DB::Registry::Entry")
Truth table0%0/3
A and B
A= ref $itemB= $item->isa("Rose::DB::Registry::Entry")
ABresult
0X0
100
111
77 {
78 0 $entry = $item;
79 }
80 0 else { Carp::croak "Don't know how to add registry entry '$item'" }
81  
82 228 ▶ $domain = $entry->domain unless(defined $domain);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain 226 2 228
83 228 ▶ $type = $entry->type unless(defined $type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 226 2 228
84  
85 228 ▶ unless(defined $domain)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $domain) 4 224 228
86 {
87 4 $domain = $parent->default_domain;
88 4 $entry->domain($domain);
89 }
90  
91 228 ▶ unless(defined $type)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 4 224 228
92 {
93 4 $type = $parent->default_type;
94 4 $entry->type($type);
95 }
96  
97 228 ▶ Carp::confess "$parent - Missing domain for registry entry: domain '$domain', type '$type'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain 0 228 228
98 unless(defined $domain);
99  
100 228 ▶ Carp::confess "$parent - Missing type for registry entry: domain '$domain', type '$type'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 228 228
101 unless(defined $type);
102  
103 228 ▶ Carp::confess "$parent - Missing driver for registry entry: domain '$domain', type '$type'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->driver 0 228 228
104 unless(defined $entry->driver);
105  
106 228 $entries->{$domain}{$type} = $entry;
107 228 push(@added, $entry);
108 }
109  
110 228 ▶ return wantarray ? @added : \@added;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 228 0 228
111 }
112  
113 sub add_entry
114 228 ▶{
Subroutine add_entry: called CC=7 SCAR=23.7
Pod documented
115 228 my($self) = shift;
116  
117 # Smuggle parent in with an otherwise nonsensical arrayref arg
118 228 ▶ my $parent = shift if(ref $_[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 226 2 228
119  
120 228 ▶ if(@_ == 1 || (ref $_[0] && $_[0]->isa('Rose::DB::Registry::Entry')))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 or ref $_[0] and $_[0]->isa("Rose::DB::Registry::Entry")) 0 228 228
Condition33%2/6
@_ == 1 or ref $_[0] and $_[0]->isa("Rose::DB::Registry::Entry")
l!l&&r!l&&!r
00228
ref $_[0] and $_[0]->isa("Rose::DB::Registry::Entry")
!ll&&!rl&&r
22800
MC/DC0%0/3
@_ == 1 or ref $_[0] and $_[0]->isa("Rose::DB::Registry::Entry")
@_ == 1 ref $_[0] $_[0]->isa("Rose::DB::Registry::Entry")
Truth table25%1/4
A or B and C
A= @_ == 1B= ref $_[0]C= $_[0]->isa("Rose::DB::Registry::Entry")
ABCresult
1XX1
0111
00X0
0100
121 {
122 0 ▶ return ($self->add_entries(($parent ? $parent : ()), @_))[0];
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
123 }
124  
125 228 ▶ return ($self->add_entries(($parent ? $parent : ()), { @_ }))[0];
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 226 2 228
126 }
127  
128 sub entry_exists
129 28 ▶{
Subroutine entry_exists: called CC=3 SCAR=11.4
Pod documented
130 28 my($self, %args) = @_;
131  
132 Carp::croak "Missing required 'type' argument"
133 28 ▶ unless(defined $args{'type'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"type"} 0 28 28
134  
135 Carp::croak "Missing required 'domain' argument"
136 28 ▶ unless(defined $args{'domain'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"domain"} 0 28 28
137  
138 28 return exists $self->hash->{$args{'domain'}}{$args{'type'}};
139 }
140  
141 sub delete_entry
142 0 ▶{
Subroutine delete_entry: not called CC=2 SCAR=17.9
Pod documented
143 0 my($self, %args) = @_;
144 0 ▶ return undef unless($self->entry_exists(%args));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->entry_exists(%args) 0 0 0
145 0 return delete $self->hash->{$args{'domain'}}{$args{'type'}};
146 }
147  
148 sub entry
149 14 ▶{
Subroutine entry: called CC=2 SCAR=7.1
Pod documented
150 14 my($self, %args) = @_;
151 14 ▶ return undef unless($self->entry_exists(%args));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->entry_exists(%args) 0 14 14
152 14 return $self->hash->{$args{'domain'}}{$args{'type'}};
153 }
154  
155 sub delete_domain
156 0 ▶{
Subroutine delete_domain: not called CC=1 SCAR=6.9
Pod documented
157 0 my($self, $domain) = @_;
158 0 my $entries = $self->hash;
159 0 delete $entries->{$domain};
160 }
161  
162 sub registered_types
163 10 ▶{
Subroutine registered_types: called CC=3 SCAR=11.0
Pod documented
164 10 my($self, $domain) = @_;
165 10 ▶ my @types = sort keys %{ $self->hash->{$domain} || {} };
Condition50%1/2
$self->hash->{$domain} || {}
l!l
100
MC/DC0%0/1
$self->hash->{$domain} || {}
$self->hash->{$domain}
Truth table50%1/2
A
A= $self->hash->{$domain}
Aresult
11
00
166 10 ▶ return wantarray ? @types : \@types;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 2 10
167 }
168  
169 sub registered_domains
170 4 ▶{
Subroutine registered_domains: called CC=2 SCAR=6.9
Pod documented
171 4 my @domains = sort keys %{ shift->hash };
172 4 ▶ return wantarray ? @domains : \@domains;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
173 }
174  
175 sub dump
176 2 ▶{
Subroutine dump: called CC=3 SCAR=11.0
Pod documented
177 2 my($self) = shift;
178  
179 2 my $entries = $self->hash;
180 2 my %reg;
181  
182 2 foreach my $domain ($self->registered_domains)
183 {
184 8 foreach my $type ($self->registered_types($domain))
185 {
186 34 $reg{$domain}{$type} = $entries->{$domain}{$type}->dump;
187 }
188 }
189  
190 2 return \%reg;
191 }
192  
193 17 1;
194  
195 __END__
« DB/Cache.pm ↑ Summary DB/Registry/Entry.pm »