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>
my $model = MyApp::Model::Employee->new;<br> $model->load(14);<br> my $action = $model->new_action('Create');<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'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> <<a href="mailto:jesse@bestpractical.com">jesse@bestpractical.com</a>> 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'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>> Author: sterling<br>> Date: Sun Aug 19 09:39:34 2007<br>> New Revision: 3915<br>><br>> Modified:<br>> jifty/trunk/ (props changed)<br>> jifty/trunk/lib/Jifty/Web.pm
<br>> jifty/trunk/t/01-test-web.t<br>><br>> Log:<br>> r8812@riddle: andrew | 2007-08-19 08:38:43 -0500<br>> Added a new helper, new_record_action(), that wraps new_action()<br>> with additional help creating Create, Update, Delete, and Search
<br>> actions for models.<br>><br>><br>> Modified: jifty/trunk/lib/Jifty/Web.pm<br>> ======================================================================<br>> ========<br>> --- jifty/trunk/lib/Jifty/Web.pm (original)
<br>> +++ jifty/trunk/lib/Jifty/Web.pm Sun Aug 19 09:39:34 2007<br>> @@ -9,13 +9,11 @@<br>><br>> =cut<br>><br>> -<br>> -<br>> -<br>> use CGI::Cookie;<br>> use XML::Writer;<br>> use CSS::Squish;
<br>> use Digest::MD5 qw(md5_hex);<br>> +use Scalar::Util qw(blessed);<br>> use Carp qw(carp);<br>> use base qw/Class::Accessor::Fast Class::Data::Inheritable<br>> Jifty::Object/;<br>><br>> @@ -566,6 +564,50 @@
<br>> );<br>> }<br>><br>> +=head3 new_record_action model => MODELCLASS, record_action =><br>> RECORD_ACTION, PARAMHASH<br>> +<br>> +This takes all the same arguments as L</new_action>, except that
<br>> you specify the C<model> and C<record_action> rather than the<br>> C<class>. This helps you create a record action.<br>> +<br>> +You must give the C<model> argument, which may either be an
<br>> instance of the model or the class name.<br>> +<br>> +The C<record_action> is optional and defaults to 'Update' if not<br>> given. It can be set to 'Create', 'Update', 'Delete', or 'Search'.
<br>> +<br>> +For example:<br>> +<br>> + my $record = MyApp::Model::Employee->new;<br>> + $record->load(14);<br>> +<br>> + my $action = Jifty->web->new_record_action(<br>> + model => $record,
<br>> + record_action => 'Delete',<br>> + record => $record,<br>> + );<br>> +<br>> + # $action is now an instance of MyApp::Model::DeleteEmployee<br>> +<br>> +=cut<br>
> +<br>> +sub new_record_action {<br>> + my $self = shift;<br>> + my %args = (<br>> + model => undef,<br>> + record_action => 'Update',<br>> + @_<br>> + );
<br>> +<br>> + # Get the name of the model class and action<br>> + my $model = delete $args{model};<br>> + my $action_class = blessed $model || $model;<br>> + my $record_action = delete $args{record_action};
<br>> +<br>> + # Convert it to the action<br>> + $action_class =~ s/::Model::/::Action::$record_action/;<br>> +<br>> + # Add it to the arguments and call new_action()<br>> + $args{class} = $action_class;
<br>> + return $self->new_action( %args );<br>> +}<br>> +<br>> =head3 failed_actions<br>><br>> Returns an array of L<Jifty::Action> objects, one for each<br>><br>> Modified: jifty/trunk/t/01-
test-web.t<br>> ======================================================================<br>> ========<br>> --- jifty/trunk/t/01-test-web.t (original)<br>> +++ jifty/trunk/t/01-test-web.t Sun Aug 19 09:39:34 2007
<br>> @@ -1,6 +1,6 @@<br>> #!/usr/bin/perl -w<br>><br>> -use Jifty::Test tests => 5;<br>> +use Jifty::Test tests => 9;<br>><br>> my $web = Jifty::Test->web;<br>> isa_ok( $web->request, "Jifty::Request" );
<br>> @@ -36,3 +36,39 @@<br>> $web = Jifty::Test->web;<br>> isa_ok( $web->request, "Jifty::Request::Subclass" );<br>> isa_ok( $web->response, "Jifty::Response::Subclass" );<br>
> +<br>> +# Testing new_record_action()<br>> +{<br>> + no warnings 'redefine';<br>> +<br>> + # Create a mock new_action()<br>> + $orig_new_action = \&Jifty::Web::new_action;<br>> + *Jifty::Web::new_action = sub {
<br>> + is($args{class}, $args{expected});<br>> + };<br>> +<br>> + Jifty->web->new_record_action(<br>> + model => 'Jifty::Model::ModelClass',<br>> + expected => 'Jifty::Action::UpdateModelClass',
<br>> + );<br>> +<br>> + Jifty->web->new_record_action(<br>> + model => 'Jifty::Model::ModelClass',<br>> + record_action => 'Delete',<br>> + expected => 'Jifty::Action::DeleteModelClass',
<br>> + );<br>> +<br>> + Jifty->web->new_record_action(<br>> + model => 'TestApp::Model::Employee',<br>> + expected => 'TestApp::Action::UpdateEmployee',
<br>> + );<br>> +<br>> + Jifty->web->new_record_action(<br>> + model => 'TestApp::Model::Employee',<br>> + record_action => 'Search',<br>> + expected => 'TestApp::Action::SearchEmployee',
<br>> + );<br>> +<br>> + # Restore the original<br>> + *Jifty::Web::new_action = $orig_new_action;<br>> +}<br>> _______________________________________________<br>> Jifty-commit mailing list<br>
> <a href="mailto:Jifty-commit@lists.jifty.org">Jifty-commit@lists.jifty.org</a><br>> <a href="http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit">http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
</a><br>><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>