Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'SFBF'

Conflicts:
	Build.PL
	Changes
	MANIFEST
	MANIFEST.SKIP
	README
	t/00-load.t
  • Loading branch information...
commit 7e14113ba1b7a2e1fe6d7995369d1ab18419e40c 2 parents 6bf6418 + dc192b8
Kent Fredric kentfredric authored
Showing with 1,122 additions and 2 deletions.
  1. +2 −0  Build.PL
  2. +3 −0  Changes
  3. +30 −0 MANIFEST
  4. +1 −0  MANIFEST.SKIP
  5. +2 −0  TODO
  6. +64 −0 lib/SparkX/Form/BasicFields.pm
  7. +65 −0 lib/SparkX/Form/Field/Button.pm
  8. +62 −0 lib/SparkX/Form/Field/Checkbox.pm
  9. +57 −0 lib/SparkX/Form/Field/File.pm
  10. +57 −0 lib/SparkX/Form/Field/Hidden.pm
  11. +69 −0 lib/SparkX/Form/Field/Image.pm
  12. +81 −0 lib/SparkX/Form/Field/MultiSelect.pm
  13. +57 −0 lib/SparkX/Form/Field/Password.pm
  14. +74 −0 lib/SparkX/Form/Field/Radio.pm
  15. +57 −0 lib/SparkX/Form/Field/Reset.pm
  16. +71 −0 lib/SparkX/Form/Field/Select.pm
  17. +57 −0 lib/SparkX/Form/Field/Submit.pm
  18. +57 −0 lib/SparkX/Form/Field/Text.pm
  19. +58 −0 lib/SparkX/Form/Field/Textarea.pm
  20. +11 −2 t/00-load.t
  21. +18 −0 t/01-pod-coverage.t
  22. +15 −0 t/02-button.t
  23. +12 −0 t/03-checkbox.t
  24. +11 −0 t/04-file.t
  25. +11 −0 t/05-hidden.t
  26. +11 −0 t/06-image.t
  27. +15 −0 t/07-multiselect.t
  28. +11 −0 t/08-password.t
  29. +14 −0 t/09-radio.t
  30. +11 −0 t/10-reset.t
  31. +15 −0 t/11-select.t
  32. +11 −0 t/12-submit.t
  33. +11 −0 t/13-text.t
  34. +11 −0 t/14-textarea.t
  35. +10 −0 t/lib/Mockform.pm
2  Build.PL
View
@@ -9,6 +9,7 @@ my $builder = Module::Build->new(
dist_version_from => 'lib/Spark/Form.pm',
build_requires => {
'Test::More' => 0,
+ 'Test::MockObject' => 0,
'Test::MockObject::Extends' => 0,
},
requires => {
@@ -17,6 +18,7 @@ my $builder = Module::Build->new(
'HTML::Tiny' => 0,
'MooseX::AttributeHelpers' => 0,
'List::MoreUtils' => 0,
+ 'List::Util' => 0,
},
add_to_cleanup => [ 'Spark-*' ],
create_makefile_pl => 'traditional',
3  Changes
View
@@ -6,3 +6,6 @@ Revision history for Spark-Form
0.2 2009-07-21
Added testing deps.
Auto-requires printer modules for you (and fixes related bug)
+
+0.3
+ Merged in SparkX::Form::BasicFields
30 MANIFEST
View
@@ -11,20 +11,50 @@ lib/Spark/Form/Printer.pm
lib/Spark/Form/Printer/HTML.pm
lib/Spark/Form/Printer/XHTML.pm
lib/Spark/Form/Source.pm
+lib/SparkX/Form/BasicFields.pm
+lib/SparkX/Form/Field/Button.pm
+lib/SparkX/Form/Field/Checkbox.pm
+lib/SparkX/Form/Field/File.pm
+lib/SparkX/Form/Field/Hidden.pm
+lib/SparkX/Form/Field/Image.pm
+lib/SparkX/Form/Field/MultiSelect.pm
+lib/SparkX/Form/Field/Password.pm
+lib/SparkX/Form/Field/Radio.pm
+lib/SparkX/Form/Field/Reset.pm
+lib/SparkX/Form/Field/Select.pm
+lib/SparkX/Form/Field/Submit.pm
+lib/SparkX/Form/Field/Text.pm
+lib/SparkX/Form/Field/Textarea.pm
MANIFEST This list of files
README
t/00-load.t
t/01-form-basic.t
+t/01-pod-coverage.t
t/02-form-register.t
+t/02-button.t
t/03-form-custom.t
+t/03-checkbox.t
t/04-form-custom-lazy.t
+t/04-file.t
t/05-printer.t
+t/05-hidden.t
+t/06-image.t
+t/07-multiselect.t
+t/08-password.t
+t/09-radio.t
+t/10-reset.t
+t/11-select.t
+t/12-submit.t
+t/13-text.t
+t/14-textarea.t
t/lib/TestApp/Form/Custom.pm
t/lib/TestApp/Form/Field/Custom.pm
t/lib/TestApp/Form/Field/Email.pm
t/lib/TestApp/Form/Field/Password.pm
t/lib/TestApp/Form/Printer/Join.pm
+t/lib/Mockform.pm
t/pod-coverage.t
t/pod.t
Makefile.PL
META.yml
+TODO
1  MANIFEST.SKIP
View
@@ -5,3 +5,4 @@
\.bak$
^MANIFEST\.SKIP$
^.git
+.gz$
2  TODO
View
@@ -0,0 +1,2 @@
+3. ::Reset ought not to have a value
+4. Debatable whether ::{File,Image} ought to have a value (not echoed, not validated but read)
64 lib/SparkX/Form/BasicFields.pm
View
@@ -0,0 +1,64 @@
+package SparkX::Form::BasicFields;
+
+our $VERSION = '0.2';
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::BasicFields - A collection of basic fields for Spark::Form
+
+L<Spark::Form> is a way to define your own forms with validation and auto-printing. See that module for more information.
+
+This file is just explanatory. SEE ALSO for more interesting files.
+
+=head1 VERSION
+
+Version 0.2
+
+=head1 SEE ALSO
+
+L<Spark::Form> - The forms handling system itself
+L<SparkX::BasicValidators> - If you want to have validation of these fields
+L<SparkX::Form::Field::Text> - A text field
+L<SparkX::Form::Field::Checkbox> - A checkbox field
+L<SparkX::Form::Field::Radio> - A radio button set
+L<SparkX::Form::Field::Select> - A select button set
+L<SparkX::Form::Field::TextArea> - A textarea field
+
+=head1 AUTHOR
+
+James Laver, C<< <printf(qw[%s@%s.%s cpan jameslaver com])> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-sparkx-form-basicfields at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SparkX-Form-BasicFields>. I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SparkX-Form-BasicFields>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/SparkX-Form-BasicFields>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 James Laver, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+
+=cut
65 lib/SparkX/Form/Field/Button.pm
View
@@ -0,0 +1,65 @@
+package SparkX::Form::Field::Button;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+has 'content' => (
+ isa => 'Str',
+ is => 'rw',
+ required => 0,
+ default => '',
+);
+
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->button({value => $self->value, name => $self->name},$self->content);
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Button - A Button for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
62 lib/SparkX/Form/Field/Checkbox.pm
View
@@ -0,0 +1,62 @@
+package SparkX::Form::Field::Checkbox;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({
+ type => 'checkbox',
+ value => 1,
+ ($self->value ? (checked => 'checked') : ()),
+ name => $self->name
+ });
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Checkbox - A Checkbox field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/File.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::File;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'file', name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::File - A File upload field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/Hidden.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::Hidden;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'hidden', value => $self->value, name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Hidden - A hidden field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
69 lib/SparkX/Form/Field/Image.pm
View
@@ -0,0 +1,69 @@
+package SparkX::Form::Field::Image;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+has 'names' => (
+ lazy => 1,
+ (Moose->VERSION >= 0.84 ) ? (is => 'bare') : (),
+ default => sub {
+ my $self = shift;
+
+ [$self->name . ".x", $self->name . ".y"]
+ },
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html' ) );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'image', name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Image - An image field for SparkX::Form
+
+Note that this does not support server-side image map functionality but will be treated as a submit. Patches welcome that don't break this (99% of the time desired) behaviour.
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
81 lib/SparkX/Form/Field/MultiSelect.pm
View
@@ -0,0 +1,81 @@
+package SparkX::Form::Field::MultiSelect;
+
+use Moose;
+use HTML::Tiny;
+use List::Util 'first';
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'ArrayRef[Str]',
+);
+
+has options => (
+ isa => 'ArrayRef',
+ is => 'rw',
+ required => 0,
+ lazy => 1,
+ default => sub { shift->value },
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _is_selected {
+ my ($self,$value) = @_;
+
+ first {$value eq $_} @{$self->value};
+}
+
+sub _render {
+ my ($self,$html) = @_;
+ $html->select({name => $self->name, multiple=>'multiple'},
+ join(' ',
+ map {
+ my $__ = $_;
+ $html->option({
+ value => $_,
+ ($self->_is_selected($_) ? (selected => 'selected') : ()),
+ })
+ } @{$self->options}
+ )
+ );
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::MultiSelect - A multiple select dropdown field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/Password.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::Password;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'password', name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Password - A Password field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
74 lib/SparkX/Form/Field/Radio.pm
View
@@ -0,0 +1,74 @@
+package SparkX::Form::Field::Radio;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+has options => (
+ isa => 'ArrayRef',
+ is => 'rw',
+ required => 0,
+ lazy => 1,
+ default => sub { shift->value },
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+ join(
+ " ",
+ map {
+ $html->input({
+ type => 'radio',
+ value => $_,
+ ($self->value eq $_ ? (checked => 'checked') : ()),
+ name => $self->name,
+ })
+ } @{$self->options}
+ );
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Radio - A set of radio buttons for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field(s) to html
+
+=head2 to_xhtml() => Str
+
+Renders the field(s) to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/Reset.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::Reset;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'reset', name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Reset - A reset button for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
71 lib/SparkX/Form/Field/Select.pm
View
@@ -0,0 +1,71 @@
+package SparkX::Form::Field::Select;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+has options => (
+ isa => 'ArrayRef',
+ is => 'rw',
+ required => 0,
+ lazy => 1,
+ default => sub { shift->value },
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+ $html->select({name => $self->name},
+ join(' ',map {
+ $html->option({
+ value => $_,
+ (($self->value eq $_) ? (selected => 'selected') : ()),
+ }, $_);
+ } @{$self->options}),
+ );
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Select - A select dropdown field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/Submit.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::Submit;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'submit', value => $self->value, name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Submit - A Submit field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
57 lib/SparkX/Form/Field/Text.pm
View
@@ -0,0 +1,57 @@
+package SparkX::Form::Field::Text;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->input({type => 'text', value => $self->value, name => $self->name});
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Text - A Text field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
58 lib/SparkX/Form/Field/Textarea.pm
View
@@ -0,0 +1,58 @@
+package SparkX::Form::Field::Textarea;
+
+use Moose;
+use HTML::Tiny;
+
+extends 'Spark::Form::Field';
+with 'Spark::Form::Field::Role::Printable::HTML',
+ 'Spark::Form::Field::Role::Printable::XHTML',
+ 'Spark::Form::Field::Role::Validateable';
+
+has '+value' => (
+ isa => 'Str',
+ default => '',
+);
+
+sub to_html {
+ shift->_render( HTML::Tiny->new( mode => 'html') );
+}
+
+sub to_xhtml {
+ shift->_render( HTML::Tiny->new( mode => 'xml') );
+}
+
+sub _render {
+ my ($self,$html) = @_;
+
+ $html->textarea({name => $self->name},$self->value);
+}
+
+sub validate { 1 }
+
+1;
+__END__
+
+=head1 NAME
+
+SparkX::Form::Field::Textarea - A Textarea field for SparkX::Form
+
+=head1 METHODS
+
+=head2 to_html() => Str
+
+Renders the field to html
+
+=head2 to_xhtml() => Str
+
+Renders the field to xhtml
+
+=head2 validate() => Bool
+
+Validates the field. Before composition with validators, always returns 1.
+
+=head1 SEE ALSO
+
+L<SparkX::Form> - The forms module this is to be used with
+L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
+
+=cut
13 t/00-load.t
View
@@ -1,13 +1,22 @@
#!perl -T
-use Test::More tests => 2;
+use Test::More;
+
+my @fields = qw(
+ Button Checkbox File Hidden Image
+ MultiSelect Password Radio Reset
+ Select Submit Text Textarea
+);
BEGIN {
-
+ plan tests => ( 3 + scalar @fields );
+
use_ok($_) foreach (qw[
Spark::Form
Spark::Form::Field
]);
+ use_ok( "SparkX::Form::Field::$_" ) foreach @fields;
+ use_ok( 'SparkX::Form::BasicFields' );
}
diag( "Testing Spark::Form $Spark::Form::VERSION, Perl $], $^X" );
18 t/01-pod-coverage.t
View
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod::Coverage
+my $min_tpc = 1.08;
+eval "use Test::Pod::Coverage $min_tpc";
+plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
+ if $@;
+
+# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
+# but older versions don't recognize some common documentation styles
+my $min_pc = 0.18;
+eval "use Pod::Coverage $min_pc";
+plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
+ if $@;
+
+all_pod_coverage_ok();
15 t/02-button.t
View
@@ -0,0 +1,15 @@
+#!perl -T
+
+use Test::More tests => 2;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Button;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Button->new(name => 'test', form => $form);
+my $b2 = SparkX::Form::Field::Button->new(
+ name => 'test', form => $form,
+ content=>'<img src="foo" />'
+);
+is($b->to_xhtml,'<button name="test"></button>','Test xhtml representation');
+is($b2->to_xhtml,'<button name="test"><img src="foo" /></button>','Test xhtml representation');
12 t/03-checkbox.t
View
@@ -0,0 +1,12 @@
+#!perl -T
+
+use Test::More tests => 2;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Checkbox;
+
+my $form = Mockform->new;
+my $c = SparkX::Form::Field::Checkbox->new(name => 'test', form => $form);
+my $c2 = SparkX::Form::Field::Checkbox->new(name => 'test', form => $form, value => 1);
+is($c->to_xhtml,'<input name="test" type="checkbox" value="1" />','Test xhtml representation');
+is($c2->to_xhtml,'<input checked="checked" name="test" type="checkbox" value="1" />','Test xhtml representation');
11 t/04-file.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::File;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::File->new(name => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="file" />','Test xhtml representation');
11 t/05-hidden.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Hidden;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Hidden->new(name => 'test', value => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="hidden" value="test" />','Test xhtml representation');
11 t/06-image.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Image;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Image->new(name => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="image" />','Test xhtml representation');
15 t/07-multiselect.t
View
@@ -0,0 +1,15 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::MultiSelect;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::MultiSelect->new(
+ name => 'test', form => $form,
+ value => ['1','3'],
+ options => ['1','2','3','4'],
+);
+
+is($b->to_xhtml,'<select multiple="multiple" name="test"><option selected="selected" value="1"></option> <option value="2"></option> <option selected="selected" value="3"></option> <option value="4"></option></select>','Test xhtml representation');
11 t/08-password.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Password;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Password->new(name => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="password" />','Test xhtml representation');
14 t/09-radio.t
View
@@ -0,0 +1,14 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Radio;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Radio->new(
+ name => 'test', form => $form,
+ value => 'test-2', options => ['test-1','test-2','test-3'],
+);
+
+is($b->to_xhtml,'<input name="test" type="radio" value="test-1" /> <input checked="checked" name="test" type="radio" value="test-2" /> <input name="test" type="radio" value="test-3" />','Test xhtml representation');
11 t/10-reset.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Reset;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Reset->new(name => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="reset" />','Test xhtml representation');
15 t/11-select.t
View
@@ -0,0 +1,15 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Select;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Select->new(
+ name => 'test', form => $form,
+ options => ['test-1','test-2','test-3'],
+ value => 'test-2',
+);
+
+is($b->to_xhtml,'<select name="test"><option value="test-1">test-1</option> <option selected="selected" value="test-2">test-2</option> <option value="test-3">test-3</option></select>','Test xhtml representation');
11 t/12-submit.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Submit;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Submit->new(name => 'test', value => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="submit" value="test" />','Test xhtml representation');
11 t/13-text.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Text;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Text->new(name => 'test', value => 'test', form => $form);
+
+is($b->to_xhtml,'<input name="test" type="text" value="test" />','Test xhtml representation');
11 t/14-textarea.t
View
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 1;
+use lib 't/lib';
+use Mockform;
+use SparkX::Form::Field::Textarea;
+
+my $form = Mockform->new;
+my $b = SparkX::Form::Field::Textarea->new(name => 'test', form => $form, value=>'test');
+
+is($b->to_xhtml,'<textarea name="test">test</textarea>','Test xhtml representation');
10 t/lib/Mockform.pm
View
@@ -0,0 +1,10 @@
+package Mockform;
+
+use Test::MockObject::Extends;
+
+our @ISA = ('Test::MockObject');
+
+sub new {
+ my ($package, %opts) = @_;
+ my $mock = Test::MockObject::Extends->new('Spark::Form');
+}
Please sign in to comment.
Something went wrong with that request. Please try again.