[Catalyst-commits] r10624 - in trunk/Catalyst-Example-InstantCRUD:
. lib/Catalyst/Example lib/Catalyst/Example/Controller
lib/Catalyst/Example/Controller/InstantCRUD
lib/Catalyst/Helper/Controller lib/Catalyst/Helper/View script t
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Tue Jun 23 19:54:24 GMT 2009
Author: zby
Date: 2009-06-23 19:54:24 +0000 (Tue, 23 Jun 2009)
New Revision: 10624
Modified:
trunk/Catalyst-Example-InstantCRUD/MANIFEST
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/Example/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl
trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t
trunk/Catalyst-Example-InstantCRUD/t/pod-coverage.t
Log:
FormHandler
Modified: trunk/Catalyst-Example-InstantCRUD/MANIFEST
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/MANIFEST 2009-06-23 19:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/MANIFEST 2009-06-23 19:54:24 UTC (rev 10624)
@@ -8,6 +8,8 @@
t/10.apptest.t
t/20.create_dvdzbr.t
t/21.test_dvdzbr.t
+t/30.create_rest.t
+t/31.test_rest.t
t/pod-coverage.t
t/pod.t
t/tmp/test.db
@@ -20,5 +22,5 @@
lib/Catalyst/Plugin/Auth/Utils.pm
lib/Catalyst/Example/InstantCRUD.pm
lib/Catalyst/Example/Controller/InstantCRUD.pm
-
+b/Catalyst/Example/Controller/InstantCRUD/REST.pm
META.yml Module meta-data (added by MakeMaker)
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:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD/REST.pm 2009-06-23 19:54:24 UTC (rev 10624)
@@ -14,7 +14,6 @@
use Carp;
use Data::Dumper;
-use Rose::HTMLx::Form::DBIC;
use version; our $VERSION = qv('0.0.1');
@@ -26,6 +25,28 @@
sub by_id : Local : ActionClass('REST') { }
+sub _get_form {
+ my( $self, $c, $pks ) = @_;
+ my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
+ my @ids;
+ @ids = ( item_id => $pks ) if defined $pks && @$pks;
+ my $form = $form_name->new(
+ schema => $self->model_schema($c),
+# item_class => $self->source_name($c),
+ method => $c->req->method,
+ params => $c->req->params,
+ @ids,
+ );
+ my $field = HTML::FormHandler::Field::Hidden->new(
+ name => 'x-tunneled-method',
+ form => $form,
+ value => 'PUT',
+ );
+ $form->add_field($field);
+ return $form;
+}
+
+
sub by_id_GET : Local {
my ( $self, $c, @args ) = @_;
my @model_pks = $self->model_pks( $c );
@@ -35,14 +56,7 @@
my $item = $self->model_item( $c, @pks );
$c->stash->{item} = $item;
if( $view_type eq 'edit' ){
- my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
- my $form = $form_name->new();
- $form->add_fields( 'x-tunneled-method' => { type => 'hidden', value => 'PUT' } );
- 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 );
- $processor->init_from_dbic(@pks) if scalar @pks;
+ my $form = $self->_get_form( $c, \@pks );
$c->stash( form => $form );
}
$c->stash( template => $view_type . '.tt' );
@@ -52,15 +66,9 @@
my ( $self, $c, @args ) = @_;
my @model_pks = $self->model_pks( $c );
my @pks = @args[ 0 .. scalar @model_pks - 1 ];
- my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
- my $form = $form_name->new();
- $form->add_fields( 'x-tunneled-method' => { type => 'hidden', value => 'PUT' } );
- 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 );
- my $item = $processor->dbic_from_form(@pks);
- if( $item ){
+ my $form = $self->_get_form( $c, \@pks );
+ if( $form->process ){
+ my $item = $form->item;
my @new_pks = map { $item->$_ } @model_pks;
$c->res->redirect( $c->uri_for( 'by_id', @new_pks ) );
}
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:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm 2009-06-23 19:54:24 UTC (rev 10624)
@@ -8,7 +8,7 @@
use Carp;
use Data::Dumper;
use Path::Class;
-use Rose::HTMLx::Form::DBIC;
+#use Rose::HTMLx::Form::DBIC;
use version; our $VERSION = qv('0.0.15');
@@ -45,6 +45,12 @@
return $c->model($model_name)->resultset($source);
}
+sub model_schema {
+ my ( $self, $c ) = @_;
+ my $model_name = $c->config->{InstantCRUD}{model_name};
+ return $c->model($model_name);
+}
+
sub index : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = lc( $self->source_name ) . '/list.tt';
@@ -73,19 +79,21 @@
sub edit : Local {
my ( $self, $c, @pks ) = @_;
my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
- my $processor = Rose::HTMLx::Form::DBIC->new(
- form => $form_name->new(),
- rs => $self->model_resultset($c),
+ my @ids;
+ @ids = ( item_id => [ @pks ] ) if @pks;
+ my $processor = $form_name->new(
+ schema => $self->model_schema($c),
+# item_class => $self->source_name($c),
method => $c->req->method,
params => $c->req->params,
- pks => [ @pks ],
+ @ids,
);
- my $item = $processor->process();
- if( $item ){
+ if( $processor->process() ){
+ my $item = $processor->item;
$c->res->redirect( $c->uri_for( 'view', $item->id ) );
$c->stash( item => $item );
}
- $c->stash( form => $processor->form );
+ $c->stash( form => $processor->render );
}
sub view : Local {
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/InstantCRUD.pm 2009-06-23 19:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/InstantCRUD.pm 2009-06-23 19:54:24 UTC (rev 10624)
@@ -1,6 +1,6 @@
package Catalyst::Example::InstantCRUD;
-use version; $VERSION = qv('0.0.30');
+use version; $VERSION = qv('0.0.31');
use warnings;
use strict;
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:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm 2009-06-23 19:54:24 UTC (rev 10624)
@@ -6,7 +6,7 @@
use strict;
use Path::Class;
use Data::Dumper;
-use Rose::HTMLx::Form::DBIC::FormGenerator;
+use HTML::FormHandler::Generator::DBIC;
sub mk_compclass {
my ( $self, $helper, $schema, $m2m) = @_;
@@ -24,13 +24,14 @@
my( $helper, $class, $schema, $m2m ) = @_;
$helper->{class} = $helper->{app} . '::Controller::' . $class;
(my $file = $helper->{file}) =~ s/InstantCRUD/$class/;
- my $generator = Rose::HTMLx::Form::DBIC::FormGenerator->new(
+ my $generator = HTML::FormHandler::Generator::DBIC->new(
schema => $schema,
class_prefix => $helper->{class},
style => 'single',
m2m => $m2m,
+ rs_name => $class,
);
- $helper->{form_code} = $generator->generate_form( $class );
+ $helper->{form_code} = $generator->generate_form();
$helper->render_file( compclass => $file );
}
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:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm 2009-06-23 19:54:24 UTC (rev 10624)
@@ -239,7 +239,7 @@
<br>
<a href="[% c.uri_for( 'list' ) %]">List</a>
<hr>
-[% form.html_table %]
+[% form %]
__pager__
[% IF pager %]
<div class="pager">
Modified: trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl 2009-06-23 19:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl 2009-06-23 19:54:24 UTC (rev 10624)
@@ -101,7 +101,7 @@
# debug => 1,
dump_directory => dir( $appdir , 'lib')->absolute->stringify,
use_namespaces => 1,
- default_resultset_class => '+DBIx::Class::ResultSet::RecursiveUpdate',
+# default_resultset_class => '+DBIx::Class::ResultSet::RecursiveUpdate',
components => 'UTF8Columns',
},
[ $dsn, $duser, $dpassword ],
Modified: trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t 2009-06-23 19:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/t/31.test_rest.t 2009-06-23 19:54:24 UTC (rev 10624)
@@ -21,5 +21,5 @@
$mech->default_header( 'Accept' => "text/x-json");
$mech->get_ok("http://localhost/dvd/by_id/2", "GET dvd object");
-warn $mech->content;
+#warn $mech->content;
Modified: trunk/Catalyst-Example-InstantCRUD/t/pod-coverage.t
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/pod-coverage.t 2009-06-23 19:54:14 UTC (rev 10623)
+++ trunk/Catalyst-Example-InstantCRUD/t/pod-coverage.t 2009-06-23 19:54:24 UTC (rev 10624)
@@ -1,6 +1,12 @@
#!perl -T
use Test::More;
-eval "use Test::Pod::Coverage 1.04";
-plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+if (!$ENV{AUTHOR_TEST}) {
+ plan skip_all => 'Author test';
+}
+else{
+ eval "use Test::Pod::Coverage 1.04";
+ plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+}
all_pod_coverage_ok();
+
More information about the Catalyst-commits
mailing list