Object::Recorder::Storage - Serializable data structure for Object::Recorder


Object-Recorder documentation Contained in the Object-Recorder distribution.

Index


Code Index:

NAME

Top

Object::Recorder::Storage - Serializable data structure for Object::Recorder

SYNOPSIS

Top

This module makes it possible to record method calls issued to a set of objects inti a serializable container which can later be replayed, perfoming the actual method calls.

CLASS METHODS

Top

new ($object_class, $constructor, @args)

Builds a new storage object.

AUTOLOAD

Arbitrary method calls are stored using AUTOLOAD. It will return another Object::Recorder::Storage instance so that method calls on return values from another recorded method calls will also be properly recorded.

AUTHOR

Top

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

COPYRIGHT & LICENSE

Top


Object-Recorder documentation Contained in the Object-Recorder distribution.
package Object::Recorder::Storage;
use warnings;
use strict;

our $VERSION = '0.01';

sub new {
    my $class = shift;
    my ($object_class, $constructor, @args) = @_;

    bless { 
        calls        => [], 
        object_class => $object_class,
        constructor  => $constructor,
        args         => \@args
    }, $class;
}

our $AUTOLOAD;

sub AUTOLOAD {
    my ($self, @args) = @_;
    my ($method) = ($AUTOLOAD =~ /::([^:]+?)$/);

    return if $method eq 'DESTROY';
    
    # only handle methods which return just one value
    my $return = (ref $self)->new;
    
    push @{$self->{calls}}, {
        method => $method,
        args   => [ @args ],
        retval => $return
    };
    
    return $return;
}

1;