I thought about rolling it into new_action directly (and it would be nicer there in some respects since you get it for free in Jifty::View::Declare::Helpers). I also thought about it as a method attached to the model:<br><br>
&nbsp; my $model = MyApp::Model::Employee-&gt;new;<br>&nbsp; $model-&gt;load(14);<br>&nbsp; my $action = $model-&gt;new_action(&#39;Create&#39;);<br><br>It was just something that I needed to patch CRUD to handle a wider range of classes, but seemed like it was something that would have a wider applicability. Whether it belongs with CRUD for now or just as an enhancement of new_action(), I&#39;m not sure I have a strong feeling either way on it.
<br><br><div><span class="gmail_quote">On 8/19/07, <b class="gmail_sendername">Jesse Vincent</b> &lt;<a href="mailto:jesse@bestpractical.com">jesse@bestpractical.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This feels like a weird thing. it&#39;s just not much syntactic sugar for<br>what it gives you. I wonder if it belongs in the CRUD stuff or if we<br>should be improving new_action...<br><br>On Aug 19, 2007, at 6:39 AM, <a href="mailto:jifty-commit@lists.jifty.org">
jifty-commit@lists.jifty.org</a> wrote:<br><br>&gt; Author: sterling<br>&gt; Date: Sun Aug 19 09:39:34 2007<br>&gt; New Revision: 3915<br>&gt;<br>&gt; Modified:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;jifty/trunk/&nbsp;&nbsp; (props changed)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;jifty/trunk/lib/Jifty/Web.pm
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;jifty/trunk/t/01-test-web.t<br>&gt;<br>&gt; Log:<br>&gt;&nbsp;&nbsp;r8812@riddle:&nbsp;&nbsp;andrew | 2007-08-19 08:38:43 -0500<br>&gt;&nbsp;&nbsp;Added a new helper, new_record_action(), that wraps new_action()<br>&gt; with additional help creating Create, Update, Delete, and Search
<br>&gt; actions for models.<br>&gt;<br>&gt;<br>&gt; Modified: jifty/trunk/lib/Jifty/Web.pm<br>&gt; ======================================================================<br>&gt; ========<br>&gt; --- jifty/trunk/lib/Jifty/Web.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(original)
<br>&gt; +++ jifty/trunk/lib/Jifty/Web.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sun Aug 19 09:39:34 2007<br>&gt; @@ -9,13 +9,11 @@<br>&gt;<br>&gt;&nbsp;&nbsp;=cut<br>&gt;<br>&gt; -<br>&gt; -<br>&gt; -<br>&gt;&nbsp;&nbsp;use CGI::Cookie;<br>&gt;&nbsp;&nbsp;use XML::Writer;<br>&gt;&nbsp;&nbsp;use CSS::Squish;
<br>&gt;&nbsp;&nbsp;use Digest::MD5 qw(md5_hex);<br>&gt; +use Scalar::Util qw(blessed);<br>&gt;&nbsp;&nbsp;use Carp qw(carp);<br>&gt;&nbsp;&nbsp;use base qw/Class::Accessor::Fast Class::Data::Inheritable<br>&gt; Jifty::Object/;<br>&gt;<br>&gt; @@ -566,6 +564,50 @@
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br>&gt;&nbsp;&nbsp;}<br>&gt;<br>&gt; +=head3 new_record_action model =&gt; MODELCLASS, record_action =&gt;<br>&gt; RECORD_ACTION, PARAMHASH<br>&gt; +<br>&gt; +This takes all the same arguments as L&lt;/new_action&gt;, except that
<br>&gt; you specify the C&lt;model&gt; and C&lt;record_action&gt; rather than the<br>&gt; C&lt;class&gt;. This helps you create a record action.<br>&gt; +<br>&gt; +You must give the C&lt;model&gt; argument, which may either be an
<br>&gt; instance of the model or the class name.<br>&gt; +<br>&gt; +The C&lt;record_action&gt; is optional and defaults to &#39;Update&#39; if not<br>&gt; given. It can be set to &#39;Create&#39;, &#39;Update&#39;, &#39;Delete&#39;, or &#39;Search&#39;.
<br>&gt; +<br>&gt; +For example:<br>&gt; +<br>&gt; +&nbsp;&nbsp;my $record = MyApp::Model::Employee-&gt;new;<br>&gt; +&nbsp;&nbsp;$record-&gt;load(14);<br>&gt; +<br>&gt; +&nbsp;&nbsp;my $action = Jifty-&gt;web-&gt;new_record_action(<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; $record,
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record_action =&gt; &#39;Delete&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; $record,<br>&gt; +&nbsp;&nbsp;);<br>&gt; +<br>&gt; +&nbsp;&nbsp;# $action is now an instance of MyApp::Model::DeleteEmployee<br>&gt; +<br>&gt; +=cut<br>
&gt; +<br>&gt; +sub new_record_action {<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;my $self = shift;<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;my %args = (<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; undef,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record_action =&gt; &#39;Update&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@_<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;);
<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;# Get the name of the model class and action<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;my $model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = delete $args{model};<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;my $action_class&nbsp;&nbsp;= blessed $model || $model;<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;my $record_action = delete $args{record_action};
<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;# Convert it to the action<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;$action_class =~ s/::Model::/::Action::$record_action/;<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;# Add it to the arguments and call new_action()<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;$args{class} = $action_class;
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;return $self-&gt;new_action( %args );<br>&gt; +}<br>&gt; +<br>&gt;&nbsp;&nbsp;=head3 failed_actions<br>&gt;<br>&gt;&nbsp;&nbsp;Returns an array of L&lt;Jifty::Action&gt; objects, one for each<br>&gt;<br>&gt; Modified: jifty/trunk/t/01-
test-web.t<br>&gt; ======================================================================<br>&gt; ========<br>&gt; --- jifty/trunk/t/01-test-web.t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (original)<br>&gt; +++ jifty/trunk/t/01-test-web.t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sun Aug 19 09:39:34 2007
<br>&gt; @@ -1,6 +1,6 @@<br>&gt;&nbsp;&nbsp;#!/usr/bin/perl -w<br>&gt;<br>&gt; -use Jifty::Test tests =&gt; 5;<br>&gt; +use Jifty::Test tests =&gt; 9;<br>&gt;<br>&gt;&nbsp;&nbsp;my $web = Jifty::Test-&gt;web;<br>&gt;&nbsp;&nbsp;isa_ok( $web-&gt;request,&nbsp;&nbsp;&quot;Jifty::Request&quot;&nbsp;&nbsp;);
<br>&gt; @@ -36,3 +36,39 @@<br>&gt;&nbsp;&nbsp;$web = Jifty::Test-&gt;web;<br>&gt;&nbsp;&nbsp;isa_ok( $web-&gt;request,&nbsp;&nbsp;&quot;Jifty::Request::Subclass&quot;&nbsp;&nbsp;);<br>&gt;&nbsp;&nbsp;isa_ok( $web-&gt;response, &quot;Jifty::Response::Subclass&quot; );<br>
&gt; +<br>&gt; +# Testing new_record_action()<br>&gt; +{<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;no warnings &#39;redefine&#39;;<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;# Create a mock new_action()<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;$orig_new_action = \&amp;Jifty::Web::new_action;<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;*Jifty::Web::new_action = sub {
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is($args{class}, $args{expected});<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;};<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;Jifty-&gt;web-&gt;new_record_action(<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#39;Jifty::Model::ModelClass&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#39;Jifty::Action::UpdateModelClass&#39;,
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;);<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;Jifty-&gt;web-&gt;new_record_action(<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#39;Jifty::Model::ModelClass&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record_action =&gt; &#39;Delete&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#39;Jifty::Action::DeleteModelClass&#39;,
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;);<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;Jifty-&gt;web-&gt;new_record_action(<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#39;TestApp::Model::Employee&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#39;TestApp::Action::UpdateEmployee&#39;,
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;);<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;Jifty-&gt;web-&gt;new_record_action(<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#39;TestApp::Model::Employee&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;record_action =&gt; &#39;Search&#39;,<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#39;TestApp::Action::SearchEmployee&#39;,
<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;);<br>&gt; +<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;# Restore the original<br>&gt; +&nbsp;&nbsp;&nbsp;&nbsp;*Jifty::Web::new_action = $orig_new_action;<br>&gt; +}<br>&gt; _______________________________________________<br>&gt; Jifty-commit mailing list<br>
&gt; <a href="mailto:Jifty-commit@lists.jifty.org">Jifty-commit@lists.jifty.org</a><br>&gt; <a href="http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit">http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
</a><br>&gt;<br><br><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">
http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel</a><br><br><br></blockquote></div><br>