| 1 | package Mojolicious::Plugin::FormValidator; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use Data::FormValidator; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | our $VERSION = '0.01'; | |||||||||||
| 8 | |||||||||||||
| 9 | 1 | our $results; | |||||||||||
| 10 | |||||||||||||
| 11 | 0 | ▶ | sub dfv_verify { | ||||||||||
|
Subroutine
dfv_verify: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 12 | 0 | my ($route, $c, $captures, $profile) = @_; | |||||||||||
| 13 | 0 | ▶ | return undef unless $profile; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | |||||||||||||
| 15 | 0 | my $input_hash = $c->req->params->to_hash; | |||||||||||
| 16 | 0 | _dfv_verify($c, $input_hash, $profile); | |||||||||||
| 17 | |||||||||||||
| 18 | 0 | return 1; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | sub register { | ||||||||||
|
Subroutine
register: called CC=1 SCAR=4.6
Pod
documented
| |||||||||||||
| 22 | 1 | my ($self, $app) = @_; | |||||||||||
| 23 | |||||||||||||
| 24 | 0 | ▶ | $app->helper(_dfv_error => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||
| 26 | 0 | my $field = shift; | |||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | return 0 if !defined $results; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | ▶ | return 0 if $results->valid($field); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | ▶ | return 1 if $results->invalid($field); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | ▶ | return 1 if $results->missing($field); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | |||||||||||||
| 33 | 0 | return 0; | |||||||||||
| 34 | 1 | }); | |||||||||||
| 35 | |||||||||||||
| 36 | 1 | return $app->routes->add_condition(dfv_verify => \&dfv_verify); | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | sub _dfv_verify { | ||||||||||
|
Subroutine
_dfv_verify: not called CC=4 SCAR=30.0
| |||||||||||||
| 40 | 0 | my $c = shift; | |||||||||||
| 41 | 0 | my $input_hash = shift; | |||||||||||
| 42 | 0 | my $dfv_profile = shift; | |||||||||||
| 43 | |||||||||||||
| 44 | 0 | my $r = Data::FormValidator->check($input_hash, $dfv_profile); | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | my @fields = (); | |||||||||||
| 47 | 0 | my $required = $r->{profile}{required}; | |||||||||||
| 48 | 0 | my $optional = $r->{profile}{optional}; | |||||||||||
| 49 | |||||||||||||
| 50 | 0 | push(@fields, @$required); | |||||||||||
| 51 | 0 | push(@fields, @$optional); | |||||||||||
| 52 | |||||||||||||
| 53 | 0 | for my $field (@fields) { | |||||||||||
| 54 | 0 | ▶ | $c->stash->{$field} = $c->req->param($field) // ""; | ||||||||||
|
Condition0%0/2
$c->req->param($field) // ""
MC/DC0%0/1
$c->req->param($field) // ""
$c->req->param($field)
Truth table0%0/2
A
A= $c->req->param($field)
| |||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | return if 0 == keys %$input_hash; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | |||||||||||||
| 59 | 0 | $results = $r; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 1 | 1; | |||||||||||
| 63 | |||||||||||||
| 64 | __END__ | ||||||||||||