File Coverage

blib/lib/Object/Recorder/Storage.pm
Criterion Covered Total %
statement 6 16 37.5
branch 0 2 0.0
condition n/a
subroutine 2 4 50.0
pod 1 1 100.0
total 9 23 39.1


line stmt bran cond sub pod time code
1             package Object::Recorder::Storage;
2 1     1   5 use warnings;
  1         1  
  1         36  
3 1     1   4 use strict;
  1         2  
  1         203  
4            
5             =head1 NAME
6            
7             Object::Recorder::Storage - Serializable data structure for Object::Recorder
8            
9             =cut
10            
11             our $VERSION = '0.01';
12            
13             =head1 SYNOPSIS
14            
15             This module makes it possible to record method calls issued to a set of objects
16             inti a serializable container which can later be replayed, perfoming the actual
17             method calls.
18            
19             =head1 CLASS METHODS
20            
21             =cut
22            
23             =head2 new ($object_class, $constructor, @args)
24            
25             Builds a new storage object.
26            
27             =cut
28            
29             sub new {
30 0     0 1   my $class = shift;
31 0           my ($object_class, $constructor, @args) = @_;
32            
33 0           bless {
34             calls => [],
35             object_class => $object_class,
36             constructor => $constructor,
37             args => \@args
38             }, $class;
39             }
40            
41             =head2 AUTOLOAD
42            
43             Arbitrary method calls are stored using AUTOLOAD. It will return another
44             L instance so that method calls on return values
45             from another recorded method calls will also be properly recorded.
46            
47             =cut
48            
49             our $AUTOLOAD;
50            
51             sub AUTOLOAD {
52 0     0     my ($self, @args) = @_;
53 0           my ($method) = ($AUTOLOAD =~ /::([^:]+?)$/);
54            
55 0 0         return if $method eq 'DESTROY';
56            
57             # only handle methods which return just one value
58 0           my $return = (ref $self)->new;
59            
60 0           push @{$self->{calls}}, {
  0            
61             method => $method,
62             args => [ @args ],
63             retval => $return
64             };
65            
66 0           return $return;
67             }
68            
69             =head1 AUTHOR
70            
71             Nilson Santos Figueiredo Junior, C<< >>
72            
73             =head1 COPYRIGHT & LICENSE
74            
75             Copyright (C) 2007 Nilson Santos Figueiredo Junior.
76             Copyright (C) 2007 Picturetrail, Inc.
77            
78             This program is free software; you can redistribute it and/or modify it
79             under the same terms as Perl itself.
80            
81             =cut
82            
83             1;