[Catalyst] access stash outside methods

Jonathan Rockway jon at jrock.us
Wed Aug 22 02:00:03 GMT 2007


Aditya Verma wrote:
> Hi All,
>
> I want all of my controllers to register there respective URLs with
> description. this data will be used in template to create dynamic HTML
> pages.
> controllers will register URLs at catalyst startup.
>
> I have to store this data into variable (not in any file or database)
> which will be accessible in all the controllers.
> To get the registration work I have to write statement outside of all
> controller methods to execute the same at the time of catalyst startup. =


How about using attributes?

   pacakge MyApp::Controller::Anything;
   use base 'MyApp::Controler::HasDescription';
  =

   sub some_action
          :Path :Args(1) :URL('/some_action/*') :Description('Some
action!') {
      # your action
   }
   # etc.

Those get parsed at startup time, and you can probably shove them in
$app->config or somewhere similarly convenient.  You can also just walk
all actions and look for the URL and Description attributes.  This is
pretty easy to do, but I don't know the details so I will let you glean
them from the code/docs. $c->action_for('/some_action')->attributes
should be close.  Have fun.

Regards,
Jonathan Rockway




-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 370 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070821/c082=
c2d8/signature.pgp


More information about the Catalyst mailing list