[Catalyst] O?Reilly might yet be interested after all

Robert 'phaylon' Sedlacek rs at 474.at
Tue Feb 6 15:28:14 GMT 2007


Matt S Trout wrote:

> And I've found TT much, -much- easier to teach to designers than perl
> would be. The main thing to remember is that really, most of TT's syntax
> is just an escape hatch - if you're doing much more than a few FOREACH
> and WHILE loops you probably have logic that should be written in perl,
> maybe as a sub in the stash, maybe some other way.

I just got one of those idea thingies: Dynamic View Roles

  package MyApp::ViewRole::Foo;
  use base 'CatalystX::ViewRole::Role';

  sub foo: Export {
      my ($self, $c, @args) = @_;
      return $self->bar(@args);
  }

  sub bar { # not exported
      my ($self, @args) = @_;
      return join ', ', @args;
  }

And in our view, localising and modifying the stash before going on to
the original 'process' or 'render'.

  package MyApp::View::TT;
  use base qw(CatalystX::ViewRole::View Catalyst::View::TT);

  __PACKAGE__->config(...);

  1;

We specify the role(s) to use in our controller...

  sub foo: Chained { ...; $c->stash(view_roles => [qw(Foo)]) }
  # or
  sub foo: Chained ViewRoles('Foo') { ... }

And can just use it in our templates:

  The foo is set to [% foo(1, 2, 3) %]
  ...

Yeah, I know. Not enough coffee yet.

-- 
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail => ' rs at 474.at ', Web => ' http://474.at ' }



More information about the Catalyst mailing list