<div dir="ltr">On Mon, Jul 21, 2008 at 2:17 PM, Jesse Vincent &lt;<a href="mailto:jesse@bestpractical.com">jesse@bestpractical.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey Sterling,<br>
<br>
Can you tell us a bit about your &#39;Do&#39; actions? I&#39;m curious why just<br>
subclassing &#39;Update&#39; isn&#39;t easy enough.</blockquote><div><br>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:<br>
<br>Jifty-&gt;web-&gt;new_action(<br>&nbsp;&nbsp;&nbsp; class =&gt; &#39;StartTimer&#39;,<br>&nbsp;&nbsp;&nbsp; record =&gt; $timer,<br>)-&gt;run;<br><br>which is really just a thick wrapper for saying:<br><br>$timer-&gt;start_timer;<br><br>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:<br>
<br>package CubicleLog::Action::ChangeTime;<br>use base qw/ CubicleLog::Action::Record::Execute /;<br><br>use Jifty::Param::Schema;<br>use Jifty::Action schema {<br>param &#39;which&#39; =&gt; is mandatory, valid_values are qw/ start stop /, default is &#39;start&#39;;<br>
param &#39;new_time&#39; =&gt; is mandatory;<br>};<br><br>sub validate_new_time { ... }<br><br>sub take_action {<br>&nbsp;&nbsp;&nbsp; my $self = shift;<br>&nbsp;&nbsp;&nbsp; my $which = $self-&gt;argument_value(&#39;which&#39;);<br>&nbsp;&nbsp;&nbsp; my $set_time = &quot;set_${which}_time&quot;;<br>
&nbsp;&nbsp;&nbsp; $self-&gt;record-&gt;$set_time($self-&gt;argument_value(&#39;new_time&#39;));<br>&nbsp;&nbsp;&nbsp; $self-&gt;result-&gt;message(_(&#39;Set %1 time.&#39;, _($which)));<br>}<br><br>And then I can easily:<br><br>Jifty-&gt;web-&gt;new_action(<br>
&nbsp;&nbsp;&nbsp; class =&gt; &#39;ChangeTime&#39;,<br>&nbsp;&nbsp;&nbsp; record =&gt; $timer,<br>&nbsp;&nbsp;&nbsp; arguments =&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; which =&gt; &#39;stop&#39;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_time =&gt; Jifty::DateTime-&gt;now,<br>&nbsp;&nbsp;&nbsp; },<br>)-&gt;run;<br><br>Perhaps Update is enough to do that. However, it didn&#39;t seem right. It seemed cluttered to include all the fields of ::Update with that.<br>
<br>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&#39;ve added to a model (like start_timer, stop_timer, etc.).<br>
<br>It also seems like it should be possible to do this:<br><br>Jifty-&gt;web-&gt;new_action(<br>&nbsp;&nbsp;&nbsp; class =&gt; &#39;CreateSomething&#39;,<br>&nbsp;&nbsp;&nbsp; arguments =&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foo =&gt; &#39;bar&#39;,<br>&nbsp;&nbsp;&nbsp; },<br>)-&gt;run;<br>
<br>as easily as this:<br><br>my $model = MyApp::Model::Something-&gt;new;<br>$model-&gt;create( foo =&gt; &#39;bar&#39; );<br> <br>since CreateSomething is usually what I want to do, in case that involves special business logic. Then I can treat Something-&gt;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&#39;s &quot;around&quot; may lack an obvious solution.)<br>
<br>I&#39;m not sure if all of that is relevant to your question, but it&#39;s all connected in my mind.<br><br>Cheers,<br>Sterling<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
-j<br>
_______________________________________________<br>
jifty-devel mailing list<br>
<a href="mailto:jifty-devel@lists.jifty.org">jifty-devel@lists.jifty.org</a><br>
<a href="http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel" target="_blank">http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel</a><br>
</blockquote></div><br></div>