File Coverage

blib/lib/Palm/Memo.pm
Criterion Covered Total %
statement 29 53 54.7
branch n/a
condition n/a
subroutine 7 12 58.3
pod 7 7 100.0
total 43 72 59.7


line stmt bran cond sub pod time code
1             package Palm::Memo;
2             #
3             # ABSTRACT: Read/write Palm OS Memo 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 2     2   5580 use strict;
  2         2  
  2         56  
16 2     2   401 use Palm::Raw();
  2         274  
  2         28  
17 2     2   324 use Palm::StdAppInfo();
  2         2  
  2         31  
18 2     2   8 use vars qw( $VERSION @ISA );
  2         2  
  2         807  
19              
20             # One liner, to allow MakeMaker to work.
21             $VERSION = '1.015';
22             # This file is part of Palm 1.015 (February 14, 2015)
23              
24             @ISA = qw( Palm::StdAppInfo Palm::Raw );
25              
26             #'
27              
28             sub import
29             {
30 2     2   13 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__,
31             [ "memo", "DATA" ],
32             );
33             }
34              
35             #'
36             sub new
37             {
38 0     0 1 0 my $classname = shift;
39 0         0 my $self = $classname->SUPER::new(@_);
40             # Create a generic PDB. No need to rebless it,
41             # though.
42              
43 0         0 $self->{name} = "MemoDB"; # Default
44 0         0 $self->{creator} = "memo";
45 0         0 $self->{type} = "DATA";
46 0         0 $self->{attributes}{resource} = 0;
47             # The PDB is not a resource database by
48             # default, but it's worth emphasizing,
49             # since MemoDB is explicitly not a PRC.
50              
51             # Initialize the AppInfo block
52 0         0 $self->{appinfo} = {
53             sortOrder => undef, # XXX - ?
54             };
55              
56             # Add the standard AppInfo block stuff
57 0         0 &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo});
58              
59             # Give the PDB a blank sort block
60 0         0 $self->{sort} = undef;
61              
62             # Give the PDB an empty list of records
63 0         0 $self->{records} = [];
64              
65 0         0 return $self;
66             }
67              
68              
69             sub new_Record
70             {
71 0     0 1 0 my $classname = shift;
72 0         0 my $retval = $classname->SUPER::new_Record(@_);
73              
74 0         0 $retval->{data} = "";
75              
76 0         0 return $retval;
77             }
78              
79             # ParseAppInfoBlock
80             # Parse the AppInfo block for Memo databases.
81             sub ParseAppInfoBlock
82             {
83 1     1 1 699 my $self = shift;
84 1         1 my $data = shift;
85 1         2 my $sortOrder;
86             my $i;
87 1         2 my $appinfo = {};
88 1         2 my $std_len;
89              
90             # Get the standard parts of the AppInfo block
91 1         4 $std_len = &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
92              
93 1         2 $data = $appinfo->{other}; # Look at the non-category part
94              
95             # Get the rest of the AppInfo block
96 1         2 my $unpackstr = # Argument to unpack()
97             "x4" . # Padding
98             "C"; # Sort order
99              
100 1         2 ($sortOrder) = unpack $unpackstr, $data;
101              
102 1         1 $appinfo->{sortOrder} = $sortOrder;
103              
104 1         3 return $appinfo;
105             }
106              
107             sub PackAppInfoBlock
108             {
109 0     0 1 0 my $self = shift;
110 0         0 my $retval;
111             my $i;
112              
113             # Pack the non-category part of the AppInfo block
114 0         0 $self->{appinfo}{other} =
115             pack("x4 C x1", $self->{appinfo}{sortOrder});
116              
117             # Pack the AppInfo block
118 0         0 $retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo});
119              
120 0         0 return $retval;
121             }
122              
123             sub PackSortBlock
124             {
125             # XXX
126 0     0 1 0 return undef;
127             }
128              
129             sub ParseRecord
130             {
131 4     4 1 66 my $self = shift;
132 4         6 my %record = @_;
133              
134 4         6 delete $record{offset}; # This is useless
135 4         14 $record{data} =~ s/\0$//; # Trim trailing NUL
136              
137 4         9 return \%record;
138             }
139              
140             sub PackRecord
141             {
142 0     0 1   my $self = shift;
143 0           my $record = shift;
144              
145 0           return $record->{data} . "\0"; # Add the trailing NUL
146             }
147              
148             1;
149              
150             __END__