Fey::ORM::Mock::Recorder - Records the history of changes for a class


Fey-ORM-Mock documentation Contained in the Fey-ORM-Mock distribution.

Index


Code Index:

NAME

Top

Fey::ORM::Mock::Recorder - Records the history of changes for a class

VERSION

Top

version 0.05

DESCRIPTION

Top

This object is used to store a record of the changes for each class.

METHODS

Top

This class provides the following methods:

Fey::ORM::Mock::Recorder->new()

Returns a new recorder object.

$recorder->record_action(...)

This method takes a set of parameters which will be passed directly to Fey::ORM::Mock::Action->new_action(). Then it stores the action.

$recorder->actions_for_class($class)

Given a class name, this returns a list of stored actions for that class, from least to most recent.

$recorder->clear_class($class)

Clears the record of actions for the class

$recorder->clear_all()

Clears the records for all classes.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


Fey-ORM-Mock documentation Contained in the Fey-ORM-Mock distribution.

package Fey::ORM::Mock::Recorder;
BEGIN {
  $Fey::ORM::Mock::Recorder::VERSION = '0.05';
}

use strict;
use warnings;

use Fey::ORM::Mock::Action;

use Moose;

has '_actions' => (
    is      => 'ro',
    isa     => 'HashRef[ArrayRef[Fey::ORM::Mock::Action]]',
    default => sub { {} },
);

sub record_action {
    my $self = shift;

    my $action = Fey::ORM::Mock::Action->new_action(@_);

    $self->_actions()->{ $action->class() } ||= [];
    push @{ $self->_actions()->{ $action->class() } }, $action;

    return;
}

sub actions_for_class {
    my $self  = shift;
    my $class = shift;

    return @{ $self->_actions()->{$class} || [] };
}

sub clear_class {
    my $self  = shift;
    my $class = shift;

    $self->_actions()->{$class} = [];
}

sub clear_all {
    my $self = shift;

    for my $class ( keys %{ $self->_actions() } ) {
        $self->clear_class($class);
    }
}

no Moose;

__PACKAGE__->meta()->make_immutable();

1;

# ABSTRACT: Records the history of changes for a class




__END__