PDB.pm

filter: Statementstmt 4.2% 17 / 401 Branchbran 0.0% 0 / 212 Conditioncond 0.0% 0 / 71 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 10.5% 2 / 19 Podpod 90.9% 10 / 11 totaltotal 3.8% 29 / 755 CC 141 SCAR 72.8
CC
141
Cov
2%
Write
3080.0
Load
1482.0
_load_rec_index
182.0
CRAP 1448.9
↑ Summary Datebook.pm »
1 # PDB.pm
2 #
3 # Perl module for reading and writing Palm databases (both PDB and PRC).
4 #
5 # Copyright (C) 1999, 2000, Andrew Arensburger.
6 # You may distribute this file under the terms of the Artistic
7 # License, as specified in the README file.
8 #
9 # $Id: PDB.pm,v 1.29 2002/11/03 16:43:16 azummo Exp $
10  
11 # A Palm database file (either .pdb or .prc) has the following overall
12 # structure:
13 # Header
14 # Index header
15 # Record/resource index
16 # Two NUL(?) bytes
17 # Optional AppInfo block
18 # Optional sort block
19 # Records/resources
20 # See http://www.palmos.com/dev/tech/docs/fileformats.zip
21 # for details.
22  
23 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 package Palm::PDB;
25 1 ▶use vars qw( $VERSION %PDBHandlers %PRCHandlers );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # One liner, to allow MakeMaker to work.
28 1 $VERSION = do { my @r = (q$Revision: 1.29 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
29  
30 =head1 NAME
31  
32 Palm::PDB - Parse Palm database files.
33  
34 =head1 SYNOPSIS
35  
36 use Palm::PDB;
37 use SomeHelperClass;
38  
39 $pdb = new Palm::PDB;
40 $pdb->Load("myfile.pdb");
41  
42 # Manipulate records in $pdb
43  
44 $pdb->Write("myotherfile.pdb");
45  
46 (Note: yes, you do want to use C<Palm::PDB>, even if you're dealing
47 with some other type of database. $pdb will be reblessed to the
48 appropriate type by C<$pdb-E<gt>Load>.)
49  
50 =head1 DESCRIPTION
51  
52 The Palm::PDB module provides a framework for reading and writing
53 database files for use on PalmOS devices such as the PalmPilot. It can
54 read and write both Palm Database (C<.pdb>) and Palm Resource
55 (C<.prc>) files.
56  
57 By itself, the PDB module is not terribly useful; it is intended to be
58 used in conjunction with supplemental modules for specific types of
59 databases, such as Palm::Raw or Palm::Memo.
60  
61 The Palm::PDB module encapsulates the common work of parsing the
62 structure of a Palm database. The L<Load()|/Load> function reads the file,
63 then passes the individual chunks (header, records, etc.) to
64 application-specific functions for processing. Similarly, the
65 L<Write()|/Write> function calls application-specific functions to get the
66 individual chunks, then writes them to a file.
67  
68 =head1 METHODS
69  
70 =cut
71  
72 1 my $EPOCH_1904 = 2082844800; # Difference between Palm's
73 # epoch (Jan. 1, 1904) and
74 # Unix's epoch (Jan. 1, 1970),
75 # in seconds.
76 1 my $HeaderLen = 32+2+2+(9*4); # Size of database header
77 1 my $RecIndexHeaderLen = 6; # Size of record index header
78 1 my $IndexRecLen = 8; # Length of record index entry
79 1 my $IndexRsrcLen = 10; # Length of resource index entry
80  
81 1 %PDBHandlers = (); # Record handler map
82 1 %PRCHandlers = (); # Resource handler map
83  
84 =head2 new
85  
86 $new = new Palm::PDB();
87  
88 Creates a new PDB. $new is a reference to an anonymous hash. Some of
89 its elements have special significance. See L<Load()|/Load>.
90  
91 =cut
92  
93 sub new
94 0 ▶{
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
95 0 my $class = shift;
96 0 my $params = shift;
97  
98 0 my $self = {};
99  
100  
101 # Initialize the PDB. These values are just defaults, of course.
102 0 ▶ $self->{'name'} = $params->{'name'} || "";
Condition0%0/2
$params->{'name'} || ''
l!l
00
MC/DC0%0/1
$params->{'name'} || ''
$params->{'name'}
Truth table0%0/2
A
A= $params->{'name'}
Aresult
11
00
103 0 ▶ $self->{'attributes'} = $params->{'attributes'} || {};
Condition0%0/2
$params->{'attributes'} || {}
l!l
00
MC/DC0%0/1
$params->{'attributes'} || {}
$params->{'attributes'}
Truth table0%0/2
A
A= $params->{'attributes'}
Aresult
11
00
104 0 ▶ $self->{'version'} = $params->{'version'} || 0;
Condition0%0/2
$params->{'version'} || 0
l!l
00
MC/DC0%0/1
$params->{'version'} || 0
$params->{'version'}
Truth table0%0/2
A
A= $params->{'version'}
Aresult
11
00
105  
106 0 my $now = time;
107  
108 0 ▶ $self->{'ctime'} = $params->{'ctime'} || $now;
Condition0%0/3
$params->{'ctime'} || $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'ctime'} || $now
$params->{'ctime'} $now
Truth table0%0/3
A || B
A= $params->{'ctime'}B= $now
ABresult
1X1
011
000
109 0 ▶ $self->{'mtime'} = $params->{'mtime'} || $now;
Condition0%0/3
$params->{'mtime'} || $now
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'mtime'} || $now
$params->{'mtime'} $now
Truth table0%0/3
A || B
A= $params->{'mtime'}B= $now
ABresult
1X1
011
000
110 0 ▶ $self->{'baktime'} = $params->{'baktime'} || -$EPOCH_1904;
Condition0%0/3
$params->{'baktime'} || -$EPOCH_1904
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'baktime'} || -$EPOCH_1904
$params->{'baktime'} -$EPOCH_1904
Truth table0%0/3
A || B
A= $params->{'baktime'}B= -$EPOCH_1904
ABresult
1X1
011
000
111  
112 0 ▶ $self->{'modnum'} = $params->{'modnum'} || 0;
Condition0%0/2
$params->{'modnum'} || 0
l!l
00
MC/DC0%0/1
$params->{'modnum'} || 0
$params->{'modnum'}
Truth table0%0/2
A
A= $params->{'modnum'}
Aresult
11
00
113 0 ▶ $self->{'type'} = $params->{'type'} || "\0\0\0\0";
Condition0%0/2
$params->{'type'} || "\000\000\000\000"
l!l
00
MC/DC0%0/1
$params->{'type'} || "\000\000\000\000"
$params->{'type'}
Truth table0%0/2
A
A= $params->{'type'}
Aresult
11
00
114 0 ▶ $self->{'creator'} = $params->{'creator'} || "\0\0\0\0";
Condition0%0/2
$params->{'creator'} || "\000\000\000\000"
l!l
00
MC/DC0%0/1
$params->{'creator'} || "\000\000\000\000"
$params->{'creator'}
Truth table0%0/2
A
A= $params->{'creator'}
Aresult
11
00
115 0 ▶ $self->{'uniqueIDseed'} = $params->{'uniqueIDseed'} || 0;
Condition0%0/2
$params->{'uniqueIDseed'} || 0
l!l
00
MC/DC0%0/1
$params->{'uniqueIDseed'} || 0
$params->{'uniqueIDseed'}
Truth table0%0/2
A
A= $params->{'uniqueIDseed'}
Aresult
11
00
116  
117 0 $self->{"2NULs"} = "\0\0";
118  
119 0 bless $self, $class;
120 0 return $self;
121 }
122  
123 =head2 RegisterPDBHandlers
124  
125 &Palm::PDB::RegisterPDBHandlers("classname", typespec...);
126  
127 Typically:
128  
129 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
130 [ "FooB", "DATA" ],
131 );
132  
133 The $pdb->L<Load()|/Load> method acts as a virtual constructor. When
134 it reads the header of a C<.pdb> file, it looks up the file's creator
135 and type in a set of tables, and reblesses $pdb into a class capable
136 of parsing the application-specific parts of the file (AppInfo block,
137 records, etc.)
138  
139 RegisterPDBHandlers() adds entries to these tables; it says that any
140 file whose creator and/or type match any of the I<typespec>s (there
141 may be several) should be reblessed into the class I<classname>.
142  
143 Note that RegisterPDBHandlers() applies only to record databases
144 (C<.pdb> files). For resource databases, see
145 L<RegisterPRCHandlers()|/RegisterPRCHandlers>.
146  
147 RegisterPDBHandlers() is typically called in the import() function of
148 a helper class. In this case, the class is registering itself, and it
149 is simplest just to use C<__PACKAGE__> for the package name:
150  
151 package PalmFoo;
152 use Palm::PDB;
153  
154 sub import
155 {
156 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
157 [ "FooZ", "DATA" ]
158 );
159 }
160  
161 A I<typespec> can be either a string, or an anonymous array with two
162 elements. If it is an anonymous array, then the first element is the
163 file's creator; the second element is its type. If a I<typespec> is a
164 string, it is equivalent to specifying that string as the database's
165 creator, and a wildcard as its type.
166  
167 The creator and type should be either four-character strings, or the
168 empty string. An empty string represents a wildcard. Thus:
169  
170 &Palm::PDB::RegisterPDBHandlers("MyClass",
171 [ "fOOf", "DATA" ],
172 [ "BarB", "" ],
173 [ "", "BazQ" ],
174 "Fred"
175 );
176  
177 Class MyClass will handle:
178  
179 =over 4
180  
181 =item Z<>
182  
183 Databases whose creator is C<fOOf> and whose type is C<DATA>.
184  
185 =item Z<>
186  
187 Databases whose creator is C<BarB>, of any type.
188  
189 =item Z<>
190  
191 Databases with any creator whose type is C<BazQ>.
192  
193 =item Z<>
194  
195 Databases whose creator is C<Fred>, of any type.
196  
197 =back
198  
199 =for html </DL>
200 <!-- Grrr... pod2html is broken, and doesn't terminate the list correctly -->
201  
202 =cut
203 #' <-- For Emacs.
204  
205 sub RegisterPDBHandlers
206 0 ▶{
Subroutine RegisterPDBHandlers: not called CC=3 SCAR=24.8
Pod documented
207 0 my $handler = shift; # Name of class that'll handle
208 # these databases
209 0 my @types = @_;
210 0 my $item;
211  
212 0 foreach $item (@types)
213 {
214 0 ▶ if (ref($item) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 0 0 0
215 {
216 0 $PDBHandlers{$item->[0]}{$item->[1]} = $handler;
217 } else {
218 0 $PDBHandlers{$item}{""} = $handler;
219 }
220 }
221 }
222  
223 =head2 RegisterPRCHandlers
224  
225 &Palm::PDB::RegisterPRCHandlers("classname", typespec...);
226  
227 Typically:
228  
229 &Palm::PDB::RegisterPRCHandlers(__PACKAGE__,
230 [ "FooZ", "CODE" ],
231 );
232  
233 RegisterPRCHandlers() is similar to
234 L<RegisterPDBHandlers()|/RegisterPDBHandlers>, but specifies a class
235 to handle resource database (C<.prc>) files.
236  
237 A class for parsing applications should begin with:
238  
239 package PalmApps;
240 use Palm::PDB;
241  
242 sub import
243 {
244 &Palm::PDB::RegisterPRCHandlers(__PACKAGE__,
245 [ "", "appl" ]
246 );
247 }
248  
249 =cut
250  
251 sub RegisterPRCHandlers
252 0 ▶{
Subroutine RegisterPRCHandlers: not called CC=3 SCAR=24.8
Pod documented
253 0 my $handler = shift; # Name of class that'll handle
254 # these databases
255 0 my @types = @_;
256 0 my $item;
257  
258 0 foreach $item (@types)
259 {
260 0 ▶ if (ref($item) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 0 0 0
261 {
262 0 $PRCHandlers{$item->[0]}{$item->[1]} = $handler;
263 } else {
264 0 $PRCHandlers{$item}{""} = $handler;
265 }
266 }
267 }
268  
269 =head2 Load
270  
271 $pdb->Load("filename");
272  
273 Reads the file F<filename>, parses it, reblesses $pdb to the
274 appropriate class, and invokes appropriate methods to parse the
275 application-specific parts of the database (see L</HELPER CLASSES>).
276  
277 Load() uses the I<typespec>s given to RegisterPDBHandlers() and
278 RegisterPRCHandlers() when deciding how to rebless $pdb. For record
279 databases, it uses the I<typespec>s passed to RegisterPDBHandlers(),
280 and for resource databases, it uses the I<typespec>s passed to
281 RegisterPRCHandlers().
282  
283 Load() looks for matching I<typespec>s in the following order, from
284 most to least specific:
285  
286 =over 4
287  
288 =item 1
289  
290 A I<typespec> that specifies both the database's creator and its type
291 exactly.
292  
293 =item 2
294  
295 A I<typespec> that specifies the database's type and has a wildcard
296 for the creator (this is rarely used).
297  
298 =item 3
299  
300 A I<typespec> that specifies the database's creator and has a wildcard
301 for the type.
302  
303 =item 4
304  
305 A I<typespec> that has wildcards for both the creator and type.
306  
307 =back
308  
309 =for html </OL>
310 <!-- Grrr... pod2html is broken, and doesn't terminate the list correctly -->
311  
312 Thus, if the database has creator "FooZ" and type "DATA", Load() will
313 first look for "FooZ"/"DATA", then ""/"DATA", then "FooZ"/"", and
314 finally will fall back on ""/"" (the universal default).
315  
316 After Load() returns, $pdb may contain the following fields:
317  
318 =over
319  
320 =item $pdb-E<gt>{Z<>"name"Z<>}
321  
322 The name of the database.
323  
324 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"ResDB"Z<>}
325  
326 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"ReadOnly"Z<>}
327  
328 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"AppInfoDirty"Z<>}
329  
330 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Backup"Z<>}
331  
332 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"OKToInstallNewer"Z<>}
333  
334 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"ResetAfterInstall"Z<>}
335  
336 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"CopyPrevention"Z<>}
337  
338 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Stream"Z<>}
339  
340 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Hidden"Z<>}
341  
342 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"LaunchableData"Z<>}
343  
344 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Recyclable"Z<>}
345  
346 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Bundle"Z<>}
347  
348 =item $pdb-E<gt>{Z<>"attributes"Z<>}{Z<>"Open"Z<>}
349  
350 These are the attribute flags from the database header. Each is true
351 iff the corresponding flag is set.
352  
353 The "LaunchableData" attribute is set on PQAs.
354  
355 =item $pdb-E<gt>{Z<>"version"Z<>}
356  
357 The database's version number. An integer.
358  
359 =item $pdb-E<gt>{Z<>"ctime"Z<>}
360  
361 =item $pdb-E<gt>{Z<>"mtime"Z<>}
362  
363 =item $pdb-E<gt>{Z<>"baktime"Z<>}
364  
365 The database's creation time, last modification time, and time of last
366 backup, in Unix C<time_t> format (seconds since Jan. 1, 1970).
367  
368 =item $pdb-E<gt>{Z<>"modnum"Z<>}
369  
370 The database's modification number. An integer.
371  
372 =item $pdb-E<gt>{Z<>"type"Z<>}
373  
374 The database's type. A four-character string.
375  
376 =item $pdb-E<gt>{Z<>"creator"Z<>}
377  
378 The database's creator. A four-character string.
379  
380 =item $pdb-E<gt>{Z<>"uniqueIDseed"Z<>}
381  
382 The database's unique ID seed. An integer.
383  
384 =item $pdb-E<gt>{Z<>"2NULs"Z<>}
385  
386 The two NUL bytes that appear after the record index and the AppInfo
387 block. Included here because every once in a long while, they are not
388 NULs, for some reason.
389  
390 =item $pdb-E<gt>{Z<>"appinfo"Z<>}
391  
392 The AppInfo block, as returned by the $pdb->ParseAppInfoBlock() helper
393 method.
394  
395 =item $pdb-E<gt>{Z<>"sort"Z<>}
396  
397 The sort block, as returned by the $pdb->ParseSortBlock() helper
398 method.
399  
400 =item @{$pdb-E<gt>{Z<>"records"Z<>}}
401  
402 The list of records in the database, as returned by the
403 $pdb->ParseRecord() helper method. Resource databases do not have
404 this.
405  
406 =item @{$pdb-E<gt>{Z<>"resources"Z<>}}
407  
408 The list of resources in the database, as returned by the
409 $pdb->ParseResource() helper method. Record databases do not have
410 this.
411  
412 =back
413  
414 All of these fields may be set by hand, but should conform to the
415 format given above.
416  
417 =for html </DL>
418 <!-- Grrr... pod2html is broken, and doesn't terminate the list correctly -->
419  
420 =cut
421 #'
422  
423 # Load
424 sub Load
425 0 ▶{
Subroutine Load: not called CC=38 SCAR=73.0
Pod documented
426 0 my $self = shift;
427 0 my $fname = shift; # Filename to read from
428 0 my $buf; # Buffer into which to read stuff
429  
430 # Open database file
431 0 ▶ open PDB, "< $fname" or die "Can't open \"$fname\": $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open PDB, "< $fname" or die qq[Can't open "$fname": $!\n] 0 0 0
432 0 binmode PDB; # Read as binary file under MS-DOS
433  
434 # Get the size of the file. It'll be useful later
435 0 seek PDB, 0, 2; # 2 == SEEK_END. Seek to the end.
436 0 $self->{_size} = tell PDB;
437 0 seek PDB, 0, 0; # 0 == SEEK_START. Rewind to the beginning.
438  
439 # Read header
440 0 my $name;
441 my $attributes;
442 0 my $version;
443 0 my $ctime;
444 0 my $mtime;
445 0 my $baktime;
446 0 my $modnum;
447 0 my $appinfo_offset;
448 0 my $sort_offset;
449 0 my $type;
450 0 my $creator;
451 0 my $uniqueIDseed;
452  
453 0 read PDB, $buf, $HeaderLen; # Read the PDB header
454  
455 # Split header into its component fields
456 0 ($name, $attributes, $version, $ctime, $mtime, $baktime,
457 $modnum, $appinfo_offset, $sort_offset, $type, $creator,
458 $uniqueIDseed) =
459 unpack "a32 n n N N N N N N a4 a4 N", $buf;
460  
461 0 ($self->{name} = $name) =~ s/\0.*$//;
462 0 ▶ $self->{attributes}{resource} = 1 if $attributes & 0x0001;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 1 0 0 0
463 0 ▶ $self->{attributes}{"read-only"} = 1 if $attributes & 0x0002;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 2 0 0 0
464 0 ▶ $self->{attributes}{"AppInfo dirty"} = 1 if $attributes & 0x0004;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 4 0 0 0
465 0 ▶ $self->{attributes}{backup} = 1 if $attributes & 0x0008;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 8 0 0 0
466 0 ▶ $self->{attributes}{"OK newer"} = 1 if $attributes & 0x0010;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 16 0 0 0
467 0 ▶ $self->{attributes}{reset} = 1 if $attributes & 0x0020;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32 0 0 0
468 0 ▶ $self->{attributes}{open} = 1 if $attributes & 0x8000;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32768 0 0 0
469 0 ▶ $self->{attributes}{launchable} = 1 if $attributes & 0x0200;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 512 0 0 0
470  
471 # Attribute names as of PalmOS 5.0 ( see /Core/System/DataMgr.h )
472  
473 0 ▶ $self->{'attributes'}{'ResDB'} = 1 if $attributes & 0x0001;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 1 0 0 0
474 0 ▶ $self->{'attributes'}{'ReadOnly'} = 1 if $attributes & 0x0002;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 2 0 0 0
475 0 ▶ $self->{'attributes'}{'AppInfoDirty'} = 1 if $attributes & 0x0004;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 4 0 0 0
476 0 ▶ $self->{'attributes'}{'Backup'} = 1 if $attributes & 0x0008;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 8 0 0 0
477 0 ▶ $self->{'attributes'}{'OKToInstallNewer'} = 1 if $attributes & 0x0010;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 16 0 0 0
478 0 ▶ $self->{'attributes'}{'ResetAfterInstall'} = 1 if $attributes & 0x0020;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32 0 0 0
479 0 ▶ $self->{'attributes'}{'CopyPrevention'} = 1 if $attributes & 0x0040;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 64 0 0 0
480 0 ▶ $self->{'attributes'}{'Stream'} = 1 if $attributes & 0x0080;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 128 0 0 0
481 0 ▶ $self->{'attributes'}{'Hidden'} = 1 if $attributes & 0x0100;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 256 0 0 0
482 0 ▶ $self->{'attributes'}{'LaunchableData'} = 1 if $attributes & 0x0200;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 512 0 0 0
483 0 ▶ $self->{'attributes'}{'Recyclable'} = 1 if $attributes & 0x0400;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 1024 0 0 0
484 0 ▶ $self->{'attributes'}{'Bundle'} = 1 if $attributes & 0x0800;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 2048 0 0 0
485 0 ▶ $self->{'attributes'}{'Open'} = 1 if $attributes & 0x8000;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32768 0 0 0
486  
487  
488 0 $self->{version} = $version;
489 0 $self->{ctime} = $ctime - $EPOCH_1904;
490 0 $self->{mtime} = $mtime - $EPOCH_1904;
491 0 $self->{baktime} = $baktime - $EPOCH_1904;
492 0 $self->{modnum} = $modnum;
493 # _appinfo_offset and _sort_offset are private fields
494 0 $self->{_appinfo_offset} = $appinfo_offset;
495 0 $self->{_sort_offset} = $sort_offset;
496 0 $self->{type} = $type;
497 0 $self->{creator} = $creator;
498 0 $self->{uniqueIDseed} = $uniqueIDseed;
499  
500 # Rebless this PDB object, depending on its type and/or
501 # creator. This allows us to magically invoke the proper
502 # &Parse*() function on the various parts of the database.
503  
504 # Look for most specific handlers first, least specific ones
505 # last. That is, first look for a handler that deals
506 # specifically with this database's creator and type, then for
507 # one that deals with this database's creator and any type,
508 # and finally for one that deals with anything.
509  
510 0 my $handler;
511 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
512 {
513 # Look among resource handlers
514 $handler = $PRCHandlers{$self->{creator}}{$self->{type}} ||
515 $PRCHandlers{undef}{$self->{type}} ||
516 $PRCHandlers{$self->{creator}}{""} ||
517 0 ▶ $PRCHandlers{""}{""};
Condition0%0/9
$Palm::PDB::PRCHandlers{$self->{'creator'}}{$self->{'type'}} || $Palm::PDB::PRCHandlers{'undef'}{$self->{'type'}} || $Palm::PDB::PRCHandlers{$self->{'creator'}}{''} || $Palm::PDB::PRCHandlers{''}{''}
l!l&&r!l&&!r
000
$Palm::PDB::PRCHandlers{$self->{"creator"}}{$self->{"type"}} or $Palm::PDB::PRCHandlers{"undef"}{$self->{"type"}} or $Palm::PDB::PRCHandlers{$self->{"creator"}}{""}
l!l&&r!l&&!r
000
$Palm::PDB::PRCHandlers{$self->{"creator"}}{$self->{"type"}} or $Palm::PDB::PRCHandlers{"undef"}{$self->{"type"}}
l!l&&r!l&&!r
000
MC/DC0%0/4
$Palm::PDB::PRCHandlers{$self->{'creator'}}{$self->{'type'}} || $Palm::PDB::PRCHandlers{'undef'}{$self->{'type'}} || $Palm::PDB::PRCHandlers{$self->{'creator'}}{''} || $Palm::PDB::PRCHandlers{''}{''}
$Palm::PDB::PRCHandlers{$self->{"creator"}}{$self->{"type"}} $Palm::PDB::PRCHandlers{"undef"}{$self->{"type"}} $Palm::PDB::PRCHandlers{$self->{"creator"}}{""} $Palm::PDB::PRCHandlers{''}{''}
Truth table0%0/5
A or B or C || D
A= $Palm::PDB::PRCHandlers{$self->{"creator"}}{$self->{"type"}}B= $Palm::PDB::PRCHandlers{"undef"}{$self->{"type"}}C= $Palm::PDB::PRCHandlers{$self->{"creator"}}{""}D= $Palm::PDB::PRCHandlers{''}{''}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
518 } else {
519 # Look among record handlers
520 $handler = $PDBHandlers{$self->{creator}}{$self->{type}} ||
521 $PDBHandlers{""}{$self->{type}} ||
522 $PDBHandlers{$self->{creator}}{""} ||
523 0 ▶ $PDBHandlers{""}{""};
Condition0%0/9
$Palm::PDB::PDBHandlers{$self->{'creator'}}{$self->{'type'}} || $Palm::PDB::PDBHandlers{''}{$self->{'type'}} || $Palm::PDB::PDBHandlers{$self->{'creator'}}{''} || $Palm::PDB::PDBHandlers{''}{''}
l!l&&r!l&&!r
000
$Palm::PDB::PDBHandlers{$self->{"creator"}}{$self->{"type"}} or $Palm::PDB::PDBHandlers{""}{$self->{"type"}} or $Palm::PDB::PDBHandlers{$self->{"creator"}}{""}
l!l&&r!l&&!r
000
$Palm::PDB::PDBHandlers{$self->{"creator"}}{$self->{"type"}} or $Palm::PDB::PDBHandlers{""}{$self->{"type"}}
l!l&&r!l&&!r
000
MC/DC0%0/4
$Palm::PDB::PDBHandlers{$self->{'creator'}}{$self->{'type'}} || $Palm::PDB::PDBHandlers{''}{$self->{'type'}} || $Palm::PDB::PDBHandlers{$self->{'creator'}}{''} || $Palm::PDB::PDBHandlers{''}{''}
$Palm::PDB::PDBHandlers{$self->{"creator"}}{$self->{"type"}} $Palm::PDB::PDBHandlers{""}{$self->{"type"}} $Palm::PDB::PDBHandlers{$self->{"creator"}}{""} $Palm::PDB::PDBHandlers{''}{''}
Truth table0%0/5
A or B or C || D
A= $Palm::PDB::PDBHandlers{$self->{"creator"}}{$self->{"type"}}B= $Palm::PDB::PDBHandlers{""}{$self->{"type"}}C= $Palm::PDB::PDBHandlers{$self->{"creator"}}{""}D= $Palm::PDB::PDBHandlers{''}{''}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
524 }
525  
526 0 ▶ if (defined($handler))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $handler) { } 0 0 0
527 {
528 0 bless $self, $handler;
529 } else {
530 # XXX - This should probably return 'undef' or something,
531 # rather than die.
532 0 die "No handler defined for creator \"$creator\", type \"$type\"\n";
533 }
534  
535 ## Read record/resource index
536 # Read index header
537 0 read PDB, $buf, $RecIndexHeaderLen;
538  
539 0 my $next_index;
540 my $numrecs;
541  
542 0 ($next_index, $numrecs) = unpack "N n", $buf;
543 0 $self->{_numrecs} = $numrecs;
544  
545 # Read the index itself
546 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
547 {
548 0 &_load_rsrc_index($self, \*PDB);
549 } else {
550 0 &_load_rec_index($self, \*PDB);
551 }
552  
553 # Read the two NUL bytes
554 # XXX - Actually, these are bogus. They don't appear in the
555 # spec. The Right Thing to do is to ignore them, and use the
556 # specified or calculated offsets, if they're sane. Sane ==
557 # appears later than the current position.
558 # read PDB, $buf, 2;
559 # $self->{"2NULs"} = $buf;
560  
561 # Read AppInfo block, if it exists
562 0 ▶ if ($self->{_appinfo_offset} != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_appinfo_offset"} != 0) 0 0 0
563 {
564 0 &_load_appinfo_block($self, \*PDB);
565 }
566  
567 # Read sort block, if it exists
568 0 ▶ if ($self->{_sort_offset} != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_sort_offset"} != 0) 0 0 0
569 {
570 0 &_load_sort_block($self, \*PDB);
571 }
572  
573 # Read record/resource list
574 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
575 {
576 0 &_load_resources($self, \*PDB);
577 } else {
578 0 &_load_records($self, \*PDB);
579 }
580  
581 # These keys were needed for parsing the file, but are not
582 # needed any longer. Delete them.
583 0 delete $self->{_index};
584 0 delete $self->{_numrecs};
585 0 delete $self->{_appinfo_offset};
586 0 delete $self->{_sort_offset};
587 0 delete $self->{_size};
588  
589 0 close PDB;
590 }
591  
592 # _load_rec_index
593 # Private function. Read the record index, for a record database
594 sub _load_rec_index
595 0 ▶{
Subroutine _load_rec_index: not called CC=13 SCAR=52.0
596 0 my $pdb = shift;
597 0 my $fh = shift; # Input file handle
598 0 my $i;
599 0 my $lastoffset = 0;
600  
601 # Read each record index entry in turn
602 0 ▶ for ($i = 0; $i < $pdb->{_numrecs}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pdb->{"_numrecs"}) 0 0 0
603 {
604 0 my $buf; # Input buffer
605  
606 # Read the next record index entry
607 my $offset;
608 0 my $attributes;
609 0 my @id; # Raw ID
610 0 my $id; # Numerical ID
611 0 my $entry = {}; # Parsed index entry
612  
613 0 read $fh, $buf, $IndexRecLen;
614  
615 # The ID field is a bit weird: it's represented as 3
616 # bytes, but it's really a double word (long) value.
617  
618 0 ($offset, $attributes, @id) = unpack "N C C3", $buf;
619  
620 0 ▶ if ($offset == $lastoffset)
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == $lastoffset) 0 0 0
621 {
622 0 print STDERR "Record $i has same offset as previous one: $offset\n";
623 }
624  
625 0 $lastoffset = $offset;
626  
627 0 $entry->{offset} = $offset;
628  
629 0 ▶ $entry->{attributes}{expunged} = 1 if $attributes & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 128 0 0 0
630 0 ▶ $entry->{attributes}{dirty} = 1 if $attributes & 0x40;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 64 0 0 0
631 0 ▶ $entry->{attributes}{deleted} = 1 if $attributes & 0x20;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32 0 0 0
632 0 ▶ $entry->{attributes}{private} = 1 if $attributes & 0x10;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 16 0 0 0
633  
634 # Attribute names as of PalmOS 5.0 ( see /Core/System/DataMgr.h )
635  
636 0 ▶ $entry->{'attributes'}{'Delete'} = 1 if $attributes & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 128 0 0 0
637 0 ▶ $entry->{'attributes'}{'Dirty'} = 1 if $attributes & 0x40;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 64 0 0 0
638 0 ▶ $entry->{'attributes'}{'Busy'} = 1 if $attributes & 0x20;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 32 0 0 0
639 0 ▶ $entry->{'attributes'}{'Secret'} = 1 if $attributes & 0x10;
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 16 0 0 0
640  
641 0 $entry->{id} = ($id[0] << 16) |
642 ($id[1] << 8) |
643 $id[2];
644  
645 # The lower 4 bits of the attributes field are
646 # overloaded: If the record has been deleted and/or
647 # expunged, then bit 0x08 indicates whether the record
648 # should be archived. Otherwise (if it's an ordinary,
649 # non-deleted record), the lower 4 bits specify the
650 # category that the record belongs in.
651 0 ▶ if (($attributes & 0xa0) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (($attributes & 160) == 0) { } 0 0 0
652 {
653 0 $entry->{category} = $attributes & 0x0f;
654 } else {
655 0 ▶ $entry->{attributes}{archive} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $attributes & 8 0 0 0
656 if $attributes & 0x08;
657 }
658  
659 # Put this information on a temporary array
660 0 push @{$pdb->{_index}}, $entry;
661 }
662 }
663  
664 # _load_rsrc_index
665 # Private function. Read the resource index, for a resource database
666 sub _load_rsrc_index
667 0 ▶{
Subroutine _load_rsrc_index: not called CC=2 SCAR=17.9
668 0 my $pdb = shift;
669 0 my $fh = shift; # Input file handle
670 0 my $i;
671  
672 # Read each resource index entry in turn
673 0 ▶ for ($i = 0; $i < $pdb->{_numrecs}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pdb->{"_numrecs"}) 0 0 0
674 {
675 0 my $buf; # Input buffer
676  
677 # Read the next resource index entry
678 my $type;
679 0 my $id;
680 0 my $offset;
681 0 my $entry = {}; # Parsed index entry
682  
683 0 read $fh, $buf, $IndexRsrcLen;
684  
685 0 ($type, $id, $offset) = unpack "a4 n N", $buf;
686  
687 0 $entry->{type} = $type;
688 0 $entry->{id} = $id;
689 0 $entry->{offset} = $offset;
690  
691 0 push @{$pdb->{_index}}, $entry;
692 }
693 }
694  
695 # _load_appinfo_block
696 # Private function. Read the AppInfo block
697 sub _load_appinfo_block
698 0 ▶{
Subroutine _load_appinfo_block: not called CC=6 SCAR=37.4
699 0 my $pdb = shift;
700 0 my $fh = shift; # Input file handle
701 0 my $len; # Length of AppInfo block
702 my $buf; # Input buffer
703  
704 # Sanity check: make sure we're positioned at the beginning of
705 # the AppInfo block
706 0 ▶ if (tell($fh) > $pdb->{_appinfo_offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh > $pdb->{"_appinfo_offset"}) 0 0 0
707 {
708 die "Bad AppInfo offset: expected ",
709 0 sprintf("0x%08x", $pdb->{_appinfo_offset}),
710 ", but I'm at ",
711 tell($fh), "\n";
712 }
713  
714 # Seek to the right place, if necessary
715 0 ▶ if (tell($fh) != $pdb->{_appinfo_offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh != $pdb->{"_appinfo_offset"}) 0 0 0
716 {
717 0 seek PDB, $pdb->{_appinfo_offset}, 0;
718 }
719  
720 # There's nothing that explicitly gives the size of the
721 # AppInfo block. Rather, it has to be inferred from the offset
722 # of the AppInfo block (previously recorded in
723 # $pdb->{_appinfo_offset}) and whatever's next in the file.
724 # That's either the sort block, the first data record, or the
725 # end of the file.
726  
727 0 ▶ if ($pdb->{_sort_offset})
Branch: 2 branches
BranchTrueFalseTotal
if ($pdb->{'_sort_offset'}) { } 0 0 0
elsif (defined $pdb->{'_index'} and @{$pdb->{'_index'};}) { } 0 0 0
728 {
729 # The next thing in the file is the sort block
730 0 $len = $pdb->{_sort_offset} - $pdb->{_appinfo_offset};
731 0 ▶ } elsif ((defined $pdb->{_index}) && @{$pdb->{_index}})
Condition0%0/3
defined $pdb->{"_index"} and @{$pdb->{"_index"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pdb->{"_index"} and @{$pdb->{"_index"};}
defined $pdb->{"_index"} @{$pdb->{"_index"};}
Truth table0%0/3
A and B
A= defined $pdb->{"_index"}B= @{$pdb->{"_index"};}
ABresult
0X0
100
111
732 {
733 # There's no sort block; the next thing in the file is
734 # the first data record
735 $len = $pdb->{_index}[0]{offset} -
736 0 $pdb->{_appinfo_offset};
737 } else {
738 # There's no sort block and there are no records. The
739 # AppInfo block goes to the end of the file.
740 0 $len = $pdb->{_size} - $pdb->{_appinfo_offset};
741 }
742  
743 # Read the AppInfo block
744 0 read $fh, $buf, $len;
745  
746 # Tell the real class to parse the AppInfo block
747 0 $pdb->{appinfo} = $pdb->ParseAppInfoBlock($buf);
748 }
749  
750 # _load_sort_block
751 # Private function. Read the sort block.
752 sub _load_sort_block
753 0 ▶{
Subroutine _load_sort_block: not called CC=4 SCAR=30.0
754 0 my $pdb = shift;
755 0 my $fh = shift; # Input file handle
756 0 my $len; # Length of sort block
757 my $buf; # Input buffer
758  
759 # Sanity check: make sure we're positioned at the beginning of
760 # the sort block
761 0 ▶ if (tell($fh) > $pdb->{_sort_offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh > $pdb->{"_sort_offset"}) 0 0 0
762 {
763 die "Bad sort block offset: expected ",
764 0 sprintf("0x%08x", $pdb->{_sort_offset}),
765 ", but I'm at ",
766 tell($fh), "\n";
767 }
768  
769 # Seek to the right place, if necessary
770 0 ▶ if (tell($fh) != $pdb->{_sort_offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh != $pdb->{"_sort_offset"}) 0 0 0
771 {
772 0 seek PDB, $pdb->{_sort_offset}, 0;
773 }
774  
775 # There's nothing that explicitly gives the size of the sort
776 # block. Rather, it has to be inferred from the offset of the
777 # sort block (previously recorded in $pdb->{_sort_offset})
778 # and whatever's next in the file. That's either the first
779 # data record, or the end of the file.
780  
781 0 ▶ if (defined($pdb->{_index}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pdb->{'_index'}) { } 0 0 0
782 {
783 # The next thing in the file is the first data record
784 $len = $pdb->{_index}[0]{offset} -
785 0 $pdb->{_sort_offset};
786 } else {
787 # There are no records. The sort block goes to the end
788 # of the file.
789 0 $len = $pdb->{_size} - $pdb->{_sort_offset};
790 }
791  
792 # Read the AppInfo block
793 0 read $fh, $buf, $len;
794  
795 # XXX - Check to see if the sort block has some predefined
796 # structure. If so, it might be a good idea to parse the sort
797 # block here.
798  
799 # Tell the real class to parse the sort block
800 0 $pdb->{sort} = $pdb->ParseSortBlock($buf);
801 }
802  
803 # _load_records
804 # Private function. Load the actual data records, for a record database
805 # (PDB)
806 sub _load_records
807 0 ▶{
Subroutine _load_records: not called CC=5 SCAR=34.0
808 0 my $pdb = shift;
809 0 my $fh = shift; # Input file handle
810 0 my $i;
811  
812 # Read each record in turn
813 0 ▶ for ($i = 0; $i < $pdb->{_numrecs}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pdb->{"_numrecs"}) 0 0 0
814 {
815 0 my $len; # Length of record
816 my $buf; # Input buffer
817  
818 # Sanity check: make sure we're where we think we
819 # should be.
820 0 ▶ if (tell($fh) > $pdb->{_index}[$i]{offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh > $pdb->{"_index"}[$i]{"offset"}) 0 0 0
821 {
822 die "Bad offset for record $i: expected ",
823 sprintf("0x%08x",
824 0 $pdb->{_index}[$i]{offset}),
825 " but it's at ",
826 sprintf("[0x%08x]", tell($fh)), "\n";
827 }
828  
829 # Seek to the right place, if necessary
830 0 ▶ if (tell($fh) != $pdb->{_index}[$i]{offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh != $pdb->{"_index"}[$i]{"offset"}) 0 0 0
831 {
832 0 seek PDB, $pdb->{_index}[$i]{offset}, 0;
833 }
834  
835 # Compute the length of the record: the last record
836 # extends to the end of the file. The others extend to
837 # the beginning of the next record.
838 0 ▶ if ($i == $pdb->{_numrecs} - 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $pdb->{'_numrecs'} - 1) { } 0 0 0
839 {
840 # This is the last record
841 $len = $pdb->{_size} -
842 0 $pdb->{_index}[$i]{offset};
843 } else {
844 # This is not the last record
845 $len = $pdb->{_index}[$i+1]{offset} -
846 0 $pdb->{_index}[$i]{offset};
847 }
848  
849 # Read the record
850 0 read $fh, $buf, $len;
851  
852 # Tell the real class to parse the record data. Pass
853 # &ParseRecord all of the information from the index,
854 # plus a "data" field with the raw record data.
855 0 my $record;
856  
857 $record = $pdb->ParseRecord(
858 0 %{$pdb->{_index}[$i]},
859 "data" => $buf,
860 );
861 0 push @{$pdb->{records}}, $record;
862 }
863 }
864  
865 # _load_resources
866 # Private function. Load the actual data resources, for a resource database
867 # (PRC)
868 sub _load_resources
869 0 ▶{
Subroutine _load_resources: not called CC=5 SCAR=34.0
870 0 my $pdb = shift;
871 0 my $fh = shift; # Input file handle
872 0 my $i;
873  
874 # Read each resource in turn
875 0 ▶ for ($i = 0; $i < $pdb->{_numrecs}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $pdb->{"_numrecs"}) 0 0 0
876 {
877 0 my $len; # Length of record
878 my $buf; # Input buffer
879  
880 # Sanity check: make sure we're where we think we
881 # should be.
882 0 ▶ if (tell($fh) > $pdb->{_index}[$i]{offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh > $pdb->{"_index"}[$i]{"offset"}) 0 0 0
883 {
884 die "Bad offset for resource $i: expected ",
885 sprintf("0x%08x",
886 0 $pdb->{_index}[$i]{offset}),
887 " but it's at ",
888 sprintf("0x%08x", tell($fh)), "\n";
889 }
890  
891 # Seek to the right place, if necessary
892 0 ▶ if (tell($fh) != $pdb->{_index}[$i]{offset})
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh != $pdb->{"_index"}[$i]{"offset"}) 0 0 0
893 {
894 0 seek PDB, $pdb->{_index}[$i]{offset}, 0;
895 }
896  
897 # Compute the length of the resource: the last
898 # resource extends to the end of the file. The others
899 # extend to the beginning of the next resource.
900 0 ▶ if ($i == $pdb->{_numrecs} - 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $pdb->{'_numrecs'} - 1) { } 0 0 0
901 {
902 # This is the last resource
903 $len = $pdb->{_size} -
904 0 $pdb->{_index}[$i]{offset};
905 } else {
906 # This is not the last resource
907 $len = $pdb->{_index}[$i+1]{offset} -
908 0 $pdb->{_index}[$i]{offset};
909 }
910  
911 # Read the resource
912 0 read $fh, $buf, $len;
913  
914 # Tell the real class to parse the resource data. Pass
915 # &ParseResource all of the information from the
916 # index, plus a "data" field with the raw resource
917 # data.
918 0 my $resource;
919  
920 $resource = $pdb->ParseResource(
921 0 %{$pdb->{_index}[$i]},
922 "data" => $buf,
923 );
924 0 push @{$pdb->{resources}}, $resource;
925 }
926 }
927  
928 =head2 Write
929  
930 $pdb->Write("filename");
931  
932 Invokes methods in helper classes to get the application-specific
933 parts of the database, then writes the database to the file
934 I<filename>.
935  
936 Write() uses the following helper methods:
937  
938 =over
939  
940 =item Z<>
941  
942 PackAppInfoBlock()
943  
944 =item Z<>
945  
946 PackSortBlock()
947  
948 =item Z<>
949  
950 PackResource() or PackRecord()
951  
952 =back
953  
954 =for html </DL>
955 <!-- Grrr... pod2html is broken, and doesn't terminate the list correctly -->
956  
957 See also L</HELPER CLASSES>.
958  
959 =cut
960 #' <-- For Emacs
961  
962 sub Write
963 0 ▶{
Subroutine Write: not called CC=55 SCAR=80.3
Pod documented
964 0 my $self = shift;
965 0 my $fname = shift; # Output file name
966 0 my @record_data;
967  
968 # Open file
969 0 ▶ open OFILE, "> $fname" or die "Can't write to \"$fname\": $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open OFILE, "> $fname" or die qq[Can't write to "$fname": $!\n] 0 0 0
970 0 binmode OFILE; # Write as binary file under MS-DOS
971  
972 # Get AppInfo block
973 0 my $appinfo_block = $self->PackAppInfoBlock;
974  
975 # Get sort block
976 0 my $sort_block = $self->PackSortBlock;
977  
978 0 my $index_len;
979  
980 # Get records or resources
981 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
982 {
983 # Resource database
984 0 my $resource;
985  
986 0 foreach $resource (@{$self->{resources}})
987 {
988 0 my $type;
989 my $id;
990 0 my $data;
991  
992 # Get all the stuff that goes in the index, as
993 # well as the resource data.
994 0 $type = $resource->{type};
995 0 $id = $resource->{id};
996 0 $data = $self->PackResource($resource);
997  
998 0 push @record_data, [ $type, $id, $data ];
999 }
1000 # Figure out size of index
1001 0 $index_len = $RecIndexHeaderLen +
1002 ($#record_data + 1) * $IndexRsrcLen;
1003 } else {
1004 0 my $record;
1005  
1006 0 foreach $record (@{$self->{records}})
1007 {
1008 0 my $attributes;
1009 my $id;
1010 0 my $data;
1011  
1012 # XXX - Should probably check the length of this
1013 # record and not add it to the record if it's 0.
1014  
1015 # Get all the stuff that goes in the index, as
1016 # well as the record data.
1017 0 $attributes = 0;
1018 0 ▶ if ($record->{attributes}{expunged} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{'attributes'}{'expunged'} or $record->{'attributes'}{'deleted'}) { } 0 0 0
Condition0%0/3
$record->{"attributes"}{"expunged"} or $record->{"attributes"}{"deleted"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$record->{"attributes"}{"expunged"} or $record->{"attributes"}{"deleted"}
$record->{"attributes"}{"expunged"} $record->{"attributes"}{"deleted"}
Truth table0%0/3
A or B
A= $record->{"attributes"}{"expunged"}B= $record->{"attributes"}{"deleted"}
ABresult
1X1
011
000
1019 $record->{attributes}{deleted})
1020 {
1021 $attributes |= 0x08
1022 0 ▶ if $record->{attributes}{archive};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"archive"} 0 0 0
1023 } else {
1024 0 $attributes = ($record->{category} & 0x0f);
1025 }
1026 $attributes |= 0x80
1027 0 ▶ if $record->{attributes}{expunged};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"expunged"} 0 0 0
1028 $attributes |= 0x40
1029 0 ▶ if $record->{attributes}{dirty};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"dirty"} 0 0 0
1030 $attributes |= 0x20
1031 0 ▶ if $record->{attributes}{deleted};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"deleted"} 0 0 0
1032 $attributes |= 0x10
1033 0 ▶ if $record->{attributes}{private};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"private"} 0 0 0
1034  
1035 0 ▶ $attributes |= 0x80 if $record->{'attributes'}{'Delete'};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"Delete"} 0 0 0
1036 0 ▶ $attributes |= 0x40 if $record->{'attributes'}{'Dirty'};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"Dirty"} 0 0 0
1037 0 ▶ $attributes |= 0x20 if $record->{'attributes'}{'Busy'};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"Busy"} 0 0 0
1038 0 ▶ $attributes |= 0x10 if $record->{'attributes'}{'Secret'};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"attributes"}{"Secret"} 0 0 0
1039  
1040 0 $id = $record->{id};
1041  
1042 0 $data = $self->PackRecord($record);
1043  
1044 0 push @record_data, [ $attributes, $id, $data ];
1045 }
1046 # Figure out size of index
1047 0 $index_len = $RecIndexHeaderLen +
1048 ($#record_data + 1) * $IndexRecLen;
1049 }
1050  
1051 0 my $header;
1052 0 my $attributes = 0x0000;
1053 0 my $appinfo_offset;
1054 my $sort_offset;
1055  
1056 # Build attributes field
1057 $attributes =
1058 ($self->{attributes}{resource} ? 0x0001 : 0) |
1059 ($self->{attributes}{"read-only"} ? 0x0002 : 0) |
1060 ($self->{attributes}{"AppInfo dirty"} ? 0x0004 : 0) |
1061 ($self->{attributes}{backup} ? 0x0008 : 0) |
1062 ($self->{attributes}{"OK newer"} ? 0x0010 : 0) |
1063 ($self->{attributes}{reset} ? 0x0020 : 0) |
1064 0 ▶ ($self->{attributes}{open} ? 0x8000 : 0);
Branch: 7 branches
BranchTrueFalseTotal
$self->{'attributes'}{'resource'} ? : 0 0 0
$self->{'attributes'}{'read-only'} ? : 0 0 0
$self->{'attributes'}{'AppInfo dirty'} ? : 0 0 0
$self->{'attributes'}{'backup'} ? : 0 0 0
$self->{'attributes'}{'OK newer'} ? : 0 0 0
$self->{'attributes'}{'reset'} ? : 0 0 0
$self->{'attributes'}{'open'} ? : 0 0 0
1065  
1066 0 ▶ $attributes |= 0x0001 if $self->{'attributes'}{'ResDB'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"ResDB"} 0 0 0
1067 0 ▶ $attributes |= 0x0002 if $self->{'attributes'}{'ReadOnly'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"ReadOnly"} 0 0 0
1068 0 ▶ $attributes |= 0x0004 if $self->{'attributes'}{'AppInfoDirty'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"AppInfoDirty"} 0 0 0
1069 0 ▶ $attributes |= 0x0008 if $self->{'attributes'}{'Backup'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Backup"} 0 0 0
1070 0 ▶ $attributes |= 0x0010 if $self->{'attributes'}{'OKToInstallNewer'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"OKToInstallNewer"} 0 0 0
1071 0 ▶ $attributes |= 0x0020 if $self->{'attributes'}{'ResetAfterInstall'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"ResetAfterInstall"} 0 0 0
1072 0 ▶ $attributes |= 0x0040 if $self->{'attributes'}{'CopyPrevention'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"CopyPrevention"} 0 0 0
1073 0 ▶ $attributes |= 0x0080 if $self->{'attributes'}{'Stream'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Stream"} 0 0 0
1074 0 ▶ $attributes |= 0x0100 if $self->{'attributes'}{'Hidden'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Hidden"} 0 0 0
1075 0 ▶ $attributes |= 0x0200 if $self->{'attributes'}{'LaunchableData'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"LaunchableData"} 0 0 0
1076 0 ▶ $attributes |= 0x0400 if $self->{'attributes'}{'Recyclable'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Recyclable"} 0 0 0
1077 0 ▶ $attributes |= 0x0800 if $self->{'attributes'}{'Bundle'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Bundle"} 0 0 0
1078 0 ▶ $attributes |= 0x8000 if $self->{'attributes'}{'Open'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attributes"}{"Open"} 0 0 0
1079  
1080  
1081 # Calculate AppInfo block offset
1082 0 ▶ if ((!defined($appinfo_block)) || ($appinfo_block eq ""))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $appinfo_block or $appinfo_block eq '') { } 0 0 0
Condition0%0/3
not defined $appinfo_block or $appinfo_block eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $appinfo_block or $appinfo_block eq ""
not defined $appinfo_block $appinfo_block eq ""
Truth table0%0/3
not(A) or B
A= not defined $appinfo_blockB= $appinfo_block eq ""
ABresult
1X1
011
000
1083 {
1084 # There's no AppInfo block
1085 0 $appinfo_offset = 0;
1086 } else {
1087 # Offset of AppInfo block from start of file
1088 0 $appinfo_offset = $HeaderLen + $index_len + 2;
1089 }
1090  
1091 # Calculate sort block offset
1092 0 ▶ if ((!defined($sort_block)) || ($sort_block eq ""))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sort_block or $sort_block eq '') { } 0 0 0
Condition0%0/3
not defined $sort_block or $sort_block eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $sort_block or $sort_block eq ""
not defined $sort_block $sort_block eq ""
Truth table0%0/3
not(A) or B
A= not defined $sort_blockB= $sort_block eq ""
ABresult
1X1
011
000
1093 {
1094 # There's no sort block
1095 0 $sort_offset = 0;
1096 } else {
1097 # Offset of sort block...
1098 0 ▶ if ($appinfo_offset == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($appinfo_offset == 0) { } 0 0 0
1099 {
1100 # ...from start of file
1101 0 $sort_offset = $HeaderLen + $index_len + 2;
1102 } else {
1103 # ...or just from start of AppInfo block
1104 0 $sort_offset = $appinfo_offset +
1105 length($appinfo_block);
1106 }
1107 }
1108  
1109 # Write header
1110 $header = pack "a32 n n N N N N N N a4 a4 N",
1111 $self->{name},
1112 $attributes,
1113 $self->{version},
1114 $self->{ctime} + $EPOCH_1904,
1115 $self->{mtime} + $EPOCH_1904,
1116 $self->{baktime} + $EPOCH_1904,
1117 $self->{modnum},
1118 $appinfo_offset,
1119 $sort_offset,
1120 $self->{type},
1121 $self->{creator},
1122 0 $self->{uniqueIDseed};
1123 ;
1124  
1125 0 print OFILE "$header";
1126  
1127 # Write index header
1128 0 my $index_header;
1129  
1130 0 $index_header = pack "N n", 0, ($#record_data+1);
1131 0 print OFILE "$index_header";
1132  
1133 # Write index
1134 0 my $rec_offset; # Offset of next record/resource
1135  
1136 # Calculate offset of first record/resource
1137 0 ▶ if ($sort_offset != 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($sort_offset != 0) { } 0 0 0
elsif ($appinfo_offset != 0) { } 0 0 0
1138 {
1139 0 $rec_offset = $sort_offset + length($sort_block);
1140 } elsif ($appinfo_offset != 0)
1141 {
1142 0 $rec_offset = $appinfo_offset + length($appinfo_block);
1143 } else {
1144 0 $rec_offset = $HeaderLen + $index_len + 2;
1145 }
1146  
1147 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
1148 {
1149 # Resource database
1150 # Record database
1151 0 my $rsrc_data;
1152  
1153 0 foreach $rsrc_data (@record_data)
1154 {
1155 0 my $type;
1156 my $id;
1157 0 my $data;
1158 0 my $index_data;
1159  
1160 0 ($type, $id, $data) = @{$rsrc_data};
1161 0 $index_data = pack "a4 n N",
1162 $type,
1163 $id,
1164 $rec_offset;
1165 0 print OFILE "$index_data";
1166  
1167 0 $rec_offset += length($data);
1168 }
1169 } else {
1170 # Record database
1171 0 my $rec_data;
1172  
1173 0 foreach $rec_data (@record_data)
1174 {
1175 0 my $attributes;
1176 my $data;
1177 0 my $id;
1178 0 my $index_data;
1179  
1180 # XXX - Probably shouldn't write this record if
1181 # length($data) == 0
1182 0 ($attributes, $id, $data) = @{$rec_data};
1183  
1184 0 ▶ if (length($data) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $data == 0) 0 0 0
1185 {
1186 0 warn printf("Write: Warning: record 0x%08x has length 0\n", $id)
1187 }
1188  
1189 0 $index_data = pack "N C C3",
1190 $rec_offset,
1191 $attributes,
1192 ($id >> 16) & 0xff,
1193 ($id >> 8) & 0xff,
1194 $id & 0xff;
1195 0 print OFILE "$index_data";
1196  
1197 0 $rec_offset += length($data);
1198 }
1199 }
1200  
1201 # Write the two NULs
1202 0 ▶ if (length($self->{"2NULs"}) == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{'2NULs'} == 2) { } 0 0 0
1203 {
1204 0 print OFILE $self->{"2NULs"};
1205 } else {
1206 0 print OFILE "\0\0";
1207 }
1208  
1209 # Write AppInfo block
1210 0 ▶ print OFILE $appinfo_block unless $appinfo_offset == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $appinfo_offset == 0 0 0 0
1211  
1212 # Write sort block
1213 0 ▶ print OFILE $sort_block unless $sort_offset == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $sort_offset == 0 0 0 0
1214  
1215 # Write record/resource list
1216 0 my $record;
1217 0 foreach $record (@record_data)
1218 {
1219 0 my $data;
1220  
1221 0 ▶ if ($self->{attributes}{resource} || $self->{'attributes'}{'ResDB'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'attributes'}{'resource'} or $self->{'attributes'}{'ResDB'}) { } 0 0 0
Condition0%0/3
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"attributes"}{"resource"} or $self->{"attributes"}{"ResDB"}
$self->{"attributes"}{"resource"} $self->{"attributes"}{"ResDB"}
Truth table0%0/3
A or B
A= $self->{"attributes"}{"resource"}B= $self->{"attributes"}{"ResDB"}
ABresult
1X1
011
000
1222 {
1223 # Resource database
1224 0 my $type;
1225 my $id;
1226  
1227 0 ($type, $id, $data) = @{$record};
1228 } else {
1229 0 my $attributes;
1230 my $id;
1231  
1232 0 ($attributes, $id, $data) = @{$record};
1233 }
1234 0 print OFILE $data;
1235 }
1236  
1237 0 close OFILE;
1238 }
1239  
1240 =head2 new_Record
1241  
1242 $record = Palm::PDB->new_Record();
1243 $record = new_Record Palm::PDB;
1244  
1245 Creates a new record, with the bare minimum needed:
1246  
1247 $record->{'category'}
1248 $record->{'attributes'}{'Dirty'}
1249 $record->{'id'}
1250  
1251 The ``Dirty'' attribute is originally set, since this function will
1252 usually be called to create records to be added to a database.
1253  
1254 C<new_Record> does B<not> add the new record to a PDB. For that,
1255 you want C<append_Record>.
1256  
1257 =cut
1258  
1259 # PDB::new_Record()
1260 # Create a new, initialized record, and return a reference to it.
1261 # The record is initially marked as being dirty, since that's usually
1262 # the Right Thing.
1263 sub new_Record
1264 0 ▶{
Subroutine new_Record: not called CC=1 SCAR=6.9
Pod documented
1265 0 my $classname = shift;
1266 0 my $retval = {};
1267  
1268 # Initialize the record
1269 0 $retval->{'category'} = 0; # Unfiled, by convention
1270 0 $retval->{'attributes'} = {
1271 # expunged => 0,
1272 dirty => 1, # Note: originally dirty
1273 'Dirty' => 1,
1274 # deleted => 0,
1275 # private => 0,
1276 # archive => 0,
1277 };
1278 0 $retval->{'id'} = 0; # Initially, no record ID
1279  
1280 0 return $retval;
1281 }
1282  
1283 =head2 append_Record
1284  
1285 $record = $pdb->append_Record;
1286 $record2 = $pdb->append_Record($record1);
1287  
1288 If called without any arguments, creates a new record with
1289 L<new_Record()|/new_Record>, and appends it to $pdb.
1290  
1291 If given a reference to a record, appends that record to
1292 @{$pdb->{records}}.
1293  
1294 Returns a reference to the newly-appended record.
1295  
1296 This method updates $pdb's "last modification" time.
1297  
1298 =cut
1299 #'
1300  
1301 # append_Record
1302 # Append the given records to the database's list of records. If no
1303 # records are given, create one, append it, and return a reference to
1304 # it.
1305 sub append_Record
1306 0 ▶{
Subroutine append_Record: not called CC=2 SCAR=17.9
Pod documented
1307 0 my $self = shift;
1308  
1309 0 ▶ if ($#_ < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 0) 0 0 0
1310 {
1311 # No arguments given. Create a new record.
1312 0 my $record = $self->new_Record;
1313  
1314 0 push @{$self->{records}}, $record;
1315  
1316 # Update the "last modification time".
1317 0 $self->{mtime} = time;
1318  
1319 0 return $record;
1320 }
1321  
1322 # At least one argument was given. Append all of the arguments
1323 # to the list of records, and return the first one.
1324 0 push @{$self->{records}}, @_;
1325  
1326 # Update the "last modification time".
1327 0 $self->{mtime} = time;
1328  
1329 0 return $_[0];
1330 }
1331  
1332 =head2
1333  
1334 $resource = Palm::PDB->new_Resource();
1335 $resource = new_Resource Palm::PDB;
1336  
1337 Creates a new resource and initializes
1338  
1339 $resource->{type}
1340 $resource->{id}
1341  
1342 =cut
1343  
1344 # new_Resource
1345 # Create a new, initialized resource, and return a reference to it.
1346 sub new_Resource
1347 0 ▶{
Subroutine new_Resource: not called CC=1 SCAR=6.9
Pod undocumented
1348 0 my $classname = shift;
1349 0 my $retval = {};
1350  
1351 # Initialize the resource
1352 0 $retval->{type} = "\0\0\0\0";
1353 0 $retval->{id} = 0;
1354  
1355 0 return $retval;
1356 }
1357  
1358 =head2 append_Resource
1359  
1360 $resource = $pdb->append_Resource;
1361 $resource2 = $pdb->append_Resource($resource1);
1362  
1363 If called without any arguments, creates a new resource with
1364 L<new_Resource()|/new_Resource>, and appends it to $pdb.
1365  
1366 If given a reference to a resource, appends that resource to
1367 @{$pdb->{resources}}.
1368  
1369 Returns a reference to the newly-appended resource.
1370  
1371 This method updates $pdb's "last modification" time.
1372  
1373 =cut
1374 #'
1375  
1376 # append_Resource
1377 # Append the given resources to the database's list of resources. If no
1378 # resources are given, create one, append it, and return a reference to
1379 # it.
1380 sub append_Resource
1381 0 ▶{
Subroutine append_Resource: not called CC=2 SCAR=17.9
Pod documented
1382 0 my $self = shift;
1383  
1384 0 ▶ if ($#_ < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 0) 0 0 0
1385 {
1386 # No arguments given. Create a new resource
1387 0 my $resource = $self->new_Resource;
1388  
1389 0 push @{$self->{resources}}, $resource;
1390  
1391 # Update the "last modification time".
1392 0 $self->{mtime} = time;
1393  
1394 0 return $resource;
1395 }
1396  
1397 # At least one argument was given. Append all of the arguments
1398 # to the list of resources, and return the first one.
1399 0 push @{$self->{resources}}, @_;
1400  
1401 # Update the "last modification time".
1402 0 $self->{mtime} = time;
1403  
1404 0 return $_[0];
1405 }
1406  
1407 =head2 findRecordByID
1408  
1409 $record = $pdb->findRecordByID($id);
1410  
1411 Looks through the list of records in $pdb, and returns a reference to
1412 the record with ID $id, or the undefined value if no such record was
1413 found.
1414  
1415 =cut
1416  
1417 # findRecordByID
1418 # Returns a reference to the record with the given ID, or 'undef' if
1419 # it doesn't exist.
1420 sub findRecordByID
1421 0 ▶{
Subroutine findRecordByID: not called CC=4 SCAR=30.0
Pod documented
1422 0 my $self = shift;
1423 0 my $id = shift;
1424  
1425 0 ▶ return undef if $id eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "" 0 0 0
1426  
1427 0 for (@{$self->{records}})
1428 {
1429 0 ▶ next unless $_->{id} == $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"id"} == $id 0 0 0
1430 0 return $_; # Found it
1431 }
1432  
1433 0 return undef; # Not found
1434 }
1435  
1436 =head2 delete_Record
1437  
1438 $pdb->delete_Record($record, $expunge);
1439  
1440 Marks $record for deletion, so that it will be deleted from the
1441 database at the next sync.
1442  
1443 If $expunge is false or omitted, the record will be marked
1444 for deletion with archival. If $expunge is true, the record will be
1445 marked for deletion without archival.
1446  
1447 This method updates $pdb's "last modification" time.
1448  
1449 =cut
1450 #'
1451  
1452 # delete_Record
1453 # $pdb->delete_Record($record ?, $expunge?)
1454 #
1455 # Mark the given record for deletion. If $expunge is true, mark the
1456 # record for deletion without an archive.
1457  
1458 sub delete_Record
1459 0 ▶{
Subroutine delete_Record: not called CC=2 SCAR=17.9
Pod documented
1460 0 my $self = shift;
1461 0 my $record = shift;
1462 0 my $expunge = shift;
1463  
1464 0 $record->{attributes}{deleted} = 1;
1465 0 ▶ if ($expunge)
Branch: 1 branch
BranchTrueFalseTotal
if ($expunge) { } 0 0 0
1466 {
1467 0 $record->{attributes}{expunged} = 1;
1468 0 $record->{attributes}{archive} = 0;
1469 } else {
1470 0 $record->{attributes}{expunged} = 0;
1471 0 $record->{attributes}{archive} = 1;
1472 }
1473  
1474 # Update the "last modification time".
1475 0 $self->{mtime} = time;
1476 }
1477  
1478 1 1;
1479  
1480 __END__
↑ Summary Datebook.pm »