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


Class-Serializer documentation  | view source Contained in the Class-Serializer distribution.

Index


NAME

Top

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

VERSION

Top

Version 0.03

SYNOPSIS

Top

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

Top

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

Top

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

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

AUTHOR

Top

Nilson Santos Figueiredo Júnior, <nilsonsfj at cpan.org>

BUGS

Top

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

SUPPORT

Top

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Class-Serializer

* CPAN Ratings

http://cpanratings.perl.org/d/Class-Serializer

* Search CPAN

http://search.cpan.org/dist/Class-Serializer

SEE ALSO

Top

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

COPYRIGHT & LICENSE

Top


Class-Serializer documentation  | view source Contained in the Class-Serializer distribution.