[Catalyst] TT custom virtual methods available to all pages.

Matt S Trout dbix-class at trout.me.uk
Wed Apr 23 20:44:38 BST 2008


On Wed, Apr 23, 2008 at 09:45:15AM -0500, Rajeev Cyrus wrote:
> Greetings.
> 
> One of my TT pages required some massaging of data that I decided to  
> do via referencing a subroutine in a template variable, eg:
> $c->stash->{mk_hash} = \&mk_hash;
> 
> I would like to use this stashed variable on all of my templates so my  
> question is:
> Where is the best place to initialize and set this variable? Where  
> should i declare the mk_hash method? Is there some way I can configure  
> catalyst to set certain template variables when the application starts?

package MyApp::View::TT;

use base qw(Catalyst::View::TT);

__PACKAGE__->config(
  ...
);

use Moose;

around template_vars => sub {
  my $orig = shift;
  my $self = shift;
  return (mk_hash => sub { ... }, $self->$orig(@_));
};

no Moose;

1;

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list