[Catalyst-commits] r10623 - in trunk/Catalyst-Example-InstantCRUD:
lib/Catalyst/Example/Controller
lib/Catalyst/Example/Controller/InstantCRUD
lib/Catalyst/Helper/Controller lib/Catalyst/Helper/View t
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Tue Jun 23 19:54:14 GMT 2009
Author: zby
Date: 2009-06-23 19:54:14 +0000 (Tue, 23 Jun 2009)
New Revision: 10623
Added:
trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t
Modified:
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD/REST.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm
Log:
REST
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD/REST.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD/REST.pm 2009-06-23 19:40:20 UTC (rev 10622)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD/REST.pm 2009-06-23 19:54:14 UTC (rev 10623)
@@ -3,8 +3,15 @@
package Catalyst::Example::Controller::InstantCRUD::REST;
-use base 'Catalyst::Example::Controller::InstantCRUD';
+use base qw/ Catalyst::Example::Controller::InstantCRUD /;
+use Class::C3;
+sub create_action {
+ my $self = shift;
+
+ return $self->maybe::next::method(@_);
+}
+
use Carp;
use Data::Dumper;
use Rose::HTMLx::Form::DBIC;
@@ -24,7 +31,7 @@
my @model_pks = $self->model_pks( $c );
my @pks = @args[ 0 .. scalar @model_pks - 1 ];
my $view_type = $args[ scalar @model_pks ];
- $view_type = 'view' if $view_type ne 'edit';
+ $view_type = 'view' if !defined( $view_type ) or $view_type ne 'edit';
my $item = $self->model_item( $c, @pks );
$c->stash->{item} = $item;
if( $view_type eq 'edit' ){
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm 2009-06-23 19:40:20 UTC (rev 10622)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm 2009-06-23 19:54:14 UTC (rev 10623)
@@ -73,21 +73,19 @@
sub edit : Local {
my ( $self, $c, @pks ) = @_;
my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
- my $form = $form_name->new();
- my $rs = $self->model_resultset($c);
- my $processor = Rose::HTMLx::Form::DBIC->new( form => $form, rs => $rs );
- my $params = $c->req->params;
- $processor->init_params( $params );
- if( $c->req->method eq 'POST' and $form->was_submitted ){
- if( my $item = $processor->dbic_from_form(@pks) ){
+ my $processor = Rose::HTMLx::Form::DBIC->new(
+ form => $form_name->new(),
+ rs => $self->model_resultset($c),
+ method => $c->req->method,
+ params => $c->req->params,
+ pks => [ @pks ],
+ );
+ my $item = $processor->process();
+ if( $item ){
$c->res->redirect( $c->uri_for( 'view', $item->id ) );
$c->stash( item => $item );
- }
}
- else {
- $processor->init_from_dbic(@pks) if scalar @pks;
- }
- $c->stash( form => $form );
+ $c->stash( form => $processor->form );
}
sub view : Local {
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm 2009-06-23 19:40:20 UTC (rev 10622)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm 2009-06-23 19:54:14 UTC (rev 10623)
@@ -61,7 +61,8 @@
serialize => {
default => 'text/html',
map => {
- 'text/html' => [ 'View', 'TT' ],
+ 'text/html' => [ 'View', 'TT' ],
+ 'text/x-json' => 'JSON::Syck',
}
}
);
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm 2009-06-23 19:40:20 UTC (rev 10622)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm 2009-06-23 19:54:14 UTC (rev 10623)
@@ -193,7 +193,7 @@
</table>
[% PROCESS pager.tt %]
<br/>
-<a href="[% c.uri_for( 'create_form' ) %]">Add</a>
+<a href="[% c.uri_for( '<+ IF rest +>create_form<+ ELSE +>edit<+ END +>' ) %]">Add</a>
__view__
[% TAGS <+ +> %]
Added: trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t (rev 0)
+++ trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t 2009-06-23 19:54:14 UTC (rev 10623)
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+use lib 't/tmp/DVDzbr_rest/lib';
+}
+
+eval "use Test::WWW::Mechanize::Catalyst 'DVDzbr_rest'";
+if ($@){
+ plan skip_all => "Test::WWW::Mechanize::Catalyst required for testing application";
+}else{
+ plan tests => 2;
+ #plan tests => 'no_plan';
+}
+
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok("http://localhost/", "Application Running");
+
+$mech->default_header( 'Content-Type' => "text/x-json");
+$mech->default_header( 'Accept' => "text/x-json");
+
+$mech->get_ok("http://localhost/dvd/by_id/2", "GET dvd object");
+warn $mech->content;
+
More information about the Catalyst-commits
mailing list