On Mar 9, 2005, at 9:52 PM, Peter Fogg wrote:

Hello all,

This module was written to help me understand the use of CGI::Session
with the context of a CGI::Application object. The problem is that
when I store the reference to the CGI::Session object that I have
created in the CGI::Application object, I cannot retrieve the reference
to the CGI::Session object so that I may delete it.

I have enclosed the pertinent parts of the "create_set" and "destroy"
subs in "##############"s.

Being new to Perl and Web site implementation using Perl modules, I am
sure that I have written code that does not conform to best practices;
please feel free to comment, I need all the help I can get! BTW, I know
that there is some redundant code here!!


CUT

#################################
# I thought that this would store the session id in the application object
# so that it would be available later in the "destroy" sub.
#
# $self->param('_SESSION', $session->id());
#
#################################




If you want to store the session object, then this is probably what you want:

$self->param('_SESSION',$session);

This stores the reference to the session object.


#################################
# This works, the session id appears on the template page.
#
#       $page->param('-sessionref' => $self->param('_SESSION'));
#
#################################


As it should, but you are only getting the session id from $self->param('_SESSION') as you have it currently coded. Instead, if you make the change noted above, you could (to make it transparent) do:


my $session = $self->param('_SESSION');
$page->param('-sessionref' => $session->id());


elf, @args) = @_;

#################################
# This is what I am trying to do. These lines are currently commented out.
#
# # my $session = $self->param('_SESSION');
# # $session->delete();
# # $session->flush();
#
#################################


These should work with the first change noted above.

As a general comment, I would suggest using plugins whenever possible when working with CGI::Application. These offer standard methods for dealing with various objects commonly needed for web development (sessions, database handles, templates, etc.). For example, it is possible that you could create several connections to the database as you have written here. Using the DBH plugin, your application can set up one database handle (if needed, otherwise not) and share it throughout. The session plugin will only create a session if a session is needed; again, it makes the session object available throughout your application as $self->session. I at first thought--"I can this just as well", but I learned that it was better to use these plugin modules until I ran into a barrier that could not be overcome, then just build on what was available. It is a great learning experience to see what others have done, as it is (at least for me), usually amazing how small these modules actually are, just cleverly and thoughtfully coded. And most of the developers have given thought to running under a mod_perl environment, where caching and singleton behaviors can be used.

Hope this helps....

Sean


--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to