The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Nile::Plugin::Session - Session manager plugin for the Nile framework.

SYNOPSIS

        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"));
                

DESCRIPTION

Nile::Plugin::Session - Session manager plugin for the Nile framework.

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.

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>

cache()

        $me->plugin->session->cache();

Returns the cache CHI object instance used by the session.

id()

        $id = $me->plugin->session->id();
        $me->plugin->session->id($id);

Returns or sets the current session id. Session id's are auto generated.

sha_bits()

        # 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.

purge()

        $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.

Bugs

This project is available on github at https://github.com/mewsoft/Nile.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Nile.

SOURCE

Source repository is at https://github.com/mewsoft/Nile.

SEE ALSO

See Nile for details about the complete framework.

AUTHOR

Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com

COPYRIGHT AND LICENSE

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.