Nile::Plugin::Session - Session manager plugin for the Nile framework.
use DateTime; # plugin session must be set to autoload in config.xml # save current username to session if (!$me->session->{username}) { $me->session->{username} = $username; } # get current username from session $username = $me->session->{username}; # save time of the user first visit to session if (!$me->session->{first_visit}) { $me->session->{first_visit} = time; } my $dt = DateTime->from_epoch(epoch => $me->session->{first_visit}); $view->set("first_visit", $dt->strftime("%a, %d %b %Y %H:%M:%S"));
Plugin settings in th config file under plugin section. The autoload variable is must be set to true value for the plugin to be loaded on application startup to setup hooks to work before actions dispatch.
plugin
autoload
This plugin uses the cache module CHI for saving sessions. All drivers supported by the CHI module are supported by this plugin.
<plugin> <session> <autoload>1</autoload> <key>nile_session_key</key> <expire>1 year</expire> <driver>File</driver> <cookie> <path>/</path> <secure></secure> <domain></domain> <httponly></httponly> </cookie> </session> </plugin>
$me->plugin->session->cache();
Returns the cache CHI object instance used by the session.
$id = $me->plugin->session->id(); $me->plugin->session->id($id);
Returns or sets the current session id. Session id's are auto generated.
# bits: 1= 40 bytes, 256=64 bytes, 512=128 bytes, 512224, 512256 $bits = $me->plugin->session->sha_bits(); $bits = 1; $me->plugin->session->sha_bits($bits);
Returns or sets the current session id generator Digest::SHA sha_bits.
$me->plugin->session->purge();
Remove all sessions that have expired from the cache. Warning: May be very inefficient, depending on the number of keys and the driver.
This project is available on github at https://github.com/mewsoft/Nile.
Please visit the project's homepage at https://metacpan.org/release/Nile.
Source repository is at https://github.com/mewsoft/Nile.
See Nile for details about the complete framework.
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nile
CPAN shell
perl -MCPAN -e shell install Nile
For more information on module installation, please visit the detailed CPAN module installation guide.