EBook-MOBI
view release on metacpan or search on metacpan
lib/EBook/MOBI/MobiPerl/Palm/StdAppInfo.pm view on Meta::CPAN
package MyPDBHandler;
use Palm::StdAppInfo(); # Note the parentheses
@ISA = qw( Palm::StdAppInfo );
use constant APPINFO_PADDING = 1;
sub ParseAppInfoBlock {
my $self = shift;
my $data = shift;
my $appinfo = {};
&Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
$app_specific_data = $appinfo->{other};
}
sub PackAppInfoBlock {
my $self = shift;
my $retval;
$self->{appinfo}{other} = <pack application-specific data>;
$retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo});
return $retval;
}
Or as a standalone C<PDB> helper class:
use Palm::StdAppInfo;
=head1 DESCRIPTION
Many Palm applications use a common format for keeping track of categories.
The C<Palm::StdAppInfo> class deals with this common format:
$pdb = new Palm::PDB;
$pdb->Load("myfile.pdb");
@categories = @{$pdb->{appinfo}{categories}};
$lastUniqueID = $pdb->{appinfo}{lastUniqueID};
$other = $pdb->{appinfo}{other};
where:
C<@categories> is an array of references-to-hash:
=over 4
=item C<$cat = $categories[0];>
=item C<$cat-E<gt>{name}>
The name of the category, a string of at most 16 characters.
=item C<$cat-E<gt>{id}>
The category ID, an integer in the range 0-255. Each category has a
unique ID. By convention, 0 is reserved for the "Unfiled" category;
IDs assigned by the Palm are in the range 1-127, and IDs assigned by
the desktop are in the range 128-255.
=item C<$cat-E<gt>{renamed}>
A boolean. This field is true iff the category has been renamed since
the last sync.
=back
C<$lastUniqueID> is (I think) the last category ID that was assigned.
C<$other> is any data that follows the category list in the AppInfo
block. If you're writing a helper class for a PDB that includes a
category list, you should parse this field to get any data that
follows the category list; you should also make sure that this field
is initialized before you call C<&Palm::StdAppInfo::pack_AppInfo>.
=head2 APPINFO_PADDING
Normally, the AppInfo block includes a byte of padding at the end, to
bring its length to an even number. However, some databases use this
byte for data.
If your database uses the padding byte for data, then your
C<&ParseAppInfoBlock> method (see L<"SYNOPSIS">) should call
C<&parse_StdAppInfo> with a true $nopadding argument.
If, for whatever reason, you wish to inherit
C<&StdAppInfo::ParseAppInfoBlock>, then add
use constant APPINFO_PADDING => 0;
to your handler package, to tell it that the padding byte is really
data.
=head1 FUNCTIONS
=cut
#'
use constant APPINFO_PADDING => 1; # Whether to add the padding byte at
# the end of the AppInfo block.
# Note that this might be considered a hack:
# this relies on the fact that 'use constant'
# defines a function with no arguments; that
# therefore this can be called as an instance
# method, with full inheritance. That is, if
# the handler class doesn't define it, Perl
# will find the constant in the parent. If
# this ever changes, the code below that uses
# $self->APPINFO_PADDING will need to be
# changed.
use constant numCategories => 16; # Number of categories in AppInfo block
use constant categoryLength => 16; # Length of category names
use constant stdAppInfoSize => # Length of a standard AppInfo block
2 +
(categoryLength * numCategories) +
numCategories +
1 + 1; # The padding byte at the end may
# be omitted
( run in 0.905 second using v1.01-cache-2.11-cpan-bbb979687b5 )