perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Perrin Harkins <phark...@gmail.com>
Subject Re: mod_perl / CGI.pm and 'our' variables
Date Mon, 27 Jul 2009 14:37:20 GMT
2009/7/21 Tomáš Bažant <tbazant@suse.cz>:
> i'm writing a web application using %SUBJ% and would like to set 'our
> $dbh = ...' so that i do not need to pass db handler as an argument to
> functions in different packages every time i need. but this 'global'
> variable is not seen inside imported package as $::dbh (as it is in
> normal non-mod_perl application).

The scoping of variables is not changed by mod_perl.  When you declare
a package variable, you should be able to see it from other packages,
but you won't be able to refer to it as $dbh except in the package
where you declared it.

Example:

package Foo;
our $dbh;

$dbh->ping; # works

package Bar;
$dbh->ping; # fails

You can still use the fully-qualified name to get at it: $Foo::dbh.

- Perrin

Mime
View raw message