Catalyst::Model::InjectionHelpers::PerSession - Adaptor that returns a session scoped model
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;
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:
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.
This receives the serialized version of the object that you created with 'freeze' and you shold use it to restore your object.
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.
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.
John Napiorkowski email:jjnapiork@cpan.org
Catalyst::Plugin::InjectionHelpers Catalyst, Catalyst::Model::InjectionHelpers::Application, Catalyst::Model::InjectionHelpers::Factory, Catalyst::Model::InjectionHelpers::PerRequest Catalyst::ModelRole::InjectionHelpers
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.
To install Catalyst::Plugin::InjectionHelpers, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::InjectionHelpers
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::InjectionHelpers
For more information on module installation, please visit the detailed CPAN module installation guide.