Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 8040 invoked from network); 14 Jan 2010 21:42:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2010 21:42:51 -0000 Received: (qmail 44781 invoked by uid 500); 14 Jan 2010 21:42:49 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 44748 invoked by uid 500); 14 Jan 2010 21:42:49 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 44740 invoked by uid 99); 14 Jan 2010 21:42:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 21:42:49 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=HS_INDEX_PARAM,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [204.209.205.13] (HELO defout.telus.net) (204.209.205.13) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 21:42:38 +0000 Received: from edmwaa03.telusplanet.net ([75.157.224.165]) by priv-edmwes50.telusplanet.net (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100114214215.TRMP8976.priv-edmwes50.telusplanet.net@edmwaa03.telusplanet.net>; Thu, 14 Jan 2010 14:42:15 -0700 Received: from [192.168.1.74] (d75-157-224-165.bchsia.telus.net [75.157.224.165]) by edmwaa03.telusplanet.net (BorderWare Security Platform) with ESMTP id 147B22756FC1B45B; Thu, 14 Jan 2010 14:42:14 -0700 (MST) Subject: Re: A ghost in the machine? Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset=us-ascii From: Eric Howe In-Reply-To: <4B4F8C70.6090401@1200group.com> Date: Thu, 14 Jan 2010 13:42:13 -0800 Cc: users Mod_perl Content-Transfer-Encoding: quoted-printable Message-Id: <327435C2-956D-4861-8755-5B29BF2ED817@pieinsky.ca> References: <4B4F6620.4090900@1200group.com> <0C4F9AE61E425F4F8C6912AF90E9A9E9C645E738@EX-SEA19-B.ant.amazon.com> <4B4F83CE.2050501@1200group.com> <4B4F8C70.6090401@1200group.com> To: Tosh Cooey X-Mailer: Apple Mail (2.1077) X-Virus-Checked: Checked by ClamAV on apache.org Hi Tosh, The function sigil ("&") is an archaic left over from before perl5. = Calling a function as "&cfg" is the same as saying "&cfg(@_)" and that = implicit "@_" was probably the source of your problem. A bit more = information can be found here: = http://www.perlfoundation.org/perl5/index.cgi?subroutines_called_with_the_= ampersand Executive summary: don't use "&" on a sub unless you need a sub-ref: my $x =3D \&cfg; $x->(); On 2010-01-14, at 13:28 , Tosh Cooey wrote: > Ok now I'm really boggled... >=20 > If I use: >=20 > my $vars =3D { config =3D> &cfg() }; > instead of: > my $vars =3D { config =3D> &cfg }; >=20 > Then it works! So what's the difference between &cfg and &cfg() when = it comes to mod_perl, or at least ModPerl::Registry? >=20 > Thank-you all... >=20 > Tosh >=20 >=20 > Tosh Cooey wrote: >> True, good point. I cleaned up my code and changed some things = around and I still have the same problem: >> index.pl >> ######## >> use MyConfig; >> use ClientConf; >> use MyUser; >> my $vars =3D { config =3D> &cfg }; >> MyConfig.pm >> ########### >> package MyConfig; >> use strict; >> use Exporter; >> use vars qw(@ISA @EXPORT); >> @ISA =3D qw(Exporter); >> @EXPORT =3D qw(&cfg &user); >> my %CFG =3D { global vars... }; >> sub cfg { >> return ClientConf->new(); >> } >> sub user { >> return MyUser->new(); >> } >> 1; >> The function "user" works just fine, it returns the object as = expected. >> #### BREAK #### >> So, while I was testing to make sure everything works exactly as I = described above I discovered unexpected behaviour. &cfg is actually: >> sub cfg { >> my ($cfg_var) =3D @_; >> if ($cfg_var) { >> ...do something... >> } else { >> return ClientConf->new(); >> } >> } >> &user is exactly as noted above. When I changed &user and added the = same $cfg_var and conditional it also did not return what I expected. >> So basically the problem I'm having is that even though I'm calling = &cfg without arguments that $cfg_var is evaluating as "TRUE", but only = under ModPerl::Registry and not under regular unadulterated PERL. >> As a PERL user for 15 years am I just the biggest newbie ever, or is = there something obscure going on that I should know about? >> Thanks for anything! >> Tosh >> Ihnen, David wrote: >>> Global? There's no need to use a global here. You only ever = reference %CFG *in* the package... so just make it package scoped - = it'll act like a static variable and persist. (scope it with 'my' and = remove it from the export) >>>=20 >>> You can always get the value you want with a call to MyConfig::cfg >>>=20 >>> David >>>=20 >>> -----Original Message----- >>> From: Tosh Cooey [mailto:tosh@1200group.com] Sent: Thursday, January = 14, 2010 10:45 AM >>> To: modperl@perl.apache.org >>> Subject: A ghost in the machine? >>>=20 >>> Hi to everyone! >>>=20 >>> I'm trying to find out if I'm passing objects properly under = mod_perl because something is not working as I expect. >>>=20 >>> index.pl >>> ######## >>> use MyConfig; >>> my $vars =3D { config =3D> &cfg }; >>>=20 >>>=20 >>> MyConfig.pm >>> ########### >>> package MyConfig; >>>=20 >>> use strict; >>> use Exporter; >>> use vars qw(@ISA @EXPORT %CFG ); >>> use ClientConf; >>> @ISA =3D qw(Exporter); >>> @EXPORT =3D qw(%CFG &cfg); >>>=20 >>> %CFG =3D { global vars... }; >>>=20 >>> sub cfg { >>> my $CFG{$clientID} =3D new ClientConf; >>> return $CFG{$clientID}; >>> } >>> 1; >>>=20 >>>=20 >>> Under normal PERL $vars->{config} is a MyConfig object. Under = mod_perl nothing is returned. Debugging with "print" statements in &cfg = shows me that "ref $CFG{$clientID}" is ClientConf, the object is there, = but upon return it just disappears. >>>=20 >>> I have other functions which "return new MyUser()" and these work = perfectly, so I'm thinking that the problem lies with the global = variable "$CFG" and that something which I think should be happening is = NOT happening. >>>=20 >>> I'm flummoxed... >>>=20 >>> Thank-you for any insights! >>>=20 >>> Tosh >>>=20 >=20 > --=20 > McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/ Eric Howe eric@pieinsky.ca