Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jk2addict (4946)

  (email not shown publicly)
AOL IM: chrislaco (Add Buddy, Send Message)
Yahoo! ID: (Add User, Send Message)

Journal of jk2addict (4946)

Tuesday May 29, 2007
09:42 PM

Catalyst::Action: Good Magic

[ #33371 ]
I'm not sure how I managed to get this far into Handel/Mango Catalyst bits without ever knowing/understanding the magic that is Catalyst::Action. The requirement was easy: add a :FormFile attribute to the Mango controllers so one could override the default form used with actions like create/edit:

sub edit : Local FormFile('/path/to/form.yml') {
    my $form = $self->form;

I surfed through things I knew futzed with actions. Controller::FormBuilder, Action:REST, etc. They all seemed large, or complicated, esp when you don't grok what the hell is really going on behind the scenes. After a pointer to $c->action->attribute by JMax, it all became quite clear; and easy: First, just add an attribute parser to the controller:

sub _parse_FormFile_attr {
    my ($self, $c, $name, $value) = @_;

    if (my $form = $self->_load_form_from_file($c, $value)) {
        return Form => $form;


This saves the form the 'Form' attribute for the current sub/action. Then it's just a matter of sucking out the attribute for the current action when requested:

    if (exists $c->action->attributes->{'Form'}) {
        $form = $c->action->attributes->{'Form'}->[-1];

That's it. Sure, there are more way to skin this cat, especially if you go all out on an :ActionClass(). But it got me where I needed to go without a whole lot of code.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.