NAME

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

VERSION

Version 0.01

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::Dumper which, in turn, relies on B::Deparse for CODEREF deparsing.

The most important thing, however, is to keep in mind that this module is highly experimental. There are no guarantees whatsoever about the generated code.

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.

This currently doesn't work for classes that keep a lot of lexical data such as closures or inside-out objects. This problem is hard to solve since heavy XS magic will probably be needed.

AUTHOR

Nilson Santos Figueiredo Júnior, <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::Dumper, B::Deparse

COPYRIGHT & LICENSE

Copyright 2008 Nilson Santos Figueiredo Júnior, all rights reserved.

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 169:

Non-ASCII character seen before =encoding in 'Júnior,'. Assuming CP1252