line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::ValidateRM; |
2
|
4
|
|
|
4
|
|
293380
|
use base ('Exporter','AutoLoader'); |
|
4
|
|
|
|
|
39
|
|
|
4
|
|
|
|
|
2749
|
|
3
|
4
|
|
|
4
|
|
8816
|
use HTML::FillInForm; |
|
4
|
|
|
|
|
15929
|
|
|
4
|
|
|
|
|
156
|
|
4
|
4
|
|
|
4
|
|
4011
|
use Data::FormValidator; |
|
4
|
|
|
|
|
90537
|
|
|
4
|
|
|
|
|
192
|
|
5
|
4
|
|
|
4
|
|
34
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
2256
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw( |
8
|
|
|
|
|
|
|
&dfv_results |
9
|
|
|
|
|
|
|
&dfv_error_page |
10
|
|
|
|
|
|
|
&check_rm_error_page |
11
|
|
|
|
|
|
|
&check_rm |
12
|
|
|
|
|
|
|
&validate_rm |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '2.52'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub check_rm { |
18
|
9
|
|
|
9
|
1
|
36008
|
my $self = shift; |
19
|
9
|
|
50
|
|
|
39
|
my $return_rm = shift || die 'missing required return run mode'; |
20
|
9
|
|
50
|
|
|
31
|
my $profile_in = shift || die 'missing required profile'; |
21
|
9
|
|
100
|
|
|
76
|
my $fif_params = shift || {}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# If the profile is not a hash reference, |
24
|
|
|
|
|
|
|
# assume it's a CGI::App method |
25
|
9
|
|
|
|
|
65
|
my $profile; |
26
|
9
|
100
|
|
|
|
46
|
if (ref $profile_in eq 'HASH') { |
27
|
1
|
|
|
|
|
3
|
$profile = $profile_in; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
8
|
50
|
|
|
|
55
|
if ($self->can($profile_in)) { |
31
|
8
|
|
|
|
|
34
|
$profile = $self->$profile_in(); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
0
|
$profile = eval { $self->$profile_in() }; |
|
0
|
|
|
|
|
0
|
|
35
|
0
|
0
|
|
|
|
0
|
die "Error running profile method '$profile_in': $@" if $@; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
190
|
my $dfv = Data::FormValidator->new({}, $self->param('dfv_defaults') ); |
41
|
9
|
|
|
|
|
474
|
my $r =$dfv->check($self->query,$profile); |
42
|
9
|
|
|
|
|
403250
|
$self->{'__DFV_RESULT'} = $r; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Pass the params through the object so the user |
45
|
|
|
|
|
|
|
# can just call dfv_error_page() later |
46
|
9
|
|
|
|
|
69
|
$self->{'__DFV_RETURN_RM'} = $return_rm; |
47
|
9
|
|
|
|
|
44
|
$self->{'__DFV_FIF_PARAMS'} = $fif_params; |
48
|
|
|
|
|
|
|
|
49
|
9
|
100
|
|
|
|
52
|
if (wantarray) { |
50
|
|
|
|
|
|
|
# We have to call the function non-traditionally to achieve mix-in happiness. |
51
|
7
|
|
|
|
|
84
|
return $r, dfv_error_page($self); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
2
|
|
|
|
|
10
|
return $r; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub dfv_results { |
59
|
1
|
|
|
1
|
1
|
2293
|
my $self = shift; |
60
|
1
|
50
|
|
|
|
9
|
die "must call check_rm() or validate_rm() first." unless defined $self->{'__DFV_RESULT'}; |
61
|
1
|
|
|
|
|
13
|
return $self->{'__DFV_RESULT'}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub validate_rm { |
65
|
6
|
|
|
6
|
1
|
12676
|
my $self = shift; |
66
|
6
|
|
|
|
|
30
|
my ($r,$err_page) = $self->check_rm(@_); |
67
|
6
|
|
|
|
|
41
|
return (scalar $r->valid,$err_page); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub dfv_error_page { |
71
|
8
|
|
|
8
|
0
|
58
|
my $self = shift; |
72
|
8
|
|
|
|
|
146
|
my $r = $self->{'__DFV_RESULT'}; |
73
|
8
|
|
|
|
|
43
|
my $return_rm = $self->{'__DFV_RETURN_RM'}; |
74
|
8
|
|
100
|
|
|
133
|
my $fif_params = $self->param('dfv_fif_defaults') || {}; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# merge the defaults with the ones given for this fill |
77
|
8
|
|
|
|
|
311
|
$fif_params = {%$fif_params, %{$self->{'__DFV_FIF_PARAMS'}}}; |
|
8
|
|
|
|
|
44
|
|
78
|
|
|
|
|
|
|
|
79
|
8
|
|
|
|
|
29
|
my $err_page = undef; |
80
|
8
|
50
|
33
|
|
|
61
|
if ($r->has_missing or $r->has_invalid) { |
81
|
|
|
|
|
|
|
# If ::Forward has been loaded, act like forward() |
82
|
8
|
|
|
|
|
106
|
my $before_rm = $self->{__CURRENT_RUNMODE}; |
83
|
8
|
50
|
|
|
|
57
|
$self->{__CURRENT_RUNMODE} = $return_rm if ($INC{'CGI/Application/Plugin/Forward.pm'}); |
84
|
|
|
|
|
|
|
|
85
|
8
|
|
|
|
|
105
|
my $return_page = $self->$return_rm($r->msgs); |
86
|
|
|
|
|
|
|
|
87
|
8
|
|
|
|
|
58844
|
$self->{__CURRENT_RUNMODE} = $before_rm; |
88
|
|
|
|
|
|
|
|
89
|
8
|
100
|
|
|
|
67
|
my $return_pageref = (ref($return_page) eq 'SCALAR') |
90
|
|
|
|
|
|
|
? $return_page : \$return_page; |
91
|
|
|
|
|
|
|
|
92
|
8
|
|
100
|
|
|
41
|
my $fif_class = $self->param('dfv_fif_class') || 'HTML::FillInForm'; |
93
|
8
|
|
|
|
|
229
|
eval { require $fif_class }; |
|
8
|
|
|
|
|
1099
|
|
94
|
|
|
|
|
|
|
# Deliberately do _not_ check if the eval succeeded, |
95
|
|
|
|
|
|
|
# since $fif_class might be an inlined class not to be found in @INC. |
96
|
8
|
|
|
|
|
123
|
my $fif = $fif_class->new(); |
97
|
8
|
|
|
|
|
29549
|
$err_page = $fif->fill( |
98
|
|
|
|
|
|
|
scalarref => $return_pageref, |
99
|
|
|
|
|
|
|
fobject => $self->query, |
100
|
|
|
|
|
|
|
%$fif_params, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
8
|
|
|
|
|
4566
|
return $err_page; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
*check_rm_error_page = \&dfv_error_page; |
107
|
|
|
|
|
|
|
my $avoid_warning = \&check_rm_error_page; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |