File Coverage

blib/lib/Catalyst/Plugin/FormValidator.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::FormValidator;
2              
3 2     2   1303277 use strict;
  2         3  
  2         53  
4 2     2   385 use MRO::Compat;
  2         2095  
  2         40  
5 2     2   988 use Data::FormValidator;
  2         27794  
  2         333  
6              
7             our $VERSION = '0.093_1';
8             $VERSION = eval $VERSION;
9              
10             =head2 prepare
11              
12             Override Catalyst's prepare
13              
14             =cut
15              
16             sub prepare {
17 3     3 1 23593 my $c = shift;
18 3         25 $c = $c->maybe::next::method(@_);
19 3         23455 $c->{form} = Data::FormValidator->check( $c->request->parameters, {} );
20 3         984 return $c;
21             }
22              
23              
24             =head2 form
25              
26             $c->form object
27              
28             =cut
29              
30             sub form {
31 6     6 1 8166 my $c = shift;
32 6 100       20 if ( $_[0] ) {
33 3 50       14 my $form = $_[1] ? {@_} : $_[0];
34             $c->{form} =
35 3         57 Data::FormValidator->check( $c->request->parameters, $form );
36             }
37 6         881 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             1;