Marc S. Brooks > Apache2-WebApp-Plugin-Cookie > Apache2::WebApp::Plugin::Cookie

Download:
Apache2-WebApp-Plugin-Cookie-0.10.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  

NAME ^

Apache2::WebApp::Plugin::Cookie - Plugin providing HTTP cookie methods

SYNOPSIS ^

  my $obj = $c->plugin('Cookie')->method( ... );     # Apache2::WebApp::Plugin::Cookie->method()

    or

  $c->plugin('Cookie')->method( ... );

DESCRIPTION ^

Common methods for creating and manipulating web browser cookies.

PREREQUISITES ^

This package is part of a larger distribution and was NOT intended to be used directly. In order for this plugin to work properly, the following packages must be installed:

  Apache2::WebApp
  Apache2::WebApp::Plugin::Filters
  Params::Validate

INSTALLATION ^

From source:

  $ tar xfz Apache2-WebApp-Plugin-Cookie-0.X.X.tar.gz
  $ perl MakeFile.PL PREFIX=~/path/to/custom/dir LIB=~/path/to/custom/lib
  $ make
  $ make test
  $ make install

Perl one liner using CPAN.pm:

  $ perl -MCPAN -e 'install Apache2::WebApp::Plugin::Cookie'

Use of CPAN.pm in interactive mode:

  $ perl -MCPAN -e shell
  cpan> install Apache2::WebApp::Plugin::Cookie
  cpan> quit

Just like the manual installation of Perl modules, the user may need root access during this process to insure write permission is allowed within the installation directory.

CONFIGURATION ^

In order to set a browser cookie, you need to specify a valid hostname in your webapp.conf

  [apache]
  domain = www.domain.com

OBJECT METHODS ^

set

Set a new browser cookie.

  $c->plugin('Cookie')->set( $c, {
        name    => 'foo',
        value   => 'bar',
        expires => '24h',
        domain  => 'www.domain.com',    # optional
        secure  => 0,
    });

get

Return the browser cookie value.

  my $result = $c->plugin('Cookie')->get($name);

  # bar is value of $result

delete

Delete a browser cookie by name.

  $c->plugin('Cookie')->delete( \%controller, $name );

EXAMPLE ^

  package Example;

  use strict;
  use warnings;

  sub _default {
      my ( $self, $c ) = @_;

      $c->plugin('Cookie')->set( $c, {
          name    => 'foo',
          value   => 'bar',
          expires => '1h',
          secure  => 0,
        });

      $c->plugin('CGI')->redirect( $c, '/app/example/verify' );
  }

  sub verify {
      my ( $self, $c ) = @_;

      $c->request->content_type('text/html');

      print $c->plugin('Cookie')->get('foo');
  }

  1;

SEE ALSO ^

Apache2::WebApp, Apache2::WebApp::Plugin, Apache2::Cookie

AUTHOR ^

Marc S. Brooks, <mbrooks@cpan.org> - http://mbrooks.info

COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/artistic.html

syntax highlighting: