Hello Monks!

Problem is that to use the CGI::Session for CGI::Application I have to configure it during setup time. I need to either pass it DBH which means I already need to be connected to DB, or parameters that will be used to create DBH and connect by the CGI::Session itself.

In first case (giving it DBH):
I'm connecting no matter if it will be needed (say I dont need Session parameters nor DB access).

Second case (giving it parameters):
It solves the problem that it doesn't connect if it's not needed. But then when it's needed from the application also I end up with two DB connections (one mine, mine from CGI::Session).

Any solution for this?

I'm not using DBI directly but from a module that I wrote which is sort of DB abstraction. I've implemented a Singleton pattern in it - so there is only one connection trougths application. And the way I send DBH to CGI::Session is by requesting it from my module.

### Set the configs for Sessions ### $self->session_config( CGI_SESSION_OPTIONS => ["driver:MySQL;serializer:Storab +le", $self->query, {Handle => $DB->dbh()}] );
Obviosly I already need to be connected at the time when I'm sending DBH to it. Maybe there is some way (TIE perhaps?) to catch all calls that CGI::Session would make on that DBH, and first connect and then execute them?

Only solution that I know would work and how to do it (but not the nicest one) is to change CGI::Session just a bit ...


In reply to Using CGI:App and Session plugin - double DB connection fix. by techcode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.