Apache2-WebApp-Plugin-Session
view release on metacpan or search on metacpan
lib/Apache2/WebApp/Plugin/Session.pm view on Meta::CPAN
By default, when a new session is created, a browser cookie is set that contains
a C<session_id>. Upon success, this session identifier is returned, which can
also be used to set a customized session cookie.
my $session_id = $c->plugin('Session')->create($c, 'login',
{
username => 'foo',
password => 'bar',
}
);
=head2 get
Takes the cookie unique identifier or session id as arguments. Returns the
session data as a hash reference.
my $data_ref = $c->plugin('Session')->get($c, 'login');
print $data_ref->{username}; # outputs 'foo'
=head2 update
Takes the cookie unique identifier or session id as arguments. Updates
existing session data.
$c->plugin('Session')->update($c, 'login',
{
last_login => localtime(time),
remember => 1,
}
);
=head2 delete
Takes the cookie unique identifier or session id as arguments. Deletes an
existing session.
$c->plugin('Session')->delete($c, 'login');
=head2 id
Return the cookie unique identifier for a given session.
my $session_id = $c->plugin('Session')->id($c, 'login');
=head1 EXAMPLE
package Example;
sub _default {
my ($self, $c) = @_;
$c->plugin('Session')->create($c, 'login',
{
username => 'foo',
password => 'bar',
}
);
$c->plugin('CGI')->redirect($c, '/app/example/verify');
}
sub verify {
my ($self, $c) = @_;
my $data_ref = $c->plugin('Session')->get($c, 'login');
$c->request->content_type('text/html');
print $data_ref->{username} . '-' . $data_ref->{password}; # outputs 'foo-bar'
}
1;
=head1 SUPPORTED TYPES
Apache2::WebApp::Plugin::Session::File
Apache2::WebApp::Plugin::Session::Memcached
Apache2::WebApp::Plugin::Session::MySQL
=head1 SEE ALSO
L<Apache2::WebApp>, L<Apache2::WebApp::Plugin>, L<Apache2::WebApp::Plugin::Cookie>,
L<Apache::Session>
=head1 AUTHOR
Marc S. Brooks, E<lt>mbrooks@cpan.orgE<gt> - L<http://mbrooks.info>
=head1 COPYRIGHT
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L<http://dev.perl.org/licenses/artistic.html>
=cut
( run in 0.812 second using v1.01-cache-2.11-cpan-13bb782fe5a )