[jifty-devel] "Do" actions
Jesse Vincent
jesse at bestpractical.com
Mon Jul 21 18:04:55 EDT 2008
On Jul 21, 2008, at 3:01 PM, Sterling Hanenkamp wrote:
> On Mon, Jul 21, 2008 at 2:17 PM, Jesse Vincent <jesse at bestpractical.com
> > wrote:
> 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:
>
That feels like maybe we really want to make it easier to replace all
the columns when you subclass.
Is Execute only an abstract action class?
> Jifty->web->new_action(
> class => 'StartTimer',
> record => $timer,
> )->run;
>
> which is really just a thick wrapper for saying:
>
> $timer->start_timer;
>
> 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 time:
>
> 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 'start';
> 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->record->$set_time($self->argument_value('new_time'));
> $self->result->message(_('Set %1 time.', _($which)));
> }
>
> And then I can easily:
>
> Jifty->web->new_action(
> class => 'ChangeTime',
> record => $timer,
> arguments => {
> which => 'stop',
> new_time => Jifty::DateTime->now,
> },
> )->run;
>
> 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:
>
> Jifty->web->new_action(
> class => 'CreateSomething',
> arguments => {
> foo => 'bar',
> },
> )->run;
>
> 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 solution.)
>
> I'm not sure if all of that is relevant to your question, but it's
> all connected in my mind.
>
> Cheers,
> Sterling
>
>
>
> -j
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
> _______________________________________________
> 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/93906dfc/attachment.htm
More information about the jifty-devel
mailing list