Re: Other Globals in %once

Dave Rolsky <[email protected]>
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
On Thu, 29 Apr 2004, David Wheeler wrote:

> Interesting. The errors we're getting are when we try to compile a
> component:
>
>      my $interp = HTML::Mason::Interp->new(
>          'allow_globals' => [qw($story
>                                 $burner
>                                 $writer
>                                 $element)]
>          'in_package'    => TEMPLATE_BURN_PKG
>          'comp_root'     => $self->get_comp_dir,
>          'data_dir'      => $self->get_data_dir,
>      );
>
>      my $comp = eval { $interp->make_component(comp_source => $data) };
>
> However, the $story, $burner, $writer, and $element objects aren't
> actually assigned. This has never been a problem, because we're not
> executing the component, just compiling it. Does the %once block
> actually get executed by make_component()? If so, need it be? And if it
> must be, well, I guess I'll have to figure out a way to make mock
> objects to assign to those globals. Which would be a PITA.

Yes, the once block is executed when the component's compiled Perl code is
loaded/eval'd.  That's how we make sure that it's contents always stick
around in memory as long as the compiled component itself is in memory.
That's really the only good way to do it, I think.

> The globals are of course always assigned to when executing a component.

I think in your case you already know what those globals will be, so you
might as well assign them before making the component.


-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/


-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.