| 1 | package Catalyst::Plugin::FormValidator; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use MRO::Compat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Data::FormValidator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.094'; | |||||||||
| 8 | 2 | $VERSION = eval $VERSION; | |||||||||
| 9 | |||||||||||
| 10 | =head2 prepare | ||||||||||
| 11 | |||||||||||
| 12 | Override Catalyst's prepare | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub prepare { | ||||||||
|
Subroutine
prepare: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 17 | 3 | my $c = shift; | |||||||||
| 18 | 3 | $c = $c->maybe::next::method(@_); | |||||||||
| 19 | 3 | $c->{form} = Data::FormValidator->check( $c->request->parameters, {} ); | |||||||||
| 20 | 3 | return $c; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | =head2 form | ||||||||||
| 25 | |||||||||||
| 26 | $c->form object | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | 6 | ▶ | sub form { | ||||||||
|
Subroutine
form: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 31 | 6 | my $c = shift; | |||||||||
| 32 | 6 | ▶ | if ( $_[0] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 3 | ▶ | my $form = $_[1] ? {@_} : $_[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | $c->{form} = | ||||||||||
| 35 | 3 | Data::FormValidator->check( $c->request->parameters, $form ); | |||||||||
| 36 | } | ||||||||||
| 37 | 6 | return $c->{form}; | |||||||||
| 38 | } | ||||||||||
| 39 | =head1 NAME | ||||||||||
| 40 | |||||||||||
| 41 | Catalyst::Plugin::FormValidator - Data::FormValidator | ||||||||||
| 42 | plugin for Catalyst. | ||||||||||
| 43 | |||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||
| 45 | |||||||||||
| 46 | use Catalyst 'FormValidator'; | ||||||||||
| 47 | |||||||||||
| 48 | $c->form( optional => ['rest'] ); | ||||||||||
| 49 | print $c->form->valid('rest'); | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | Note that not only is this plugin disrecommended (as it takes over the global | ||||||||||
| 53 | C<< $c->form >> method, rather than being applyable in only part of your | ||||||||||
| 54 | application), but L<Data::FormValidator> itself is not recommended for use. | ||||||||||
| 55 | |||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||
| 57 | |||||||||||
| 58 | This plugin uses L<Data::FormValidator> to validate and set up form data | ||||||||||
| 59 | from your request parameters. It's a quite thin wrapper around that | ||||||||||
| 60 | module, so most of the relevant information can be found there. | ||||||||||
| 61 | |||||||||||
| 62 | =head2 EXTENDED METHODS | ||||||||||
| 63 | |||||||||||
| 64 | =head2 METHODS | ||||||||||
| 65 | |||||||||||
| 66 | =head3 form | ||||||||||
| 67 | |||||||||||
| 68 | Merge values with FormValidator. | ||||||||||
| 69 | |||||||||||
| 70 | $c->form( required => ['yada'] ); | ||||||||||
| 71 | |||||||||||
| 72 | Returns a L<Data::FormValidator::Results> object. | ||||||||||
| 73 | |||||||||||
| 74 | $c->form->valid('rest'); | ||||||||||
| 75 | |||||||||||
| 76 | The actual parameters sent to $c->form are the same as the profile in | ||||||||||
| 77 | L<Data::FormValidator>'s check function. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | =head1 SEE ALSO | ||||||||||
| 82 | |||||||||||
| 83 | L<Catalyst>, L<Data::FormValidator> | ||||||||||
| 84 | |||||||||||
| 85 | =head1 AUTHOR | ||||||||||
| 86 | |||||||||||
| 87 | Sebastian Riedel, C<sri@cpan.org> | ||||||||||
| 88 | |||||||||||
| 89 | =head1 CONTRIBUTORS | ||||||||||
| 90 | |||||||||||
| 91 | Devin Austin C<(dhoss@cpan.org)> | ||||||||||
| 92 | |||||||||||
| 93 | =head1 COPYRIGHT | ||||||||||
| 94 | |||||||||||
| 95 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 96 | the same terms as Perl itself. | ||||||||||
| 97 | |||||||||||
| 98 | =cut | ||||||||||
| 99 | |||||||||||
| 100 | 2 | 1; | |||||||||