Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

has_field working

  • Loading branch information...
commit 7cd4631e5831ac8d19df66fabc0cdfcd53318d77 1 parent 36bcaaa
gerda.shank@gmail.com authored
View
10 lib/HTML/FormHandler.pm
@@ -1,6 +1,6 @@
package HTML::FormHandler;
-use Moose;
+use HTML::FormHandler::Moose;
use MooseX::AttributeHelpers;
extends 'HTML::FormHandler::Model';
@@ -10,7 +10,7 @@ use Locale::Maketext;
use HTML::FormHandler::I18N; # base class for language files
use 5.008;
-our $VERSION = '0.08';
+our $VERSION = '0.09';
=head1 NAME
@@ -670,9 +670,11 @@ field objects. It calls the make_field() method for each field.
sub build_form
{
my $self = shift;
+$DB::single=1;
+ my $field_list = $self->meta->field_list;
+ $self->_build_fields( $field_list, 0 ) if $field_list;
my $profile = $self->profile;
-
for my $group ( 'required', 'optional', 'fields' )
{
my $required = $group eq 'required' ? 1 : 0;
@@ -1265,5 +1267,5 @@ the same terms as Perl itself.
=cut
-no Moose;
+no HTML::FormHandler::Moose;
1;
View
9 lib/HTML/FormHandler/Meta/Class.pm
@@ -0,0 +1,9 @@
+package # hide from Pause
+ HTML::FormHandler::Meta::Class;
+use Moose;
+extends 'Moose::Meta::Class';
+
+has 'field_list' => ( is => 'rw' );
+
+no Moose;
+1;
View
28 lib/HTML/FormHandler/Moose.pm
@@ -0,0 +1,28 @@
+package # hide from Pause
+ HTML::FormHandler::Moose;
+
+use Moose;
+use HTML::FormHandler::Meta::Class;
+
+Moose::Exporter->setup_import_methods(
+ with_caller => [ 'has_field' ],
+ also => 'Moose',
+);
+
+sub init_meta {
+ shift;
+ Moose->init_meta( @_, metaclass => 'HTML::FormHandler::Meta::Class' );
+}
+
+sub has_field
+{
+ my ( $caller, $name, %options ) = @_;
+
+ my $obj = Class::MOP::Class->initialize( $caller );
+ my $list = $caller->meta->field_list || [];
+ push @{$list}, ($name => \%options);
+ $caller->meta->field_list($list);
+ $list = $caller->meta->field_list;
+}
+
+1;
View
BIN  t/db/book.db
Binary file not shown
View
22 t/lib/Form/Test.pm
@@ -0,0 +1,22 @@
+package Form::Test;
+
+use HTML::FormHandler::Moose;
+extends 'HTML::FormHandler';
+
+has_field 'reqname' => ( type => 'Text', required => 1 );
+has_field 'optname' => ( type => 'Text' );
+has_field 'fruit' => ( type => 'Select' );
+
+has 'name' => ( isa => 'Str', is => 'rw', default => 'TestForm');
+
+sub options_fruit {
+ return (
+ 1 => 'apples',
+ 2 => 'oranges',
+ 3 => 'kiwi',
+ );
+}
+
+no HTML::FormHandler::Moose;
+1;
+
View
2  t/process.t
@@ -6,7 +6,7 @@ use lib 't/lib';
BEGIN {
eval "use DBIx::Class";
plan skip_all => 'DBIX::Class required' if $@;
- plan tests => 20;
+ plan tests => 19;
}
use_ok( 'HTML::FormHandler' );
Please sign in to comment.
Something went wrong with that request. Please try again.