[jifty-devel] "Do" actions

Sterling Hanenkamp sterling at hanenkamp.com
Mon Jul 21 18:01:17 EDT 2008

On Mon, Jul 21, 2008 at 2:17 PM, Jesse Vincent <jesse at bestpractical.com>

> Hey Sterling,
> Can you tell us a bit about your 'Do' actions? I'm curious why just
> subclassing 'Update' isn't easy enough.

Because subclassing Update comes with all the baggage of all my record
columns. I just wanted something simple that cares only about the record
itself and possibly some extra parameters. For example, I might have a very
simple task like this:

    class => 'StartTimer',
    record => $timer,

which is really just a thick wrapper for saying:


Or I might want to have a simplified action for changing timers. For
example, I can with a single form change either the start time or the stop

package CubicleLog::Action::ChangeTime;
use base qw/ CubicleLog::Action::Record::Execute /;

use Jifty::Param::Schema;
use Jifty::Action schema {
param 'which' => is mandatory, valid_values are qw/ start stop /, default is
param 'new_time' => is mandatory;

sub validate_new_time { ... }

sub take_action {
    my $self = shift;
    my $which = $self->argument_value('which');
    my $set_time = "set_${which}_time";
    $self->result->message(_('Set %1 time.', _($which)));

And then I can easily:

    class => 'ChangeTime',
    record => $timer,
    arguments => {
        which => 'stop',
        new_time => Jifty::DateTime->now,

Perhaps Update is enough to do that. However, it didn't seem right. It
seemed cluttered to include all the fields of ::Update with that.

This is also wrapped up with this is another issue for me. Actions are a
little hard for me to categorize since they just seem like functors with a
bunch of extra traits attached to the parameters defining form
characteristics, validation, canonicalization, etc. I feel like I want a
really generic way of creating actions that just execute whatever function
I've added to a model (like start_timer, stop_timer, etc.).

It also seems like it should be possible to do this:

    class => 'CreateSomething',
    arguments => {
        foo => 'bar',

as easily as this:

my $model = MyApp::Model::Something->new;
$model->create( foo => 'bar' );

since CreateSomething is usually what I want to do, in case that involves
special business logic. Then I can treat Something->create() as a low-level
method and CreateSomething as the high level. Putting a bunch of
before/after triggers into the Something model is a possible alternative,
but there are things that are difficult when you do that. (For example,
trying to perform the equivalent of Moose's "around" may lack an obvious

I'm not sure if all of that is relevant to your question, but it's all
connected in my mind.


> -j
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20080721/bba67be9/attachment.htm 

More information about the jifty-devel mailing list