Handel::Checkout::Stash - Basic storage for checkout plugins during processing


Handel documentation Contained in the Handel distribution.

Index


Code Index:

NAME

Top

Handel::Checkout::Stash - Basic storage for checkout plugins during processing

SYNOPSIS

Top

    use Handel::Checkout;

    my $checkout = Handel::Checkout->new;
    $checkout->process;

    # later in some plugin
    sub myhandler {
        my ($self, $ctx) = @_;

        $ctx->stash->{'mystuff'};
        ...
    };

    # later in some other plugin
    sub myhandler {
        my ($self, $ctx) = @_;

        my $stuff = $ctx->stash->{'mystuff'};
        ...
    };

DESCRIPTION

Top

Handel::Checkout::Stash is used by Handel::Checkout::Plugin plugins to pass data between themselves during a call to process. Before and after each call to process, clear is called is empty the stash.

To prevent this behavior, simply subclass this package with an empty clear and tell Handel::Checkout to use the new stash instead:

    package MyApp::Stash;
    use strict;
    use warnings;
    use base 'Handel::Checkout::Stash';

    sub clear {};

    ---

    use Handel::Checkout;

    my $co = Handel::Checkout->new({
        stash => MyApp::Stash->new
    });

CONSTRUCTOR

Top

new

Arguments: \%data

Creates a new instance of Handel::Checkout::Stash. You can optionally pass a hash reference to new which will be blessed into the new stash instance.

METHODS

Top

clear

Empties the contents of the stash.

The method is called before the call to $plugin->setup so plugins can set stash data, and the stash remains until the next call to process so $plugin->teardown can read any remaining stash data before process ends.

AUTHOR

Top

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/



Handel documentation Contained in the Handel distribution.

# $Id$
package Handel::Checkout::Stash;
use strict;
use warnings;

BEGIN {
    use Handel::L10N qw/translate/;
};

sub new {
    my ($class, $data) = @_;

    throw Handel::Exception::Argument(
        -details => translate('PARAM1_NOT_HASHREF')
    ) if defined $data && ref($data) ne 'HASH'; ## no critic

    my $self = bless $data || {}, $class;

    return $self;
};

sub clear {
    my $self = shift;

    %{$self} = ();

    return;
};

1;
__END__