[Catalyst-commits] r7486 - in
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO: . trunk
trunk/lib trunk/lib/CatalystX trunk/lib/CatalystX/CRUD
trunk/lib/CatalystX/CRUD/Controller trunk/t
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Tue Mar 11 17:20:17 GMT 2008
Author: karpet
Date: 2008-03-11 17:20:15 +0000 (Tue, 11 Mar 2008)
New Revision: 7486
Added:
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/branches/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/MANIFEST
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Makefile.PL
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/README
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/00-load.t
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/boilerplate.t
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod-coverage.t
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod.t
Log:
import from peknet
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,37 @@
+Revision history for CatalystX-CRUD-Controller-RHTMLO
+
+0.01 19 Oct 2007
+ First version, released on an unsuspecting world.
+
+0.02 20 Oct 2007
+ * fix POD line so that CPAN doesn't think there's doc separate from code
+
+0.03 23 Oct 2007
+
+0.04 25 Oct 2007
+ * override form() to stash the $c object in app()
+
+0.05 1 November 2007
+ * return from do_search() if no input to form
+ * pass field names on to NEXT do_search so they make it to make_query()
+
+0.06 9 Nov 2007
+ * fix legacy refactoring bug in form_to_object() (no such thing as param_hash() method)
+ Thanks to John Siracusa for the catch.
+
+0.07 16 Nov 2007
+ * fix bug with form->init_fields where values were being un-initialized if params were not
+ present.
+
+0.08 17 Nov 2007
+ * fix bug when checking for whether do_search() should be performed.
+
+0.09 31 Dec 2007
+ * implement field_names() per CXC::Controller API.
+ * fix bug in form() where app() would be set to undef if $c was not passed.
+ * added custom create() to allow for form prepopulation via $c->req->params
+ * make debug() statement in do_search() conditional on $c->debug
+
+0.10 29 Jan 2008
+ * fix bug to allow for PKs that are not serial ints
+
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/MANIFEST
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/MANIFEST (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/MANIFEST 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,10 @@
+Changes
+MANIFEST
+#META.yml # Will be created by "make dist"
+Makefile.PL
+README
+lib/CatalystX/CRUD/Controller/RHTMLO.pm
+t/00-load.t
+t/boilerplate.t
+t/pod-coverage.t
+t/pod.t
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Makefile.PL
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Makefile.PL (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Makefile.PL 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'CatalystX::CRUD::Controller::RHTMLO',
+ AUTHOR => 'Peter Karman <karman at cpan.org>',
+ VERSION_FROM => 'lib/CatalystX/CRUD/Controller/RHTMLO.pm',
+ ABSTRACT_FROM => 'lib/CatalystX/CRUD/Controller/RHTMLO.pm',
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'CatalystX::CRUD' => 0.20,
+
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'CatalystX-CRUD-Controller-RHTMLO-*' },
+);
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/README
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/README (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/README 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,38 @@
+CatalystX-CRUD-Controller-RHTMLO
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::Controller::RHTMLO
+
+You can also look for information at:
+
+ Search CPAN
+ http://search.cpan.org/dist/CatalystX-CRUD-Controller-RHTMLO
+
+ CPAN Request Tracker:
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Controller-RHTMLO
+
+ AnnoCPAN, annotated CPAN documentation:
+ http://annocpan.org/dist/CatalystX-CRUD-Controller-RHTMLO
+
+ CPAN Ratings:
+ http://cpanratings.perl.org/d/CatalystX-CRUD-Controller-RHTMLO
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2007 Peter Karman
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,220 @@
+package CatalystX::CRUD::Controller::RHTMLO;
+use strict;
+use base qw( CatalystX::CRUD::Controller );
+use NEXT;
+use Carp;
+
+our $VERSION = '0.10';
+
+=head1 NAME
+
+CatalystX::CRUD::Controller::RHTMLO - Rose::HTML::Objects CRUD controller
+
+=head1 SYNOPSIS
+
+ see CatalystX::CRUD::Controller
+
+=head1 DESCRIPTION
+
+This is an implementation of CatalystX::CRUD::Controller
+for Rose::HTML::Objects. It supercedes Catalyst::Controller::Rose for
+basic CRUD applications.
+
+=cut
+
+=head1 METHODS
+
+The following methods are new or override base methods.
+
+=cut
+
+=head2 create
+
+Attribute: Local
+
+Overrides base create() to optionally pre-populate form
+with param-based values.
+
+=cut
+
+sub create : Local {
+ my ( $self, $c ) = @_;
+ $c->forward( 'fetch', [0] );
+ $c->forward('edit');
+ for my $field ( $self->field_names ) {
+ if ( exists $c->req->params->{$field} ) {
+ $c->stash->{form}
+ ->field_value( $field, $c->req->params->{$field} );
+ }
+ }
+}
+
+=head2 form( [ I<context> ] )
+
+Returns an instance of config->{form_class}.
+A single form object is instantiated and cached in the controller object.
+The form's clear() method is called before returning.
+If I<context> object is passed it is stashed via the forms's app() method.
+
+B<NOTE:> The form is cleared only the B<first time>
+form() is called in each request cycle, and only if I<content> is present.
+This is B<different> than the behaviour described in
+CatalystX::CRUD::Controller.
+
+=cut
+
+sub form {
+ my ( $self, $c ) = @_;
+ $self->{_form} ||= $self->form_class->new;
+ if ($c) {
+ $self->{_form}->clear unless $c->stash->{_form_called}++;
+ $self->{_form}->app($c);
+ }
+ return $self->{_form};
+}
+
+=head2 field_names
+
+Returns an array ref of the field names in form.
+
+=cut
+
+sub field_names {
+ my ($self) = @_;
+ return $self->form->field_names;
+}
+
+=head2 form_to_object( I<context> )
+
+Overrides base method.
+
+=cut
+
+sub form_to_object {
+ my ( $self, $c ) = @_;
+
+ my $form = $c->stash->{form};
+ my $obj = $c->stash->{object};
+ my $obj_meth = $self->init_object;
+ my $form_meth = $self->init_form;
+ my $pk = $self->primary_key;
+
+ # id always comes from url but not necessarily from form
+ my $id = $c->req->params->{$pk} || $c->stash->{object_id};
+
+ # initialize the form with the object's values
+ $form->$form_meth( $obj->delegate );
+
+ # set param values from request
+ $form->params( $c->req->params );
+ $form->param( $pk => $id );
+
+ # override form's values with those from params
+ # no_clear is important because we already initialized with object
+ # and we do not want to undo those mods.
+ $form->init_fields( no_clear => 1 );
+
+ # return if there was a problem with any param values
+ unless ( $form->validate() ) {
+ $c->stash->{error} = $form->error; # NOT throw_error()
+ $c->stash->{template} ||= $self->default_template; # MUST specify
+ return 0;
+ }
+
+ # re-set object's values from the now-valid form
+ $form->$obj_meth( $obj->delegate );
+
+ # set id explicitly since there's some bug
+ # with param() setting it in save()
+ $obj->$pk($id);
+
+ # let serial column work its magic
+ $obj->$pk(undef)
+ if ( !$obj->$pk || $obj->$pk eq '0' || $id eq '0' );
+
+ #carp "object $pk == $id ? " . $obj->$pk;
+
+ return $obj;
+}
+
+=head2 do_search( I<context>, I<arg> )
+
+Makes form values sticky then calls the base do_search() method with NEXT.
+
+=cut
+
+sub do_search {
+ my ( $self, $c, @arg ) = @_;
+
+ # make form sticky
+ $c->stash->{form} ||= $self->form;
+
+ # if we have no input, just return for initial search
+ if ( !@arg && !$c->req->param && $c->action->name eq 'search' ) {
+ $c->log->debug("no input to search. return") if $c->debug;
+ return;
+ }
+
+ $c->stash->{form}->params( $c->req->params );
+ $c->stash->{form}->init_fields();
+
+ return $self->NEXT::do_search( $c, scalar $c->stash->{form}->field_names,
+ @arg );
+}
+
+1;
+
+__END__
+
+=head1 AUTHOR
+
+Peter Karman, C<< <karman at cpan dot org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-catalystx-crud-controller-rhtmlo at rt.cpan.org>,
+or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-Controller-RHTMLO>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc CatalystX::CRUD::Controller::RHTMLO
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/CatalystX-CRUD-Controller-RHTMLO>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/CatalystX-CRUD-Controller-RHTMLO>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Controller-RHTMLO>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/CatalystX-CRUD-Controller-RHTMLO>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2007 Peter Karman, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/00-load.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/00-load.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/00-load.t 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+ use_ok( 'CatalystX::CRUD::Controller::RHTMLO' );
+}
+
+diag( "Testing CatalystX::CRUD::Controller::RHTMLO $CatalystX::CRUD::Controller::RHTMLO::VERSION, Perl $], $^X" );
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/boilerplate.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/boilerplate.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/boilerplate.t 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,48 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+ my ($filename, %regex) = @_;
+ open my $fh, "<", $filename
+ or die "couldn't open $filename for reading: $!";
+
+ my %violated;
+
+ while (my $line = <$fh>) {
+ while (my ($desc, $regex) = each %regex) {
+ if ($line =~ $regex) {
+ push @{$violated{$desc}||=[]}, $.;
+ }
+ }
+ }
+
+ if (%violated) {
+ fail("$filename contains boilerplate text");
+ diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+ } else {
+ pass("$filename contains no boilerplate text");
+ }
+}
+
+not_in_file_ok(README =>
+ "The README is used..." => qr/The README is used/,
+ "'version information here'" => qr/to provide version information/,
+);
+
+not_in_file_ok(Changes =>
+ "placeholder date/time" => qr(Date/time)
+);
+
+sub module_boilerplate_ok {
+ my ($module) = @_;
+ not_in_file_ok($module =>
+ 'the great new $MODULENAME' => qr/ - The great new /,
+ 'boilerplate description' => qr/Quick summary of what the module/,
+ 'stub function definition' => qr/function[12]/,
+ );
+}
+
+module_boilerplate_ok('lib/CatalystX/CRUD/Controller/RHTMLO.pm');
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod-coverage.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod-coverage.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod-coverage.t 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,6 @@
+#!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 $@;
+all_pod_coverage_ok();
Added: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod.t (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/t/pod.t 2008-03-11 17:20:15 UTC (rev 7486)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
More information about the Catalyst-commits
mailing list