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

NAME

Data::Rebuilder - Builds an object rebuilder.

VERSION

Version 0.01

SYNOPSIS

  ###
  ### freeze composite ...
  ###
  
  my $builder = Data::Rebuilder->new;
  $builder->parameterize( driver => $driver );
  $builder->parameterize( user   => $user );
  my $icy_compsite = $builder->build_rebulder( $composite );
  
  ###
  ### restore composite with current context ...
  ###
  
  my $builder = eval $icy_composite;
  my $melted_composite = $builder->( driver => $driver,
                                     user   => $user );

DESCRIPTION

This approach is like to Data::Dumper approach. Moreover, an output of this module is not easy to read.

However this solution can rebuild tied values, weak references, and closures. In addition, this solution can parameterize arbitrary nodes of composite. Users can give new objects as arguments of the subroutine which is result.

STATIC METHODS

safe_require
  safe_require ( $0 );                                # does not load
  safe_require ( Path::Class::file( $0 )->absolute ); # does not load
  safe_require ( 'path/to/module.pm' );               # loads
  safe_require ( '/absolute/path/to/module.pm');      # does not load

Loads module safery.

new
  my $builder = Data::Rebuilder->new;

Creates and returns new object. It does not receives any arguments.

ATTRIBUTES

poly

Contains Data::Polymorph instance.

DYNAMIC METHODS

ref_to_var
  my $var = $builder->ref_to_var( $ref ); # returns $__17898432__

Makes a reference to a variable name.

parameterize
  $builder->parameterize( a_object => $a_object );

Register an object as a parameter of rebuilders.

register_freezer
  $builder->register_freezer( 'Target::Class' => sub{ ... } );

same as

  $builder->poly->define( 'Target::Class' => freeze => sub{ ... }  );

Registers freezer method for the types (or classes).

Customization of this approach is not easy way. As other way, you can customize by register_sleep and register_module_loader.

register_sleep
  $builder->register_sleep( 'Target::Class' => sub{
    my $self = shift;
    return ( { foo  => $self->foo,
               bar  => $self->bar,
               bazz => $self->bazz } , sub{
      my $obj = shift;
      bless $obj , blessed $self;
      $obj->init;
      $obj;
    } )
  } );

Registers "sleep" method for the class.

You can drop some properties that is not necessary for the serialization by these methods.

The "sleep" method returns an object and an optional subroutine reference. They are a information for serializer and a restructuring procedure for the information. So , when rebuilding the object , a rebuilder uses these informations.

register_module_loader
  $builder->register_module_loader( 'Foo::Class' => sub{ 'require Foo;' }  );

Registers a module loader builder. The default method of this searches files from any CVs in the symbol table of the class, and builds loading code with these information.

module_loader
  # returns 'require Symbol;'
  $exp = $dumper->module_loader('Symbol');
  
  # returns 'B::Rebuilder::safe_require "/path/to/your/UNIVERSAL.pm"'
  $exp = $dumper->module_loader('UNIVERSAL');

Returns an expression which reads module for the given package name.

blank
  $exp = $dumper->blank( { foo => 'bar' } ); # returns '{}'
  $exp = $dumper->blank( [ foo => 'bar' ] ); # returns '[]'
  $exp = $dumper->blank( FileHandle->new  ); # returns 'Symbol::gensym()'

A return value of this method is for tiers.

tier
  $exp = $builder->tier( '$foo', 'TIEHANDLE', $obj );

Returns a expression which ties variable with the tied object.

freeze
  my $icy = $dumper->freeze( $obj );

Makes Perl source code which builds given object. This method should not be used from applications, because it modifies the objects state. This method should be used from extensions.

rebuilder
  my $icy = $dumper->build_rebulder( $obj );

Builds Perl source code which is object rebuilder subroutine.

SEE ALSO

Data::Dumper

AUTHOR

lieutar, <lieutar at 1dk.jp>

BUGS

Please report any bugs or feature requests to bug-data-dumper-sub at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Rebuilder. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

and...

Even if I am writing strange English because I am not good at English, I'll not often notice the matter. (Unfortunately, these cases aren't testable automatically.)

If you find strange things, please tell me the matter.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Data::Rebuilder

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2008 lieutar, all rights reserved.

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