Re: Other Globals in %once
"Jonathan Swartz" <[email protected]>
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: "Dave Rolsky" <[email protected]> To: "David Wheeler" <[email protected]> Cc: "Jonathan Swartz" <[email protected]>; "Mason Developers" <[email protected]>; "Serge Sozonoff" <[email protected]> Sent: Saturday, May 01, 2004 11:58 AM Subject: Re: [Mason-devel] Other Globals in %once > On Sat, 1 May 2004, David Wheeler wrote: > > > No, I mean that $m is available but undefined in %once blocks. If what > > Dave tells me is correct, then other globals created by allow_globals > > and set_global() are already assigned before the %once block executes, > > so ignore the "other globals" part. So yes, I'm referring to loading > > the component before the globals are defined. > > > > $m and $r are undefined in %once blocks, and I'm not sure the reasons > > for that are compelling enough. Seems to me that the Perl way is to > > allow the flexibility to use them, with the caveats well documented. > > IOW, give Masonites enough rope to shoot themselves in the foot. ;-) > > Actually, I thought of a compelling reason that this won't go into the > current stable branch, at least ;) > > The changes to make this work would require a bit more code surgery than > I'd like. Specifically, we currently set the $m variable in > Request->exec. To make it available in <%once>, we'd have to set it in > the Interp object instead, and I'm not sure where. It could be in load(), > but then it'd get reset every time a new component is loaded, which can > happen multiple times in a request. Also, we'd need to think about this > should work in the face of subrequests. > > So while I'm not entirely opposed to this, I don't think it's something > that can go in the stable branch. I'm opposed to it, for these reasons: 1. $m isn't guaranteed to be defined in <%once>, since you can load a component outside the context of a request, e.g. when preloading. I don't think a component should stop working when you preload it. That's a decision that might be made by someone far from the person developing the component. 2. As Serge points out, <%once> may execute or not execute for any arbitrary request, depending on the whim of the component cache. So you shouldn't be defining anything in <%once> that depends on the current request ($m). David, I'm not clear on what you were planning to use $m for in <%once>. Was it for something that would always be the same regardless of the current request? Jon ------------------------------------------------------- This SF.Net email is sponsored by: Oracle 10g Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE. http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click