[Catalyst] Reusable actions, AOP vs. other styles

Dominique Quatravaux dom at idealx.com
Fri Apr 7 09:31:46 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sebastian Riedel wrote:

>
> Ok, i'll try to write a short answer.
>
> Reusable actions doesn't mean they have to be the exact same. You
> may have complicated generic actions, for example to add a new
> record to a dbic model. (this can be generic, dbic class
> independent)

I do workflow stuff for a living, and this is potentially of huge
interest to me. If I understand correctly, I'll be able to code the
concept of "double validation" as a generic controller, and specialize
the nitty-gritty details (e.g. the contents of the validation forms)
on a per-workflow basis.

> sub add : Local : Action('Add') { my ( $self, $c ) = @_;
> $c->stash->{validate} = HTML::Widget->new;
> $c->stash->{validate}->constraint( 'ASCII', 'foo' ); }

This means that ->add() will get executed *before* the code for a
generic Add action, which expects a $c->stash->{validate} to be  set
up already for it, correct? I've always wondered, how is this AOP
thingy better / different from a controller that separates generics
from specifics using plain old OO inheritance, e.g.

  package My::Crud;

  use base "Generic::Crud";

  sub add : Local {
     my ($self, $c) = @_;
     $c->stash->{validate} = HTML::Widget->new;
     $c->stash->{validate}->constraint(' ASCII', 'foo');
     $self->SUPER::add($c);
  }

or what about the so-called "IOC" style:

  package Generic::Crud;

  sub add : Local {
     my ($self, $c) = @_;
     my $validator = $self->validator_widget();
     $validator->do_whatever_you_please_with_it();
  }

  package My::Crud;

  use base "Generic::Crud";

  sub validator_widget {
     my ($self, $c) = @_;
     my $widget = HTML::Widget->new;
     $widget->constraint(' ASCII', 'foo');
     return $widget;
  }

Would you please offer some enlightenment as to why you prefer AOP?

- --
Dominique QUATRAVAUX                           Ingénieur senior
01 44 42 00 08                                 IDEALX

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFENhVgMJAKAU3mjcsRArwMAJ9LKrob6PDHhOf0ka+eJjWi9rX8ogCcCP5q
IKQyHcSZCc+0xZWgHLnHMmE=
=RlvU
-----END PGP SIGNATURE-----





More information about the Catalyst mailing list