[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [coldsync-hackers] p5-palm
> But Palm::PDB has to decide, at some point, how to parse the
> database records. One obvious approach is to extract the creator/type and
> pass the buck to a set of specialized functions. This is what the current
> Palm::PDB does.
> The other obvious approach would be to read the PDB without
> parsing the records, i.e., return a list of data strings. Then have the
> user's script call some set of specialized functions to parse those
> strings. This strikes me as inelegant and wasteful.
What i'm suggesting is that Palm::PDB does just do it in the basic mannor,
and then the application programmer, when writting my code to read through
the datebase(s), will create a class which inherrits from Palm::PDB, and
overloads the functions like ParseRecord and so on. Anything dealling with
the "real" data in the database should be overloaded. Also give the ability to
choose which handler via a Palm::Manager, and you are all set.
Therefore you have, IMO, an intuitive, elegant, object-oriented way to handle
PDB files.
I think that the base Palm::PDB class still handles all the low-level details,
like reading in the database header info, and then getting all indexes, and
managing things like "findRecordByID". I'm just think that the base class
would find the record, and return ParseRecord on the data returned by this
function. The base ParseRecord would do nothing but return the plain data.
However, in a class which inherritted the Palm::PDB file, would re-write the
ParseRecord to do something intelligent. And it would need to re-write
PackRecord, etc to do any writing to files.
My hope is that this can become even easier. I would hope that eventually
something like this could happen:
package Palm::Whatever;
use Palm::PDB;
use vars qw/@ISA/;
@ISA = qw( Palm::PDB );
my $SCHEMA = [ ## "data_type", "data_name", "array_length" (default=1)
[ "byte" , "name", 32 ],
[ "byte" , "version" ],
[ "Ulong", "firstVGARec" ]
...
];
sub load {
my $class_name = shift;
$class_name = ref $class_name || $class_name;
bless load Palm::PDB( shift(@_), $SCHEMA ), $class_name;
}
And make the default Palm::PDB's ParseRecord, PackRecord, etc a little smarter
and be able to check if the $SCHEMA has been given. If so, parse based on that.
An bad example implementation:
#
# Parses Record's based on schema if one was given.
# Else return the raw data.
# The function might be overloaded.
#
sub ParseRecord {
my $self = shift;
my $ref_to_data = shift;
if (! exists $self->{RECORD_SCHEMA} ) {
return $ref_to_data->{raw}; ## perhaps return $ret_to_data instead.
} else {
## parse the record based on schema.
## probably have modified the SCHEMA given to get offset's/lengths,etc,
## but.. those are details to be worked out yet.
}
}
Anyways, that's enough for now.
Ryan
--
Ryan VanderBijl http://www.calvin.edu/~rvbijl39
--
This message was sent through the coldsync-hackers mailing list. To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body. For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.