Form::Factory::Stasher::Memory - Remember things in a Perl hash


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Stasher::Memory - Remember things in a Perl hash

VERSION

Top

version 0.020

SYNOPSIS

Top

  $c->session->{stash_stuff} ||= {};
  my $stasher = Form::Factory::Stasher::Memory->new(
      stash_hash => $c->session->{stash_stuff},
  );

  $stasher->stash(foo => { blah => 1 });
  my $bar = $stasher->unstash('bar');

DESCRIPTION

Top

Stashes things into a plain memory hash. This is useful if you already have a mechanism for remember things that can be reused via a hash.

ATTRIBUTES

Top

stash_hash

The hash reference to stash stuff into. Defaults to an empty anonymous hash.

METHODS

Top

stash

Stash the stuff given.

unstash

Unstash the stuff requested.

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Stasher::Memory;
BEGIN {
  $Form::Factory::Stasher::Memory::VERSION = '0.020';
}
use Moose;

with qw( Form::Factory::Stasher );

has stash_hash => (
    is        => 'rw',
    isa       => 'HashRef',
    required  => 1,
    default   => sub { {} },
);

sub stash {
    my ($self, $moniker, $stash) = @_;
    $self->stash_hash->{ $moniker } = $stash;
}

sub unstash {
    my ($self, $moniker) = @_;
    delete $self->stash_hash->{ $moniker };
}

1;