in reply to Sharing Variables and Routines between modules

I suggest you try using CGI::Application. The database handle will be accessible to any run mode (web page) by using $self->dbh, and you can use $self->param() to share data instead of using globals, etc.

  • Comment on Re: Sharing Variables and Routines between modules

Replies are listed 'Best First'.
Re^2: Sharing Variables and Routines between modules
by Anonymous Monk on Nov 03, 2010 at 10:53 UTC
    Thanks for your replies all.

    Having read the pod for CGI::Application gave me some valuable insight about a better way to reach my goals.

    The best approach I've been able to come up with so far is this:

    Write basic framework "instance" scripts: index.pl, admin.pl etc.etc.
    Each script uses My_Common which contains the bulk of the software's routines.
    My_Common uses My_Database and My_Globals
    My_Database and My_Globals export their methods to MyCommon which in turn exports these to the instance script.

    The result: shared variables and routines.
    $global{'image_path'} stays in this form as does $dbh for the database handle, and both are available in index.pl and My_Common

    Every new instance script simply uses My_Common, and if I decide to create other modules, these can be simply used by My_Common and I'm good to go again.

    Thanks again.