Python::Serialise::Marshal - a module for reading and writing marshalled Python files
use Python::Serialise::Marshal;
my $pr = Python::Serialise::Marshal->new("file/for/reading");
while (my $data = $pr->load()) {
print Dumper $data;
}
my $pw = Python::Serialise::Marshal->new(">file/for/writing");
$pw->dump(['a' 'list']);
$pw->dump("a string");
$pw->dump(42);
$pw->dump({'a'=>'hash'});
$pw->close();
Marshalling is a method of serialising files in Python (another method, Pickling, is also available). It is the method that Mailman uses to store its config files.
This module is an attempt to write a pure Perl implementation of the algorithm.
Open a file for reading or writing. Can take any arguments that IO::File can.
Returns the next data structure from the marshalled file or undef.
Takes a ref to an array or a hash or a number or string and pickles it.
Structures may be nested.
Closes the current file.
Python has inbuilt support form complex numbers whilst Perl
provides it through the core module Math::Complex. Unserialising
a Python complex number will return a Math::Complex object
and, as you'd expect, serialising something that ISA Math::Complex
will result in a serialised Python complex number.
Python has None objects, similar to Perl's undef.
Because load indictaes "no more objects" by returning undef
we have to return Python::Serialise::None objects. However dump can
take undef and serialise it as a None object.
Much less than my Pickle module because this is a
much saner file format.
I can't think of a nice elegant way of doing tests at the moment.
I'm sure I will soon.
You could always dump the data structure out as YAML in Python and then read it back in with YAML in Perl.
I also may look into wrapping the Python source code file in XS.
Simon Wistow <simon@thegestalt.org>
(c) 2003 Simon Wistow
Distributed under the same terms as Perl itself.
This software is under no warranty and will probably ruin your life, kill your friends, burn your house and bring about the apocalypse.
http://www.python.org, YAML, File::Binary, Math::Complex and the RESOURCES file in this distribution.