blib/lib/Nephia/Plugin/FormValidator/Lite.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 27 / 27 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package Nephia::Plugin::FormValidator::Lite;
2 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = "0.03";
7  
8 1 ▶use FormValidator::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use parent 'Nephia::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 my ($class, %opts) = @_;
15 my $self = $class->SUPER::new(%opts);
16 $self->{RUN_SQL} = [];
17 return $self;
18 }
19  
20 sub exports { qw/form/ }
21  
22 sub form(@) {
23 my $self = shift;
24 my $context = shift;
25 sub (@) {
26 my %rule = @_;
27 my $req = $context->get('req');
28 my $conf = $context->get('config')->{'Plugin::FormValidator::Lite'};
29 try {
30 FormValidator::Lite->load_constraints(@{$conf->{constants}});
31 }
32 catch {
33 croak 'Constraints of FormValidator::Lite is invalid format in config';
34 };
35  
36 my $validator;
37 try {
38 $validator = FormValidator::Lite->new($req);
39 $validator->load_function_message($conf->{function_message});
40 $validator->check(
41 %rule
42 );
43  
44 # default param message is param key
45 $validator->set_param_message(
46 map { $_, $_ } keys %rule
47 );
48 }
49 catch {
50 die $_;
51 };
52  
53 return $validator;
54 };
55 }
56  
57 1;
58 __END__
↑ Summary