Palm/ToDo.pm

filter: Statementstmt 49.4% 47 / 95 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 100% 6 / 6 totaltotal 51.6% 63 / 122 CC 6 SCAR 14.3
CC
6
Cov
48%
PackRecord
12.0
ParseRecord
4.7
new
2.0
CRAP 4.2
« Palm/ZirePhoto.pm ↑ Summary Palm/DateTime.pm »
1 package Palm::ToDo;
2 #
3 # ABSTRACT: Handler for Palm ToDo databases
4 #
5 # Copyright (C) 1999, 2000, Andrew Arensburger.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the same terms as Perl itself.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
13 # GNU General Public License or the Artistic License for more details.
14  
15 # XXX - Bug: apparently, the first ToDo item shows up with a category
16 # of "unfiled"
17  
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Palm::Raw();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Palm::StdAppInfo();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use vars qw( $VERSION @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # One liner, to allow MakeMaker to work.
25 3 $VERSION = '1.400';
26 # This file is part of Palm 1.400 (March 14, 2015)
27  
28 3 @ISA = qw( Palm::StdAppInfo Palm::Raw );
29  
30 #'
31  
32 sub import
33 2 ▶{
Subroutine import: called CC=1 SCAR=0.0
34 2 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
35 [ "todo", "DATA" ],
36 );
37 }
38  
39 #'
40  
41 # new
42 # Create a new Palm::ToDo database, and return it
43 sub new
44 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
45 0 my $classname = shift;
46 0 my $self = $classname->SUPER::new(@_);
47 # Create a generic PDB. No need to rebless it,
48 # though.
49  
50 0 $self->{name} = "ToDoDB"; # Default
51 0 $self->{creator} = "todo";
52 0 $self->{type} = "DATA";
53 0 $self->{attributes}{resource} = 0;
54 # The PDB is not a resource database by
55 # default, but it's worth emphasizing,
56 # since ToDoDB is explicitly not a PRC.
57  
58 # Initialize the AppInfo block
59 $self->{appinfo} = {
60 0 dirty_appinfo => undef, # ?
61 sortOrder => undef, # ?
62 };
63  
64 # Add the standard AppInfo block stuff
65 0 &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo});
66  
67 # Give the PDB a blank sort block
68 0 $self->{sort} = undef;
69  
70 # Give the PDB an empty list of records
71 0 $self->{records} = [];
72  
73 0 return $self;
74 }
75  
76  
77 # new_Record
78 # Create a new, initialized record.
79 sub new_Record
80 0 ▶{
Subroutine new_Record: not called CC=1 SCAR=6.9
Pod documented
81 0 my $classname = shift;
82 0 my $retval = $classname->SUPER::new_Record(@_);
83  
84 # Item has no due date by default.
85 0 $retval->{due_day} = undef;
86 0 $retval->{due_month} = undef;
87 0 $retval->{due_year} = undef;
88  
89 0 $retval->{completed} = 0; # Not completed
90 0 $retval->{priority} = 1;
91  
92 # Empty description, no note.
93 0 $retval->{description} = "";
94 0 $retval->{note} = undef;
95  
96 0 return $retval;
97 }
98  
99 # ParseAppInfoBlock
100 # Parse the AppInfo block for ToDo databases.
101 sub ParseAppInfoBlock
102 1 ▶{
Subroutine ParseAppInfoBlock: called CC=1 SCAR=0.0
Pod documented
103 1 my $self = shift;
104 1 my $data = shift;
105 1 my $dirtyAppInfo;
106 my $sortOrder;
107 1 my $appinfo = {};
108 1 my $std_len;
109  
110 # Get the standard parts of the AppInfo block
111 1 $std_len = &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
112  
113 1 $data = $appinfo->{other}; # Look at the non-category part
114  
115 # Get the rest of the AppInfo block
116 1 my $unpackstr = # Argument to unpack()
117 "x2" . # Reserved
118 "n" . # XXX - Dirty AppInfo (what is this?)
119 "Cx"; # Sort order
120  
121 1 ($dirtyAppInfo, $sortOrder) = unpack $unpackstr, $data;
122  
123 1 $appinfo->{dirty_appinfo} = $dirtyAppInfo;
124 1 $appinfo->{sort_order} = $sortOrder;
125  
126 1 return $appinfo;
127 }
128  
129 sub PackAppInfoBlock
130 0 ▶{
Subroutine PackAppInfoBlock: not called CC=1 SCAR=6.9
Pod documented
131 0 my $self = shift;
132 0 my $retval;
133  
134 # Pack the application-specific part of the AppInfo block
135 $self->{appinfo}{other} = pack("x2 n Cx",
136 $self->{appinfo}{dirty_appinfo},
137 0 $self->{appinfo}{sort_order});
138  
139 # Pack the AppInfo block
140 0 $retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo});
141  
142 0 return $retval;
143 }
144  
145 sub ParseRecord
146 1 ▶{
Subroutine ParseRecord: called CC=4 SCAR=15.5
Pod documented
147 1 my $self = shift;
148 1 my %record = @_;
149 1 my $data = $record{data};
150  
151 1 delete $record{offset}; # This is useless
152 1 delete $record{data}; # No longer necessary
153  
154 1 my $date;
155 my $priority;
156  
157 1 ($date, $priority) = unpack "n C", $data;
158 1 $data = substr $data, 3; # Remove the stuff we've already seen
159  
160 1 ▶ if ($date != 0xffff)
Branch: 1 branch
BranchTrueFalseTotal
if ($date != 65535) 0 1 1
161 {
162 0 my $day;
163 my $month;
164 0 my $year;
165  
166 0 $day = $date & 0x001f; # 5 bits
167 0 $month = ($date >> 5) & 0x000f; # 4 bits
168 0 $year = ($date >> 9) & 0x007f; # 7 bits (years since 1904)
169 0 $year += 1904;
170  
171 0 $record{due_day} = $day;
172 0 $record{due_month} = $month;
173 0 $record{due_year} = $year;
174 }
175  
176 1 my $completed; # Boolean
177  
178 1 $completed = $priority & 0x80;
179 1 $priority &= 0x7f; # Strip high bit
180  
181 1 ▶ $record{completed} = 1 if $completed;
Branch: 1 branch
BranchTrueFalseTotal
if $completed 0 1 1
182 1 $record{priority} = $priority;
183  
184 1 my $description;
185 my $note;
186  
187 1 ($description, $note) = split /\0/, $data;
188  
189 1 $record{description} = $description;
190 1 ▶ $record{note} = $note unless $note eq "";
Branch: 1 branch
BranchTrueFalseTotal
unless $note eq "" 1 0 1
191  
192 1 return \%record;
193 }
194  
195 sub PackRecord
196 0 ▶{
Subroutine PackRecord: not called CC=3 SCAR=24.8
Pod documented
197 0 my $self = shift;
198 0 my $record = shift;
199 0 my $retval;
200 my $rawDate;
201 0 my $priority;
202  
203 0 ▶ if (defined($record->{due_day}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $record->{'due_day'}) { } 0 0 0
204 {
205 $rawDate = ($record->{due_day} & 0x001f) |
206 (($record->{due_month} & 0x000f) << 5) |
207 0 ((($record->{due_year} - 1904) & 0x007f) << 9);
208 } else {
209 0 $rawDate = 0xffff;
210 }
211 0 $priority = $record->{priority} & 0x7f;
212 0 ▶ $priority |= 0x80 if $record->{completed};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"completed"} 0 0 0
213  
214 0 $retval = pack "n C",
215 $rawDate,
216 $priority;
217 0 $retval .= $record->{description} . "\0";
218 0 $retval .= $record->{note} . "\0";
219  
220 0 return $retval;
221 }
222  
223 3 1;
224  
225 __END__
« Palm/ZirePhoto.pm ↑ Summary Palm/DateTime.pm »