Anthony,
Long time no talk! Hope you're doing well. I've followed this
thread, and I think I have an idea about how this can work.
First, on the DataPlace project, we're now using Catalyst. It's a lot
more mechanism than plain Mason, but it provides some of these nice
features like a $stash that gets cleared out for you on every request,
and which is accessible to both your Controller and Model objects and
to the Mason templates that are used to render Views.
If you don't want to go that far, what I would suggest is that you
follow the allow_globals method Jonathan described, and then just
access them from within your Perl models by explicitly mentioning the
HTML::Mason::Commands package, like so:
--------------
In your httpd.conf or other perl init file that sets up Mason:
allow_globals [qw($stash)]
---------------
In autohandler or init.handler (something we often introduce to make
autohandler inherit from, so we can put the HTML template into
autohandler and the DB setup stuff into init.handler):
$stash = {}; # This is to clear out the stash at the start of each
request. Alternatively you could put this at the end of your
autohandler, and it would clear it out after the request is fully
rendered.
---------------
In Perl modules that you "use" from your Mason templates (or from the
global Interp object so they get preloaded)
Store into the stash like this
$HTML::Mason::Commands::stash->{message} = "This is a message for the
stash";
or perhaps:
$HTML::Mason::Commands::stash->{messages} ||= [];
push(@{$HTML::Mason::Commands::stash->{messages}}, "Another message
from my module");
---------------
Access the stash like this from a Perl module:
my $message = $HTML::Mason::Commands::stash->{message}
Or access it like this from a Mason component:
<% join('<br>', @{$stash->{messages}} %>
In this case, you still have to worry about the calling order, so that
you are sure you're storing values in the stash first and using them
later in the request life-cycle. But I think it will accomplish what
you want.
--Mark
On Dec 14, 2007, at 7:07 PM, Anthony Ettinger wrote:
> Can you perhaps provide a link to details about this technique? which
> files, how it gets instantiated, etc.
>
> I definitely want the "global" to be instantiated on each request,
> without sharing value between users. and then dies off at the end of
> the request.
>
> On Dec 14, 2007 4:52 PM, Jonathan Swartz <[EMAIL PROTECTED]> wrote:
>> If all you want is a global stash (as in TT), then you could create a
>> global called $stash visible to all components:
>>
>> allow_globals => [qw($stash)]
>> ...
>> $interp->set_global(stash => { ... });
>>
>> This is no different than
>>
>> package HTML::Mason::Commands;
>> use vars qw($stash);
>>
>> $HTML::Mason::Commands::stash = { ... };
>>
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users