You can probably try the global variable approach:

Have a look at http://www.masonhq.com/docs/manual/1.28/Params.html#allow_globals
to allow your
$web variable to be accessible globally (a bit like the $m object).

Then you can initialize it only once in your top level <%once> block.

Cheers.

J.

On 14 June 2012 19:56, Paul Tomblin <ptomb...@xcski.com> wrote:
> I'm very new to Mason - I'm using it to do some customization to
> Request Tracker.
>
> I want all my custom pages to be able to access a class which, among
> other things, owns the handle to my database.  I created an
> autohandler:
>
> --start snip--
> % $m->call_next;
>
> <%once>
> my $web
> </%once>
>
> <%INIT>
> $RT::Logger->debug("my autohandler");
> use RTx::FooBar::Web;
> $web || RTx::FooBar::Web->new();
> </%INIT>
> --end snip--
>
> And I attempted to use this in my web page:
> --start snip--
> ...
> <%init>
> ...
>
> my $catRecs = RTx::FooBar::Records::Categorys->new(Handle => 
> $web->CFHandle());
> </%init>
> --end snip--
>
> But I get the error:
> --start snip--
> error:  Error during compilation of
> /opt/rt4/local/plugins/RTx-FooBar/html/cf/change_request.html:
> Global symbol "$web" requires explicit package name at
> /opt/rt4/local/plugins/RTx-FooBar/html/cf/change_request.html line 74.
>
> context:
> ...
> 70:  use RTx::FooBar::Records::Categorys;
> 71:
> 72:  my @clientFieldNames = ('First Name','Last Name','Phone
> #','Windows Acct', 'Location');
> 73:  my @clientFields =
> ('first_name','last_name','phone_number','windows_id', 'location_id');
> 74:  my $catRecs = RTx::FooBar::Records::Categorys->new(Handle =>
> $web->CFHandle());
> 75:  $catRecs->UnLimit;
> 76:  RT::Logger->debug("catRecs count = " . $catRecs->Count);
> 77:  my @categories = @{$catRecs->ItemsArrayRef};
> 78:
> --end snip--
>
> I've tried using <%share> and <%once>, with exactly the same results.
> How can I get the variable to be shared between the autohandler and
> the web pages?
>
> --
> http://www.linkedin.com/in/paultomblin
> http://careers.stackoverflow.com/ptomblin
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users



-- 
Jerome Eteve.

http://sigstp.blogspot.com/
http://twitter.com/jeteve

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to