Memo.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 81 CC 1 SCAR 6.9
CC
1
Cov
0%
import
2.0
new
2.0
new_Record
2.0
CRAP 2.0
1 # Palm::Memo.pm
2 #
3 # Perl class for dealing with Palm Memo databases.
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: Memo.pm,v 1.13 2002/11/07 14:12:05 arensb Exp $
10  
11 use strict;
12 package Palm::Memo;
13 use Palm::Raw();
14 use Palm::StdAppInfo();
15 use vars qw( $VERSION @ISA );
16  
17 # One liner, to allow MakeMaker to work.
18 $VERSION = do { my @r = (q$Revision: 1.13 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
19  
20 @ISA = qw( Palm::StdAppInfo Palm::Raw );
21  
22 =head1 NAME
23  
24 Palm::Memo - Handler for Palm Memo databases.
25  
26 =head1 SYNOPSIS
27  
28 use Palm::Memo;
29  
30 =head1 DESCRIPTION
31  
32 The Memo PDB handler is a helper class for the Palm::PDB package. It
33 parses Memo databases.
34  
35 =head2 AppInfo block
36  
37 The AppInfo block begins with standard category support. See
38 L<Palm::StdAppInfo> for details.
39  
40 Other fields include:
41  
42 $pdb->{appinfo}{sortOrder}
43  
44 I don't know what this is.
45  
46 =head2 Sort block
47  
48 $pdb->{sort}
49  
50 This is a scalar, the raw data of the sort block.
51  
52 =head2 Records
53  
54 $record = $pdb->{records}[N]
55  
56 $record->{data}
57  
58 A string, the text of the memo.
59  
60 =cut
61 #'
62  
63 sub import
64 {
65 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
66 [ "memo", "DATA" ],
67 );
68 }
69  
70 =head2 new
71  
72 $pdb = new Palm::Memo;
73  
74 Create a new PDB, initialized with the various Palm::Memo fields
75 and an empty record list.
76  
77 Use this method if you're creating a Memo PDB from scratch.
78  
79 =cut
80 #'
81 sub new
82 {
83 my $classname = shift;
84 my $self = $classname->SUPER::new(@_);
85 # Create a generic PDB. No need to rebless it,
86 # though.
87  
88 $self->{name} = "MemoDB"; # Default
89 $self->{creator} = "memo";
90 $self->{type} = "DATA";
91 $self->{attributes}{resource} = 0;
92 # The PDB is not a resource database by
93 # default, but it's worth emphasizing,
94 # since MemoDB is explicitly not a PRC.
95  
96 # Initialize the AppInfo block
97 $self->{appinfo} = {
98 sortOrder => undef, # XXX - ?
99 };
100  
101 # Add the standard AppInfo block stuff
102 &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo});
103  
104 # Give the PDB a blank sort block
105 $self->{sort} = undef;
106  
107 # Give the PDB an empty list of records
108 $self->{records} = [];
109  
110 return $self;
111 }
112  
113 =head2 new_Record
114  
115 $record = $pdb->new_Record;
116  
117 Creates a new Memo record, with blank values for all of the fields.
118  
119 C<new_Record> does B<not> add the new record to C<$pdb>. For that,
120 you want C<$pdb-E<gt>append_Record>.
121  
122 =cut
123  
124 sub new_Record
125 {
126 my $classname = shift;
127 my $retval = $classname->SUPER::new_Record(@_);
128  
129 $retval->{data} = "";
130  
131 return $retval;
132 }
133  
134 # ParseAppInfoBlock
135 # Parse the AppInfo block for Memo databases.
136 sub ParseAppInfoBlock
137 {
138 my $self = shift;
139 my $data = shift;
140 my $sortOrder;
141 my $i;
142 my $appinfo = {};
143 my $std_len;
144  
145 # Get the standard parts of the AppInfo block
146 $std_len = &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
147  
148 $data = $appinfo->{other}; # Look at the non-category part
149  
150 # Get the rest of the AppInfo block
151 my $unpackstr = # Argument to unpack()
152 "x4" . # Padding
153 "C"; # Sort order
154  
155 ($sortOrder) = unpack $unpackstr, $data;
156  
157 $appinfo->{sortOrder} = $sortOrder;
158  
159 return $appinfo;
160 }
161  
162 sub PackAppInfoBlock
163 {
164 my $self = shift;
165 my $retval;
166 my $i;
167  
168 # Pack the non-category part of the AppInfo block
169 $self->{appinfo}{other} =
170 pack("x4 C x1", $self->{appinfo}{sortOrder});
171  
172 # Pack the AppInfo block
173 $retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo});
174  
175 return $retval;
176 }
177  
178 sub PackSortBlock
179 {
180 # XXX
181 return undef;
182 }
183  
184 sub ParseRecord
185 {
186 my $self = shift;
187 my %record = @_;
188  
189 delete $record{offset}; # This is useless
190 $record{data} =~ s/\0$//; # Trim trailing NUL
191  
192 return \%record;
193 }
194  
195 sub PackRecord
196 {
197 my $self = shift;
198 my $record = shift;
199  
200 return $record->{data} . "\0"; # Add the trailing NUL
201 }
202  
203 1;
204 __END__