MaTirelire/DBItemId.pm

filter: Statementstmt 13.2% 11 / 83 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 10 totaltotal 8.3% 14 / 167 CC 31 SCAR 35.5
CC
31
Cov
8%
find_by_full_name
72.0
get_first_free_id
42.0
get_id
42.0
CRAP 34.7
« FieldPack.pm ↑ Summary MaTirelire/SavedPreferences.pm »
1 =encoding iso-8859-1
2  
3 =cut
4  
5 #
6 # Copyright (C) 2005, Maxime Soulé
7 # You may distribute this file under the terms of the Artistic
8 # License, as specified in the README file.
9 #
10  
11 package Palm::MaTirelire::DBItemId;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Palm::MaTirelire::DBItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use base qw(Palm::MaTirelire::DBItem);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '1.0';
20  
21  
22 sub name ($$;$)
23 0 ▶{
Subroutine name: not called CC=5 SCAR=34.0
Pod undocumented
24 0 my($self, $id, $ref_cache) = @_;
25  
26 0 my($num, $unfiled_name) = @{$self->meta_infos}{qw(num unfiled_name)};
27  
28 # "Unfiled" case...
29 0 ▶ return $unfiled_name if defined $unfiled_name and $id == $num - 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $unfiled_name and $id == $num - 1 0 0 0
Condition0%0/3
defined $unfiled_name and $id == $num - 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $unfiled_name and $id == $num - 1
defined $unfiled_name $id == $num - 1
Truth table0%0/3
A and B
A= defined $unfiled_nameB= $id == $num - 1
ABresult
0X0
100
111
30  
31 0 ▶ my $rec = defined($ref_cache) ? $ref_cache->[$id] : $self->get_id($id);
Branch: 1 branch
BranchTrueFalseTotal
defined $ref_cache ? : 0 0 0
32  
33 0 ▶ return undef unless defined $rec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec 0 0 0
34  
35 0 return $rec->{name};
36 }
37  
38  
39 sub full_name ($$;$)
40 0 ▶{
Subroutine full_name: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my($self, $id, $ref_cache) = @_;
42  
43 0 return $self->name($id, $ref_cache);
44 }
45  
46  
47 sub unfiled_id ($)
48 0 ▶{
Subroutine unfiled_id: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my $self = shift;
50  
51 0 my($unfiled_name, $num) = @{$self->meta_infos}{qw(unfiled_name num)};
52  
53 0 ▶ return undef unless defined $unfiled_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $unfiled_name 0 0 0
54  
55 0 return $num - 1;
56 }
57  
58  
59 sub unfiled_name ($)
60 0 ▶{
Subroutine unfiled_name: not called CC=1 SCAR=6.9
Pod undocumented
61 0 return shift->meta_infos->{unfiled_name};
62 }
63  
64  
65 sub new_RecordWithAutoId ($)
66 0 ▶{
Subroutine new_RecordWithAutoId: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my $self = shift;
68  
69 0 my $rec = $self->new_Record;
70  
71 0 my $id_field = $self->meta_infos->{id_field};
72  
73 0 $rec->{$id_field} = $self->get_first_free_id;
74  
75 0 ▶ return defined($rec->{$id_field}) ? $rec : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $rec->{$id_field} ? : 0 0 0
76 }
77  
78  
79 sub new_RecordWithId ($$)
80 0 ▶{
Subroutine new_RecordWithId: not called CC=4 SCAR=30.0
Pod undocumented
81 0 my($self, $id) = @_;
82  
83 my($id_field, $unfiled_name, $num)
84 0 = @{$self->meta_infos}{qw(id_field unfiled_name num)};
85  
86 0 ▶ return undef if $id >= $num - (defined($unfiled_name) ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
if $id >= $num - (defined $unfiled_name ? 1 : 0) 0 0 0
defined $unfiled_name ? : 0 0 0
87  
88 0 my $rec = $self->new_Record;
89  
90 0 $rec->{$id_field} = $id;
91  
92 0 ▶ return defined($rec->{$id_field}) ? $rec : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $rec->{$id_field} ? : 0 0 0
93 }
94  
95  
96 sub get_first_free_id ($)
97 0 ▶{
Subroutine get_first_free_id: not called CC=6 SCAR=37.4
Pod undocumented
98 0 my $self = shift;
99  
100 my($id_field, $unfiled_name, $num)
101 0 = @{$self->meta_infos}{qw(id_field unfiled_name num)};
102 0 my @ids;
103  
104 0 foreach my $rec (@{$self->{records}})
105 {
106 0 $ids[$rec->{$id_field}] = 1;
107 }
108  
109 0 my $free_id;
110 0 ▶ for ($free_id = 0; $free_id < @ids; $free_id++)
Branch: 1 branch
BranchTrueFalseTotal
if ($free_id < @ids) 0 0 0
111 {
112 0 ▶ return $free_id unless defined $ids[$free_id];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ids[$free_id] 0 0 0
113 }
114  
115 0 ▶ return $free_id if $free_id < $num - (defined($unfiled_name) ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
if $free_id < $num - (defined $unfiled_name ? 1 : 0) 0 0 0
defined $unfiled_name ? : 0 0 0
116  
117 0 return undef;
118 }
119  
120  
121 sub get_id ($$)
122 0 ▶{
Subroutine get_id: not called CC=6 SCAR=37.4
Pod undocumented
123 0 my($self, $id) = @_;
124  
125 my($id_field, $unfiled_name, $num)
126 0 = @{$self->meta_infos}{qw(id_field unfiled_name num)};
127  
128 0 ▶ if ($id >= $num - (defined($unfiled_name) ? 1 : 0))
Branch: 2 branches
BranchTrueFalseTotal
if ($id >= $num - (defined $unfiled_name ? 1 : 0)) 0 0 0
defined $unfiled_name ? : 0 0 0
129 {
130 # XXX
131 0 return undef;
132 }
133  
134 0 foreach my $rec (@{$self->{records}})
135 {
136 0 ▶ return $rec if exists $rec->{$id_field} and $rec->{$id_field} == $id;
Branch: 1 branch
BranchTrueFalseTotal
if exists $rec->{$id_field} and $rec->{$id_field} == $id 0 0 0
Condition0%0/3
exists $rec->{$id_field} and $rec->{$id_field} == $id
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rec->{$id_field} and $rec->{$id_field} == $id
exists $rec->{$id_field} $rec->{$id_field} == $id
Truth table0%0/3
A and B
A= exists $rec->{$id_field}B= $rec->{$id_field} == $id
ABresult
0X0
100
111
137 }
138  
139 0 return undef;
140 }
141  
142  
143 sub find_by_full_name ($$)
144 0 ▶{
Subroutine find_by_full_name: not called CC=8 SCAR=42.8
Pod undocumented
145 0 my($self, $name) = @_;
146  
147 my($id_field, $unfiled_name)
148 0 = @{$self->meta_infos}{qw(id_field unfiled_name)};
149  
150 0 ▶ return wantarray ? () : undef if $name eq $unfiled_name;
Branch: 2 branches
BranchTrueFalseTotal
if $name eq $unfiled_name 0 0 0
wantarray ? : 0 0 0
151  
152 0 my $ref_cache = $self->build_cache_id;
153 0 my @ret_list;
154  
155 0 foreach my $rec (@{$self->{records}})
156 {
157 0 ▶ if (exists $rec->{$id_field}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rec->{$id_field} and $name eq $self->full_name($rec->{$id_field}, $ref_cache)) 0 0 0
Condition0%0/3
exists $rec->{$id_field} and $name eq $self->full_name($rec->{$id_field}, $ref_cache)
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rec->{$id_field} and $name eq $self->full_name($rec->{$id_field}, $ref_cache)
exists $rec->{$id_field} $name eq $self->full_name($rec->{$id_field}, $ref_cache)
Truth table0%0/3
A and B
A= exists $rec->{$id_field}B= $name eq $self->full_name($rec->{$id_field}, $ref_cache)
ABresult
0X0
100
111
158 and $name eq $self->full_name($rec->{$id_field}, $ref_cache))
159 {
160 0 ▶ return $rec unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
161  
162 0 push(@ret_list, $rec);
163 }
164 }
165  
166 0 ▶ return wantarray ? @ret_list : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
167 }
168  
169  
170 sub build_cache_id ($)
171 0 ▶{
Subroutine build_cache_id: not called CC=5 SCAR=34.0
Pod undocumented
172 0 my $self = shift;
173  
174 my($id_field, $unfiled, $num)
175 0 = @{$self->meta_infos}{qw(id_field unfiled_name num)};
176  
177 0 ▶ $unfiled = defined($unfiled) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $unfiled ? : 0 0 0
178  
179 0 my @cache;
180 0 foreach my $rec (@{$self->{records}})
181 {
182 0 ▶ if (exists $rec->{$id_field})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rec->{$id_field}) 0 0 0
183 {
184 0 my $id = $rec->{$id_field};
185  
186 0 ▶ if ($id >= $num - $unfiled)
Branch: 1 branch
BranchTrueFalseTotal
if ($id >= $num - $unfiled) { } 0 0 0
187 {
188 # XXX
189 }
190 else
191 {
192 0 $cache[$id] = $rec;
193 }
194 }
195 }
196  
197 0 return \@cache;
198 }
199  
200 1 1;
201 __END__
« FieldPack.pm ↑ Summary MaTirelire/SavedPreferences.pm »