NAME

Catalyst::Model::InjectionHelpers::PerSession - Adaptor that returns a session scoped model

SYNOPSIS

package MyApp::PerSession;

use Moose;

sub freeze {
  my ($self) = @_;
  return $self->id;
}

sub thaw {
  my ($self, $from_session) = @_;
  return $self->new_from($from_session);
}

package MyApp;

use Catalyst 'InjectionHelper';

MyApp->inject_components(
'Model::PerRequest' => {
  from_class=>'MyApp::PerSession', 
  adaptor=>'PerSession', 
});

MyApp->setup;

DESCRIPTION

Injection helper adaptor that returns a new model once for session. See Catalyst::Plugin::InjectionHelpers for details. The adapted model MUST provide the following methods:

freeze

This method should provide a serialized version of the object suitable for placing in the session. To be safe you should provide a string. We recommend that you provide the smallest possible token useful for restoring a model at a later time, such the primary key of a database row, rather than all the data since session space may be limited, depending on the session type you use.

thaw

This receives the serialized version of the object that you created with 'freeze' and you shold use it to restore your object.

cleanup

Optional. When calling 'discard' on your model to discard the current saved version you may need to add this method in order to properly cleanup. For example if you save some temporary files as part of freeze, you may wish to remove those.

NOTE

We consider this adaptor to be someone experimental since its new and is not based on any existing prior art. Please register issues so we can improve it for the future.

AUTHOR

John Napiorkowski email:jjnapiork@cpan.org

SEE ALSO

Catalyst::Plugin::InjectionHelpers Catalyst, Catalyst::Model::InjectionHelpers::Application, Catalyst::Model::InjectionHelpers::Factory, Catalyst::Model::InjectionHelpers::PerRequest Catalyst::ModelRole::InjectionHelpers

COPYRIGHT & LICENSE

Copyright 2016, John Napiorkowski email:jjnapiork@cpan.org

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.