| 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')
MC/DC0%0/1
shift() || die('missing required return run mode')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 20 | 9 | ▶ | my $profile_in = shift || die 'missing required profile'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || die('missing required profile')
MC/DC0%0/1
shift() || die('missing required profile')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | my $fif_params = shift || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 27 | 1 | $profile = $profile_in; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | else { | ||||||||||||||||||||||||||||
| 30 | 8 | ▶ | if ($self->can($profile_in)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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') || {}
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')
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$r->has_missing or $r->has_invalid
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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'
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')
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||