| 1 | package Catalyst::Controller::Validation::DFV; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | our $VERSION = '0.0.11'; | |||||||||||
| 4 | 2 | $VERSION = eval $VERSION; | |||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use base 'Catalyst::Controller'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use Data::FormValidator '4.50'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 2 | ▶ | use Data::FormValidator::Constraints qw(:closures); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 0 | ▶ | sub form_check :Private { | ||||||||||
|
Subroutine
form_check: not called CC=1 SCAR=6.9
| |||||||||||||
| 16 | 0 | my ($self, $c, $dfv_profile) = @_; | |||||||||||
| 17 | |||||||||||||
| 18 | 0 | my $results = Data::FormValidator->check( | |||||||||||
| 19 | $c->request->body_parameters, | ||||||||||||
| 20 | $dfv_profile | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | # return our findings ... | ||||||||||||
| 24 | 0 | $c->stash->{validation} = $results; | |||||||||||
| 25 | |||||||||||||
| 26 | 0 | return; | |||||||||||
| 27 | 2 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | =head1 Methods | ||||||||||||
| 31 | |||||||||||||
| 32 | =cut | ||||||||||||
| 33 | |||||||||||||
| 34 | =head2 add_form_invalid | ||||||||||||
| 35 | |||||||||||||
| 36 | =cut | ||||||||||||
| 37 | 0 | ▶ | sub add_form_invalid :Private { | ||||||||||
|
Subroutine
add_form_invalid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 38 | 0 | my ($self, $c, $invalid_key, $invalid_value) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | # if we haven't checked hte form yet, we can't add to the results | ||||||||||||
| 41 | 0 | ▶ | if (not defined $c->stash->{validation}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 0 | carp('form must be validated first'); | |||||||||||
| 43 | 0 | return; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | # the invalids are a keyed list of constraint names | ||||||||||||
| 47 | push | ||||||||||||
| 48 | 0 | @{ $c->stash->{validation}{invalid}{$invalid_key} }, | |||||||||||
| 49 | $invalid_value | ||||||||||||
| 50 | ; | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | return; | |||||||||||
| 53 | 2 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | |||||||||||||
| 55 | =head2 validation_errors_to_html | ||||||||||||
| 56 | |||||||||||||
| 57 | =cut | ||||||||||||
| 58 | 0 | ▶ | sub validation_errors_to_html :Private { | ||||||||||
|
Subroutine
validation_errors_to_html: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 59 | 0 | my ($self, $c) = @_; | |||||||||||
| 60 | 2 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 61 | |||||||||||||
| 62 | =head2 refill_form | ||||||||||||
| 63 | |||||||||||||
| 64 | =cut | ||||||||||||
| 65 | # factored out of a block of code I regularly paste into Controller/Root.pm | ||||||||||||
| 66 | 4 | ▶ | sub refill_form :Private { | ||||||||||
|
Subroutine
refill_form: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||
| 67 | 4 | my ($self, $c) = @_; | |||||||||||
| 68 | |||||||||||||
| 69 | 4 | ▶ | if (not $c->can('fillform')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | # put a warning in the logs | ||||||||||||
| 71 | 0 | $c->log->warn( | |||||||||||
| 72 | q{The context object doesn't have a fillform() method. Add 'FillInForm' to your plug-in list.} | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | |||||||||||||
| 75 | 0 | return; # no point in continuing | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | # use Catalyst::Plugin::FillInForm to refill form data | ||||||||||||
| 79 | # in order of priority we have: | ||||||||||||
| 80 | # - stash->{formdata} | ||||||||||||
| 81 | # - ->parameters() | ||||||||||||
| 82 | # - <input value="..."> | ||||||||||||
| 83 | $c->fillform( | ||||||||||||
| 84 | { | ||||||||||||
| 85 | # combine two hashrefs so we only make one method call | ||||||||||||
| 86 | 4 | ▶ | %{ $c->request->parameters || {} }, | ||||||||||
|
Condition50%1/2
$c->request->parameters || {}
MC/DC0%0/1
$c->request->parameters || {}
$c->request->parameters
Truth table50%1/2
A
A= $c->request->parameters
| |||||||||||||
| 87 | 4 | ▶ | %{ $c->stash->{formdata} || {} }, | ||||||||||
|
Condition50%1/2
$c->stash->{'formdata'} || {}
MC/DC0%0/1
$c->stash->{'formdata'} || {}
$c->stash->{'formdata'}
Truth table50%1/2
A
A= $c->stash->{'formdata'}
| |||||||||||||
| 88 | } | ||||||||||||
| 89 | ); | ||||||||||||
| 90 | |||||||||||||
| 91 | 4 | return; | |||||||||||
| 92 | 2 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 93 | |||||||||||||
| 94 | 2 | 1; | |||||||||||
| 95 | # ABSTRACT: Form validation and refilling | ||||||||||||
| 96 | __END__ | ||||||||||||