CGI-Lazy

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

Changes
lib/CGI/Lazy.pm
lib/CGI/Lazy/Authn.pm
lib/CGI/Lazy/Authz.pm
lib/CGI/Lazy/Config.pm
lib/CGI/Lazy/CookieMonster.pm
lib/CGI/Lazy/CSS.pm
lib/CGI/Lazy/DB.pm
lib/CGI/Lazy/DB/RecordSet.pm
lib/CGI/Lazy/ErrorHandler.pm
lib/CGI/Lazy/Globals.pm
lib/CGI/Lazy/ID.pm
lib/CGI/Lazy/Image.pm
lib/CGI/Lazy/Javascript.pm
lib/CGI/Lazy/Javascript/JSONParser.pm
lib/CGI/Lazy/Plugin.pm

lib/CGI/Lazy.pm  view on Meta::CPAN

		my $ref = shift;
		%args = %$ref;
	}

	my $explicitcookies = $args{-cookie} || []; #cookies set explictly in the instance
	my $lazycookie;

	if ($self->plugin) { #it's possible that this object hasn't been built- if the config object doesn't create for instance.
		if ($self->plugin->session && $self->session) {
			$lazycookie = $self->cookie(
						-name		=> $self->plugin->session->{sessionCookie},
						-expires	=> $self->plugin->session->{expires},
						-value 		=> $self->session->sessionID,
			);
		}
	} else { #something really bad happened.  Return a header anyway, so we can show an error message
		return $self->SUPER::header();
	}

	$args{-cookie} = [$lazycookie, @$explicitcookies];

lib/CGI/Lazy.pm  view on Meta::CPAN

							dbPasswd 	=> "letmein",

							dbArgs 		=> {"RaiseError" => 1},

						},

						session	=> {

							sessionTable	=> 'SessionData',

							sessionCookie	=> 'frobnostication',

							saveOnDestroy	=> 1,

							expires		=> '+15m',

						},

					},

				});

lib/CGI/Lazy/Authn.pm  view on Meta::CPAN

						dbPasswd        => 's3cr3t',

						dbArgs          => {RaiseError  => 1},

					},

					session => {

						sessionTable    => 'session',

						sessionCookie   => 'frobnitz',

						saveOnDestroy   => 1,

						expires         => '+15m',

					},

					authn   => {

						table           => 'user',

lib/CGI/Lazy/Authz.pm  view on Meta::CPAN

						dbPasswd        => 'somePass',

						dbArgs          => {RaiseError  => 1},

					},

					session => {

						sessionTable    => 'session',

						sessionCookie   => 'frobnitz',

						saveOnDestroy   => 1,

						expires         => '+5m',

					},

					authn   => {

						table           => 'user',

lib/CGI/Lazy/CookieMonster.pm  view on Meta::CPAN

package CGI::Lazy::CookieMonster;

use strict;

use CGI::Lazy::Globals;

#-----------------------------------------------------------------------------------------------------------
sub getCookie {
	my $self = shift;
	my $cookie = shift;

	return $self->q->cookie($cookie);
}

#-----------------------------------------------------------------------------------------------------------
sub goodEnoughForMe {
	my $self = shift;
	my $cookie = shift;

lib/CGI/Lazy/CookieMonster.pm  view on Meta::CPAN


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

Bug reports and comments to nik.ogura@gmail.com. 

#===========================================================================

=head1 NAME

CGI::Lazy::CookieMonster

=head1 SYNOPSIS

	use CGI::Lazy::CookieMonster;

	my $cm = CGI::Lazy::CookieMonster->new;

	$cm->getCookie($cookieName);

=head1 DESCRIPTION

Module for handling http cookies.  

Come on, when was I gonna find another opportunity for a module called 'CookieMonster'?

=head1 METHODS

=head2 getCookie ( cookie )

Retrieves cookie.

=head3 cookie

name of cookie.

=head2 goodEnoughForMe( cookie )

Dev's have to have fun too.  Returns true if $cookie.  Will probably mod it so it serves some better function.

lib/CGI/Lazy/CookieMonster.pm  view on Meta::CPAN

some value


=head2 q ()

Returns Lazy object


=head2 new ( q  )

Constructor.  Returns CookieMonster object.

=head3 q

CGI::Lazy object.

=cut

lib/CGI/Lazy/DB/RecordSet.pm  view on Meta::CPAN

							dbPasswd 	=> "letmein",

							dbArgs 		=> {"RaiseError" => 1},

						},

						session	=> {

							sessionTable	=> 'SessionData',

							sessionCookie	=> 'frobnostication',

							saveOnDestroy	=> 1,

							expires		=> '+15m',

						},

					},

				});

lib/CGI/Lazy/Session.pm  view on Meta::CPAN

package CGI::Lazy::Session;

use strict;

use JSON;
use CGI::Lazy::ID;
use CGI::Lazy::CookieMonster;
use CGI::Lazy::Session::Data;
use CGI::Lazy::Globals;

#--------------------------------------------------------------------------------------
sub cookiemonster {
	my $self = shift;
	
	return $self->{_cookiemonster};
}

lib/CGI/Lazy/Session.pm  view on Meta::CPAN

 
#--------------------------------------------------------------------------------------
sub open {
	my $class = shift;
	my $q = shift;
	my $sessionID = shift;

	my $self = {};
	$self->{_q} = $q;
	$self->{_sessionTable} = $q->plugin->session->{sessionTable};
	$self->{_sessionCookie} = $q->plugin->session->{sessionCookie};
	$self->{_expires} = $q->plugin->session->{expires};

	bless $self, $class;

	$self->{_cookiemonster} = CGI::Lazy::CookieMonster->new($q);
   	$self->{_id} = CGI::Lazy::ID->new($self);

       	$sessionID = $self->cookiemonster->getCookie($self->sessionCookie)  unless $sessionID;

	if ($sessionID) { #check sessionID against db, compare expiry time to last accessed time, reopen if valid
		#$q->util->debug->edump("have sessionID");
		$self->{_sessionID} = $sessionID;
		$self->{_data} = CGI::Lazy::Session::Data->new($self);
		
		my $now = time();
		my $expiry = $self->data->expires;

		$sessionID = $self->new($self->id->generate) if $self->expired;

lib/CGI/Lazy/Session.pm  view on Meta::CPAN

}

#--------------------------------------------------------------------------------------
sub q {
	my $self = shift;

	return $self->{_q};
}

#--------------------------------------------------------------------------------------
sub sessionCookie {
	my $self = shift;

	return $self->{_sessionCookie};
}

#--------------------------------------------------------------------------------------
sub sessionID {
	my $self = shift;
	
	return $self->{_sessionID};
}

#--------------------------------------------------------------------------------------

lib/CGI/Lazy/Session.pm  view on Meta::CPAN

							dbPasswd 	=> "letmein",

							dbArgs 		=> {"RaiseError" => 1},

						},

						session	=> {

							sessionTable	=> 'SessionData',

							sessionCookie	=> 'frobnostication',

							saveOnDestroy	=> 1,

							expires		=> '+15m',

						},

					},

				});

=head1 DESCRIPTION

CGI::Lazy::Session is for maintaining state between requests.  It's enabled in the config file or config hash.  Once it's enabled, any calls to $q->header will automatically include a cookie that will be used to retrieve session data.

To function, the session needs the following arguments:

	sessionTable	=> name of table to store data in

	sessionCookie	=> name of the cookie

	expires		=> how long a session can sit idle before expiring

By default, sessions are automatically saved when the Lazy object is destroyed, or in the cleanup stage of the request cycle for mod_perl apps.  Both mechanisms are enabled by default.  (call me paranoid)  Should you wish to disable the save on destr...
	saveOnDestroy	=> 0

If the key is missing from the config, it's as if it was set to 1.  You will have to set it to 0 to disable this functionality.  Same goes for the mod_perl save.  See CGI::Lazy::ModPerl for details

Session data is stored in the db as JSON formatted text at present.  Fancier storage (for binary data and such) will have to wait for subsequent releases.

The session table must have the following fields at a bare minimum:

	sessionID	not null, primary key, varchar(25)

	data		text (mysql) large storage (clob in oracle)

=head1 METHODS

=head2 cookiemonster

returns reference to CGI::Lazy::CookieMonster object

=head2 config

returns reference to the config object

=head2 data ()

returns reference to the CGI::Lazy::Session::Data object

=head2 db ()

lib/CGI/Lazy/Session.pm  view on Meta::CPAN

Currently only can parse seconds, minutes, hours and days.  Is more really necessary?

=head3 time

Epoch returned from time() function

=head2 q ()

Returns reference to CGI::Lazy object

=head2 sessionCookie ()

Returns name of session cookie specified by session plugin

=head2 sessionID ()

Returns session id

=head2 sessionTable ()

Returns session table name specified by session plugin

lib/CGI/Lazy/Session/Data.pm  view on Meta::CPAN

							dbPasswd 	=> "letmein",

							dbArgs 		=> {"RaiseError" => 1},

						},

						session	=> {

							sessionTable	=> 'SessionData',

							sessionCookie	=> 'frobnostication',

							saveOnDestroy	=> 1,

							expires		=> '+15m',

						},

					},

				});

lib/CGI/Lazy/Utility/Debug.pm  view on Meta::CPAN

use Data::Dumper;
use File::Basename;

#-------------------------------------------------------------------------------------------------------------------------------
sub cookie {
	my $self = shift;
	my $q = $self->q;

	print $q->header,
	      $q->start_html({-title => 'CGI Test Page'}),
	      $q->h1('Cookies'),
	      $q->table($q->th('Param'), $q->th('Value'),
			      map {
			      	$q->TR($q->th({-style => "text-align:center"}, $_), $q->td({-style => "text-align:center"}, $q->cookie($_)))
				} $q->cookie()
		       );

}

#-------------------------------------------------------------------------------------------------------------------------------
sub config {

lib/CGI/Lazy/Widget/Dataset.pm  view on Meta::CPAN

							dbPasswd 	=> "letmein",

							dbArgs 		=> {"RaiseError" => 1},

						},

						session	=> {

							sessionTable	=> 'SessionData',

							sessionCookie	=> 'frobnostication',

							saveOnDestroy	=> 1,

							expires		=> '+15m',

						},

					},

				});

t/01basic.t  view on Meta::CPAN

#						saveOnCleanup	=> '1',
#					},
#					dbh     => {
#						dbDatasource    => 'dbi:mysql:CIS:localhost',
#						dbUser          => 'CISuser',
#						dbPasswd        => 'l3tM31n',
#						dbArgs          => {RaiseError  => 1},
#					},
#					session => {
#						sessionTable    => 'session',
#						sessionCookie   => 'CIS',
#						saveOnDestroy   => 1,
#						expires         => '+5m',
#					},
#					authn   => {
#						table           => 'user',
#						primarykey      => 'user_id',
#						template        => 'login.tmpl',
#						salt            => '2349asdfLKj%@asdf',
#						userField       => 'username',
#						passwdField     => 'password',



( run in 0.429 second using v1.01-cache-2.11-cpan-e9199f4ba4c )