blib/lib/CGI/Application/Plugin/ValidateRM.pm

filter: Statementstmt 95.1% 59 / 62 Branchbran 62.5% 10 / 16 Conditioncond 69.2% 9 / 13 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 8 / 8 Podpod 75.0% 3 / 4 totaltotal 83.6% 92 / 110 CC 15 SCAR 17.7
CC
15
Cov
86%
check_rm
8.8
dfv_error_page
7.1
dfv_results
2.0
CRAP 5.9
↑ Summary Build »
1 package CGI::Application::Plugin::ValidateRM;
2 4 ▶use base ('Exporter','AutoLoader');
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use HTML::FillInForm;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Data::FormValidator;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our @EXPORT = qw(
8 &dfv_results
9 &dfv_error_page
10 &check_rm_error_page
11 &check_rm
12 &validate_rm
13 );
14  
15 4 our $VERSION = '2.5';
16  
17 sub check_rm {
18 9 ▶ my $self = shift;
Subroutine check_rm: called CC=8 SCAR=21.7
Pod documented
19 9 ▶ my $return_rm = shift || die 'missing required return run mode';
Condition50%1/2
shift() || die('missing required return run mode')
l!l
90
MC/DC0%0/1
shift() || die('missing required return run mode')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
20 9 ▶ my $profile_in = shift || die 'missing required profile';
Condition50%1/2
shift() || die('missing required profile')
l!l
90
MC/DC0%0/1
shift() || die('missing required profile')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
21 9 ▶ my $fif_params = shift || {};
Condition100%2/2
shift() || {}
l!l
18
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
22  
23 # If the profile is not a hash reference,
24 # assume it's a CGI::App method
25 9 my $profile;
26 9 ▶ if (ref $profile_in eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $profile_in eq 'HASH') { } 1 8 9
27 1 $profile = $profile_in;
28 }
29 else {
30 8 ▶ if ($self->can($profile_in)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($profile_in)) { } 8 0 8
31 8 $profile = $self->$profile_in();
32 }
33 else {
34 0 $profile = eval { $self->$profile_in() };
35 0 ▶ die "Error running profile method '$profile_in': $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
36 }
37  
38 }
39  
40 9 require Data::FormValidator;
41 9 my $dfv = Data::FormValidator->new({}, $self->param('dfv_defaults') );
42 9 my $r =$dfv->check($self->query,$profile);
43 9 $self->{'__DFV_RESULT'} = $r;
44  
45 # Pass the params through the object so the user
46 # can just call dfv_error_page() later
47 9 $self->{'__DFV_RETURN_RM'} = $return_rm;
48 9 $self->{'__DFV_FIF_PARAMS'} = $fif_params;
49  
50 9 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 7 2 9
51 # We have to call the function non-traditionally to achieve mix-in happiness.
52 7 return $r, dfv_error_page($self);
53 }
54 else {
55 2 return $r;
56 }
57 }
58  
59 sub dfv_results {
60 1 ▶ my $self = shift;
Subroutine dfv_results: called CC=2 SCAR=7.1
Pod documented
61 1 ▶ die "must call check_rm() or validate_rm() first." unless defined $self->{'__DFV_RESULT'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"__DFV_RESULT"} 0 1 1
62 1 return $self->{'__DFV_RESULT'};
63 }
64  
65 sub validate_rm {
66 6 ▶ my $self = shift;
Subroutine validate_rm: called CC=1 SCAR=0.0
Pod documented
67 6 my ($r,$err_page) = $self->check_rm(@_);
68 6 return (scalar $r->valid,$err_page);
69 }
70  
71 sub dfv_error_page {
72 8 ▶ my $self = shift;
Subroutine dfv_error_page: called CC=7 SCAR=19.6
Pod undocumented
73 8 my $r = $self->{'__DFV_RESULT'};
74 8 my $return_rm = $self->{'__DFV_RETURN_RM'};
75 8 ▶ my $fif_params = $self->param('dfv_fif_defaults') || {};
Condition100%2/2
$self->param('dfv_fif_defaults') || {}
l!l
17
MC/DC100%1/1
$self->param('dfv_fif_defaults') || {}
$self->param('dfv_fif_defaults')
Truth table100%2/2
A
A= $self->param('dfv_fif_defaults')
Aresult
11
00
76  
77 # merge the defaults with the ones given for this fill
78 8 $fif_params = {%$fif_params, %{$self->{'__DFV_FIF_PARAMS'}}};
79  
80 8 my $err_page = undef;
81 8 ▶ if ($r->has_missing or $r->has_invalid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->has_missing or $r->has_invalid) 8 0 8
Condition33%1/3
$r->has_missing or $r->has_invalid
l!l&&r!l&&!r
800
MC/DC0%0/2
$r->has_missing or $r->has_invalid
$r->has_missing $r->has_invalid
Truth table33%1/3
A or B
A= $r->has_missingB= $r->has_invalid
ABresult
1X1
011
000
82 # If ::Forward has been loaded, act like forward()
83 8 my $before_rm = $self->{__CURRENT_RUNMODE};
84 8 ▶ $self->{__CURRENT_RUNMODE} = $return_rm if ($INC{'CGI/Application/Plugin/Forward.pm'});
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"CGI/Application/Plugin/Forward.pm"} 0 8 8
85  
86 8 my $return_page = $self->$return_rm($r->msgs);
87  
88 8 $self->{__CURRENT_RUNMODE} = $before_rm;
89  
90 8 ▶ my $return_pageref = (ref($return_page) eq 'SCALAR')
Branch: 1 branch
BranchTrueFalseTotal
ref $return_page eq 'SCALAR' ? : 1 7 8
91 ? $return_page : \$return_page;
92  
93 8 ▶ my $fif_class = $self->param('dfv_fif_class') || 'HTML::FillInForm';
Condition100%2/2
$self->param('dfv_fif_class') || 'HTML::FillInForm'
l!l
17
MC/DC100%1/1
$self->param('dfv_fif_class') || 'HTML::FillInForm'
$self->param('dfv_fif_class')
Truth table100%2/2
A
A= $self->param('dfv_fif_class')
Aresult
11
00
94 8 eval "require $fif_class";
95 # Deliberately do _not_ check if the eval succeeded,
96 # since $fif_class might be an inlined class not to be found in @INC.
97 8 my $fif = $fif_class->new();
98 8 $err_page = $fif->fill(
99 scalarref => $return_pageref,
100 fobject => $self->query,
101 %$fif_params,
102 );
103 }
104 8 return $err_page;
105 }
106  
107 4 *check_rm_error_page = \&dfv_error_page;
108 4 my $avoid_warning = \&check_rm_error_page;
109  
110 4 1;
111 __END__
↑ Summary Build »