blib/lib/Mojolicious/Plugin/FormValidator.pm

filter: Statementstmt 32.4% 12 / 37 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 3 / 6 Podpod 50.0% 1 / 2 totaltotal 26.6% 16 / 60 CC 9 SCAR 28.6
CC
9
Cov
24%
__ANON__
30.0
_dfv_verify
20.0
dfv_verify
6.0
CRAP 17.5
↑ Summary
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
BranchTrueFalseTotal
unless $profile 0 0 0
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
BranchTrueFalseTotal
unless defined $Mojolicious::Plugin::FormValidator::results 0 0 0
29 0 ▶ return 0 if $results->valid($field);
Branch: 1 branch
BranchTrueFalseTotal
if $Mojolicious::Plugin::FormValidator::results->valid($field) 0 0 0
30 0 ▶ return 1 if $results->invalid($field);
Branch: 1 branch
BranchTrueFalseTotal
if $Mojolicious::Plugin::FormValidator::results->invalid($field) 0 0 0
31 0 ▶ return 1 if $results->missing($field);
Branch: 1 branch
BranchTrueFalseTotal
if $Mojolicious::Plugin::FormValidator::results->missing($field) 0 0 0
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) // ""
l!l
00
MC/DC0%0/1
$c->req->param($field) // ""
$c->req->param($field)
Truth table0%0/2
A
A= $c->req->param($field)
Aresult
11
00
55 }
56  
57 0 ▶ return if 0 == keys %$input_hash;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == keys %$input_hash 0 0 0
58  
59 0 $results = $r;
60 }
61  
62 1 1;
63  
64 __END__
↑ Summary