| Egg-Plugin-SessionKit documentation | Contained in the Egg-Plugin-SessionKit distribution. |
Egg::Model::Session::Base::DBIC - Session management by DBIC.
package MyApp::Model::Sesion;
__PACKAGE__->config(
dbic => {
label_schema => 'dbic_schma_label',
label_source => 'dbic_moniker_label',
id_field => 'id',
data_field => 'a_session',
time_field => 'lastmod',
},
);
__PACKAGE__->startup(
Base::DBIC
Store::Base64
ID::SHA1
Bind::Cookie
);
The session data is preserved by using DBIC.
'Egg::Model::DBIC' should be able to be used for use.
And, 'Base::DBIC' is added to startup of the component module generated with Egg::Helper::Model::Session. Base::FileCache of default's It is not possible to cooperate and delete it, please.
Moreover, it is necessary to load Store system module to treat the session data appropriately.
__PACKAGE__->startup( Base::DBIC Store::Base64 ID::SHA1 Bind::Cookie );
If AutoCommit is invalid and 'Egg::Plugin::DBIC' is effective in the setting of DBI, it is late commit.
It sets in config of the session component module and it sets it to 'dbic' item with HASH.
__PACKAGE__->config(
dbic => {
.......
},
);
It is Ra bell name because it obtains Schame of Egg::Model::DBIC.
The exception is generated in case of undefined.
Label name to obtain source object of session table from Egg::Model::DBIC.
The exception is generated in case of undefined.
Name of session ID column.
'id' is used in case of undefined.
Name of session data column.
'a_session' is used in case of undefined.
Name of updated day and hour column.
'lastmod' is used in case of undefined.
Because most of these methods is the one that Egg::Model::Session internally uses it, it is not necessary to usually consider it on the application side.
The source object of the session table is returned from Egg::Model::DBIC.
If AutoCommit is effective, the transaction is begun. If it is invalid, nothing is done.
If AutoCommit is effective, the transaction is shut. If it is invalid, committing does the rollback if 'is_update' is effective.
If AutoCommit is invalid, nothing is done.
When the result of 'restore' is preserved, it is returned.
The content of 'id_filed' of the configuration is returned.
The content of 'data_filed' of the configuration is returned.
The content of 'time_field' of the configuration is returned.
The session data obtained by received SESSION_ID is returned.
When SESSION_ID is not obtained, it acquires it in 'session_id' method.
New session data is preserved.
SESSION_DATA is indispensable.
When SESSION_ID is not obtained, it acquires it in 'session_id' method.
Existing session data is updated.
SESSION_DATA is indispensable.
When SESSION_ID is not obtained, it acquires it in 'session_id' method.
After Egg::Model::Session::Manager::TieHash, commit is done.
However, if 'is_update' method is invalid, rollback is issued. In a word, if data was not substituted for the session, the data is annulled.
Egg::Release, Egg::Model::Session, Egg::Model::Session::Manager::Base, Egg::Model::Session::Manager::TieHash, Egg::Model, Egg::Model::DBIC, Time::Piece::MySQL,
Masatoshi Mizuno <lushe&64;cpan.org>
Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
| Egg-Plugin-SessionKit documentation | Contained in the Egg-Plugin-SessionKit distribution. |
package Egg::Model::Session::Base::DBIC; # # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> # # $Id: DBIC.pm 256 2008-02-14 21:07:38Z lushe $ # use strict; use warnings; use Carp qw/ croak /; use Time::Piece::MySQL; sub _setup { my($class, $e)= @_; my $c= $class->config->{dbic} ||= {}; my $idcol = $c->{id_field} || 'id'; my $datacol= $c->{data_field} || 'a_session'; my $timecol= $c->{time_field} || 'lastmod'; my $moniker= $c->{label_source} || die q{I want setup 'label_source'.}; $e->is_model($c->{label_source}) || die qq{'$c->{label_source}' model is not found.}; my $s_label= $c->{label_schema} || die q{I want setup 'label_schema'.}; my $project= $e->project_name; no strict 'refs'; ## no critic. no warnings 'redefine'; if ($e->isa('Egg::Plugin::DBIC')) { $e->is_model($s_label) || die qq{'$s_label' model is not found.}; my $s_name= $s_label=~m{^dbic\:+(.+)} ? $1: $s_label; *{"${class}::_begin"}= sub { &{"${project}::begin_$s_name"}($_[0]->e); }; *{"${class}::_commit"}= sub { &{"${project}::commit_ok"}($_[0]->e, $s_name, 1) if $_[1]; }; } else { my $schema= $e->model($s_label) || die qq{'$s_label' model is not found.}; if ($schema->storage->dbh->{AutoCommit}) { *{"${class}::_begin"} = sub { $_[0]->e->model($s_label) }; *{"${class}::_commit"}= sub { 1 }; } else { *{"${class}::_begin"}= sub { my $context= $_[0]->e->model($s_label); $context->txn_begin; $context; }; *{"${class}::_commit"}= sub { $_[1] ? $_[0]->_schema->txn_commit : $_[0]->_schema->txn_rollback; }; } } *{"${class}::moniker"}= sub { $_[0]->attr->{dbic_moniker} ||= $_[0]->e->model($moniker); }; *{"${class}::result"}= sub { my $self= shift; return ($self->attr->{result} || 0) unless @_; $self->attr->{result}= shift; }; *{"${class}::id_col"} = sub { $idcol }; *{"${class}::data_col"} = sub { $datacol }; *{"${class}::time_col"} = sub { $timecol }; $class->next::method($e); } sub restore { my $self= shift; my $id = shift || $self->session_id || croak q{I want session id.}; my $result = $self->moniker->find($id) || return 0; my $datacol= $self->data_col; \$self->result($result)->$datacol; } sub insert { my $self= shift; my $data= shift || croak q{I want session data.}; my $id = shift || $self->session_id || croak q{I want session id.}; # $self->result(undef) if $self->result; $self->moniker->create({ $self->id_col => $id, $self->data_col => $$data, $self->time_col => localtime(time)->mysql_datetime, }); } sub update { my $self= shift; my $data= shift || croak q{I want session data.}; my $id = shift || $self->session_id || croak q{I want session id.}; return $self->insert($data, $id) unless $self->result; my($datacol, $timecol)= ($self->data_col, $self->time_col); $self->result->$timecol( localtime(time)->mysql_datetime ); $self->result->$datacol( $$data ); $self->result->update; } sub close { my($self)= @_; my $update_ok= $self->is_update; $self->next::method; $self->_commit($update_ok); $self; } 1; __END__