Masatoshi Mizuno > Egg-Plugin-SessionKit-3.05 > Egg::Model::Session

Download:
Egg-Plugin-SessionKit-3.05.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Egg::Model::Session - Model to use session.

SYNOPSIS ^

  my $session= $e->model('session_label');
  
  # Data is preserved in the session.
  $session->{hoge}= 'booo';
  
  # The session is shut and it preserves it.
  $session->close_session;

DESCRIPTION ^

It is a model to use the session.

To use it, the module is generated under the control of the project with the helper.

see Egg::Helper::Model::Session.

  % cd /path/to/MyApp/bin
  % ./egg_helper M::Session [MODULE_NAME]

It is this and MyApp? in the lib directory of the project. '... /Model/Session/MODULE_NAME.pm' is generated.

And, 'Session' is added to the MODEL setting of the project.

  % vi /path/to/MyApp/lib/MyApp/config.pm
  .........
  ...
  MODEL => ['Session'],

The session module is set up when the project is started by this and using it becomes possible.

Two or more kind of sessions can be treated at the same time by setting up two or more this session modules.

HOW TO SESSION ^

To acquire the session data, it acquires it specifying the label name that relates to the generated module name.

  # If it is MyApp::Model::Session::Hoge
  #   ( The capital letter and the small letter are identified )
  my $session= $e->model('session::hoge');

The label name can set the name of the favor with Confifration of the session module.

  __PACKAGE__->config(
    label_name => 'myname',
    );

When the above-mentioned setting is done, easiness can be done a little by specifying the label name.

  my $session= $e->model('myname');

However, please note no collision with the label name that other models use.

The obtained object only puts data in and out as it is because it is session data now.

  my $session_data= $session->{hoge};
  
  $session->{new_data}= 'ok';

And, the session is preserved by the 'close_session' method.

  $session->close_session;

However, because 'close_session' method is called if it is necessary for '_finish' hook of the project being called, 'close_session' need not usually be considered in the application.

The judgment whether it preserves or annul it is Egg::Model::Session::Manager. It judges with the flag that drinks and is set in 'is_update'. Only when the key to a single hierarchy is substituted, this flag is set. Therefore, the update of the value of the subhierarchy cannot be judged for HASH of the layered structure. To update only the value of the subhierarchy and to preserve it, 'is_update' should be made effective specifying it.

  # Only it is to be referred to the hoge key, is_update : like being undefined.
  $session->{hoge}{booo} = 1;
  
  # It is necessary to define is_update for oneself.
  $session->is_update(1);

  # The necessity is not in is_update if it is this.
  $session->{hoge}{booo} = 1;
  $session->{banban}     = 'ok';

SESSION MODULE ^

The session module generated with the helper has 'MyApp::Model::Session::[MODEULE_NAME]::Manager' class that succeeds to 'Egg::Model::Session::Manager::TieHash' with 'MyApp::Model::Session::[MODEULE_NAME]::Manager' class that succeeds to 'Egg::Model::Session::Manager::Base'.

The configuration of the session is done in the Manager class.

  package MyApp::Model::Session::Hoge;
  use strict;
  use base qw/ Egg::Model::Session::Manager::Base /;
  
  __PACKAGE__->config(
    label_name=> 'myname',
    .........
    ....
    );

When two or more session modules have been treated, the session that sets 'default' and treats by default can be specified.

The session treated by default in the result of sorting is decided if there is no 'default' all.

  __PACKAGE__->config(
    default => 1,
    );

Please refer to the document of the component module for each TieHash for the content set to the configuration.

And, it is 'startup' method and TieHash. The name of the component module that decides the operation of the class is specified.

  __PACKAGE__->startup(
    ID::SHA1
    Bind::Cookie
    Base::FileCache
    );

It becomes above in default,

and Egg::Model::Session::ID::SHA1 and Egg::Model::Session::Bind::Cookie and Egg::Model::Session::Base::FileCache

However, Yo is seen.

The following roles are in the above-mentioned each component module.

  ID::SHA1        ... Session ID issue etc.
  Bind::Cookie    ... Session ID ties to the client.
  Base::FileCache ... Reading and preservation. of session data.

Moreover, they are all described here and it uses it though it is thought according to circumstances that the component and the plugin, etc. concerning the preservation form are necessary.

When '+' is applied to the head, it is treated as a full name though it only has to specify since 'Egg::Model::Session' for the name.

  __PACKAGE__->startup(
    .....
    +Egg::Plugin::SessionKit::Bind::URI
    );

List of component module enclosed with this package.

I/O relation of session data.

Egg::Model::Session::Base::DBI, Egg::Model::Session::Base::DBIC, Egg::Model::Session::Base::FileCache,

Relation of session ID and client.

Egg::Model::Session::Bind::Cookie,

Session ID issue etc.

Egg::Model::Session::ID::IPaddr, Egg::Model::Session::ID::MD5, Egg::Model::Session::ID::SHA1, Egg::Model::Session::ID::UniqueID, Egg::Model::Session::ID::UUID,

Preservation form relation of session data.

Egg::Model::Session::Store::Base64, Egg::Model::Session::Store::UUencode,

Plugin etc.

Egg::Model::Session::Plugin::AbsoluteIP, Egg::Model::Session::Plugin::AgreeAgent, Egg::Model::Session::Plugin::CclassIP, Egg::Model::Session::Plugin::Ticket,

METHODS ^

new

This constructor returns the session object of the read default configuration.

MANAGER CLASS ^

The manager class is an object that wrapped the session data. TieHash according to AUTOLOAD though there is too no method that can be used. It is possible to use it in shape to relay the method of the class.

TIEHASH CLASS ^

It is an object that becomes a main body that treats the session data.

Each TieHASH component : the method with the @ISA base. It is common.

HOOK METHOD ^

'_finish' and '_finalize_error' are picked up because it is 'close_session' and TieHash. The hook is done to the class.

SEE ALSO ^

Egg::Release, Egg::Model, Egg::Model::Session::Manager::Base, Egg::Model::Session::Manager::TieHash, Egg::Helper::Model::Session, UNIVERSAL::require,

AUTHOR ^

Masatoshi Mizuno <lushe@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: