The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::Serializer - Serializes the in-memory state of a class into code

VERSION

Version 0.04

SYNOPSIS

This module does its best efforts to serialize the in-memory state of a class into runable code. For this to actually happen successfully it relies heavily on Data::Dump::Streamer which, in turn, relies on B::Deparse for CODEREF deparsing and other similar tasks.

Please, keep in mind that this module is experimental. There are no guarantees whatsoever about the generated code.

With that said, it should work just fine.

Here's a little a code snippet:

    use Class::Serializer;
    
    # Class::Serializer is Class::Serializer safe
    my $class_code = Class::Serializer->as_string('Class::Serializer');
    
    # writes directly to ClassSerializer.pm
    Class::Serializer->as_file(Class::Serializer => 'ClassSerializer.pm');

CLASS METHODS

as_string($target_class)

Serializes $target_class in-memory state (actually, symbol table entries) into perl code and returns it as a string. It will also try to detect possible dependencies and try to honor them through require statements in the generated code.

as_file($target_class, [$file_name, [$overwrite]])

Serializes $target_class in-memory state into perl code and saves it into $file_name, overwriting the file if $overwrite is set to a true value.

If $file_name is not defined, it will be constructed based on the target class name, relative do the current path. So Class::Serializer would be saved in Class/Serializer.pm.

If $file_name exists and $overwrite is not set, an exception is thrown. An exception is also thrown if the file is not writable.

CAVEATS

The dependency detecting code is pretty simple and may be not very reliable.

Closures should work just fine as of version 0.04. This feature wasn't tested extensively, though (it just relies on Data::Dump::Streamer for that).

AUTHOR

Nilson Santos Figueiredo Junior, <nilsonsfj at cpan.org>

BUGS

Please report any bugs or feature requests directly to the author. If you ask nicely it will probably get fixed or implemented.

SUPPORT

You can also look for information at:

SEE ALSO

Data::Dump::Streamer, B::Deparse

COPYRIGHT & LICENSE

Copyright 2008 Nilson Santos Figueiredo Junior, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.