| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package CatalystX::CRUD::Test::Form; | 
| 2 | 4 |  |  | 4 |  | 4440 | use strict; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 125 |  | 
| 3 | 4 |  |  | 4 |  | 18 | use warnings; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 108 |  | 
| 4 | 4 |  |  | 4 |  | 23 | use Carp; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 223 |  | 
| 5 | 4 |  |  | 4 |  | 47 | use Data::Dump; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 215 |  | 
| 6 | 4 |  |  | 4 |  | 39 | use base qw( Class::Accessor::Fast ); | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 2679 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(qw( params fields )); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our $VERSION = '0.58'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 NAME | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | CatalystX::CRUD::Test::Form - mock form class for testing CatalystX::CRUD packages | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | package MyApp::Form::Foo; | 
| 19 |  |  |  |  |  |  | use strict; | 
| 20 |  |  |  |  |  |  | use base qw( CatalystX::CRUD::Test::Form ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub foo_from_form { | 
| 23 |  |  |  |  |  |  | my $self = shift; | 
| 24 |  |  |  |  |  |  | return $self->SUPER::object_from_form(@_); | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub init_with_foo { | 
| 28 |  |  |  |  |  |  | my $self = shift; | 
| 29 |  |  |  |  |  |  | return $self->SUPER::init_with_object(@_); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | 1; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | CatalystX::CRUD::Test::Form is a mock form class for testing CatalystX::CRUD | 
| 38 |  |  |  |  |  |  | packages. The API is similar to Rose::HTML::Form, but implements very naive | 
| 39 |  |  |  |  |  |  | methods only. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =head1 METHODS | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =head2 new( I<args> ) | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | Returns new object instance. I<args> must be a hashref and | 
| 47 |  |  |  |  |  |  | must contain at least a key/value pair for B<fields>. | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =cut | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub new { | 
| 52 | 55 |  |  | 55 | 1 | 114 | my $class = shift; | 
| 53 | 55 |  |  |  |  | 253 | my $self  = $class->SUPER::new(@_); | 
| 54 | 55 | 50 | 33 |  |  | 1624 | croak "fields() required to be an ARRAY ref" | 
| 55 |  |  |  |  |  |  | unless $self->fields and ref( $self->fields ) eq 'ARRAY'; | 
| 56 | 55 | 50 |  |  |  | 2631 | $self->params( { map { $_ => undef } @{ $self->fields } } ) | 
|  | 110 |  |  |  |  | 1435 |  | 
|  | 55 |  |  |  |  | 1166 |  | 
| 57 |  |  |  |  |  |  | unless $self->params; | 
| 58 | 55 |  |  |  |  | 452 | return $self; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | *field_names = \&fields; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head2 fields( [ I<arrayref> ] ) | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | Get/set the arrayref of field names. | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | This must be set in new(). | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head2 field_names | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | An alias for fields(). | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head2 params( [ I<hashref> ] ) | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Get/set the hashref of key/value pairs for the form object. The keys should | 
| 76 |  |  |  |  |  |  | be the names of form fields and should match the value of fields(). | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head2 param( I<key> => I<val> ) | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | Sets the key/value pair for a field. I<key> should be the name of a field, | 
| 81 |  |  |  |  |  |  | as indicated by params(). | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =cut | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub param { | 
| 86 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 87 | 0 |  |  |  |  | 0 | my $key  = shift; | 
| 88 | 0 | 0 |  |  |  | 0 | croak "key required" if !defined $key; | 
| 89 | 0 |  |  |  |  | 0 | my $val = shift; | 
| 90 | 0 |  |  |  |  | 0 | $self->params->{$key} = $val; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =head2 init_fields | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | Placeholder only. Does nothing. | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =cut | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | sub init_fields { | 
| 100 | 9 |  |  | 9 | 1 | 22 | my $self = shift; | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | # nothing to do | 
| 103 |  |  |  |  |  |  | #$self->dump; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head2 clear | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | Resets params() to an empty hashref. | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =cut | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | sub clear { | 
| 113 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 114 | 0 |  |  |  |  | 0 | $self->params( {} ); | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head2 validate | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | Does nothing. Always returns true. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =cut | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | sub validate { | 
| 124 | 9 |  |  | 9 | 1 | 19 | my $self = shift; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | # nothing to do in this poor man's form. | 
| 127 |  |  |  |  |  |  | #$self->dump; | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 9 |  |  |  |  | 26 | 1; | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head2 init_with_object( I<object> ) | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | You should override this method in your subclass. Basically sets all | 
| 135 |  |  |  |  |  |  | accessors in form equal to the equivalent value in I<object>. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | Returns the Form object. | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =cut | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | sub init_with_object { | 
| 142 | 21 |  |  | 21 | 1 | 1677 | my ( $self, $object ) = @_; | 
| 143 | 21 |  |  |  |  | 34 | for my $f ( keys %{ $self->params } ) { | 
|  | 21 |  |  |  |  | 456 |  | 
| 144 | 42 | 50 |  |  |  | 3279 | if ( $object->can($f) ) { | 
| 145 | 42 |  |  |  |  | 137 | $self->params->{$f} = $object->$f; | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  | } | 
| 148 | 21 |  |  |  |  | 2972 | return $self; | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head2 object_from_form( I<object> ) | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | You should override this method in your subclass. Basically sets all | 
| 154 |  |  |  |  |  |  | accessors in I<object> equal to the equivalent value in form. | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =cut | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | sub object_from_form { | 
| 159 | 9 |  |  | 9 | 1 | 63 | my ( $self, $object ) = @_; | 
| 160 | 9 |  |  |  |  | 11 | for my $f ( keys %{ $self->params } ) { | 
|  | 9 |  |  |  |  | 165 |  | 
| 161 | 9 | 50 |  |  |  | 98 | if ( $object->can($f) ) { | 
| 162 | 9 |  |  |  |  | 195 | $object->$f( $self->params->{$f} ); | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  | } | 
| 165 | 9 |  |  |  |  | 3166 | return $object; | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =head2 dump | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | Wrapper around Data::Dump::dump. Returns the form object serialized. | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =cut | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | sub dump { | 
| 175 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 176 | 0 |  |  |  |  |  | Data::Dump::dump($self); | 
| 177 |  |  |  |  |  |  | } | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | 1; | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | __END__ | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =head1 AUTHOR | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Peter Karman, C<< <perl at peknet.com> >> | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =head1 BUGS | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 190 |  |  |  |  |  |  | C<bug-catalystx-crud at rt.cpan.org>, or through the web interface at | 
| 191 |  |  |  |  |  |  | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD>. | 
| 192 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 193 |  |  |  |  |  |  | your bug as I make changes. | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 SUPPORT | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | perldoc CatalystX::CRUD | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | You can also look for information at: | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =over 4 | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | L<http://annocpan.org/dist/CatalystX-CRUD> | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | L<http://cpanratings.perl.org/d/CatalystX-CRUD> | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD> | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | =item * Search CPAN | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | L<http://search.cpan.org/dist/CatalystX-CRUD> | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | =back | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | Copyright 2008 Peter Karman, all rights reserved. | 
| 228 |  |  |  |  |  |  |  | 
| 229 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 230 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | =cut |