sbatty has asked for the wisdom of the Perl Monks concerning the following question:

I have been experimenting with CGI::Session and find it promising, but I'm having difficulty with the new() method and Class::DBI. I can't find any documentation supporting the use of Class::DBI objects with the new() constructor. The docs state that the CGI::Session new() method requires three arguments(dataset name, a session id, and a hashref) but no explanation is provided for the third arg, the hashref. Can anyone shed some light on this? I'm not even able to figure out what that third arg does from the docs. It sometimes appears to point to a storage location for session data and at other times the hashref appears to contain option/value pairs.
Examples from the docs: my $session = new CGI::Session( "driver:MySQL", undef, {Directory=>"/tmp"} );
my $session = new CGI::Session( "driver:MySQL", undef, {Handle=>"$dbh"} ); /Examples
my $session = new CGI::Session( "driver:MySQL", undef, {Class::DBI=>"TableObject"} );
I'm trying to figure out what would go in place of the pseudo code "{Class::DBI=>"TableObject"}" in the above example. What goes here to use the table object? Can anyone provide sources of additional documentation or examples? Thank you for sharing your Perl knowledge.

Replies are listed 'Best First'.
Re: How do I use CGI::Session constructor method with Class::DBI?
by jeffa (Bishop) on Oct 31, 2003 at 19:15 UTC
    I don't think you can do that at all. The CGI::Session constructor is not set up to work with Class::DBI, nor should it be, as it handles the "behind the scenes" stuff for you. You can, however, use CGI::Session and Class::DBI together in your application -- they just do different things. But as for instantiating the CGI::Session object, i see no reason to use Class::DBI even if you could.

    As far as the third argument is concerned, you have to inspect the source for CGI::Session::MySQL to see that the only items you can specify here are:

    • Handle (this should be a DBI::db object or subclass)
    • DataSource
    • User
    • Password

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: How do I use CGI::Session constructor method with Class::DBI?
by perrin (Chancellor) on Oct 31, 2003 at 19:08 UTC
    Slow down, you're going off in all directions here. The third argument is specific to the CGI::Session driver you choose. It is documented there (e.g. in CG::Session::MySQL), although I would agree that the documentation for it is not very clear.

    CGI::Session has nothing at all to do with Class::DBI. If you want to store an object in the session that gets returned from CGI::Session->new(), you call the param() method on that object. Class::DBI objects are already stored in the database so there is no need to store them in the session too.