line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::ValidOp::Op; |
2
|
10
|
|
|
10
|
|
78717
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
392
|
|
3
|
10
|
|
|
10
|
|
89
|
use warnings; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
307
|
|
4
|
|
|
|
|
|
|
|
5
|
10
|
|
|
10
|
|
52
|
use base qw/ CGI::ValidOp::Base /; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
1497
|
|
6
|
10
|
|
|
10
|
|
4528
|
use CGI::ValidOp::Param; |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
317
|
|
7
|
10
|
|
|
10
|
|
58
|
use Data::Dumper; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
530
|
|
8
|
10
|
|
|
10
|
|
56
|
use Carp; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
5510
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
11
|
|
|
|
|
|
|
sub PROPERTIES { |
12
|
|
|
|
|
|
|
{ |
13
|
130
|
|
|
130
|
0
|
763
|
name => undef, |
14
|
|
|
|
|
|
|
alias => undef, |
15
|
|
|
|
|
|
|
error_op => undef, |
16
|
|
|
|
|
|
|
-error_decoration => undef, |
17
|
|
|
|
|
|
|
on_error_return => 'undef', |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
22
|
|
|
|
|
|
|
# the argument parsing means: |
23
|
|
|
|
|
|
|
# 1) if an argument is an existing method, take it as a config option |
24
|
|
|
|
|
|
|
# 2) else take it as a param |
25
|
|
|
|
|
|
|
# FIXME should have a params key instead; this is too magical |
26
|
|
|
|
|
|
|
sub init { |
27
|
66
|
|
|
66
|
0
|
91
|
my $self = shift; |
28
|
66
|
|
|
|
|
84
|
my( $args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
66
|
|
|
|
|
240
|
$self->SUPER::init; # FIXME nasty hack to get around methods not being |
31
|
|
|
|
|
|
|
# defined 'cause we return if no input |
32
|
66
|
50
|
|
|
|
255
|
$self->set_name( $args ) |
33
|
|
|
|
|
|
|
or croak 'Name required in CGI::ValidOp::Op::init.'; |
34
|
|
|
|
|
|
|
|
35
|
65
|
100
|
|
|
|
194
|
return $self unless ref $args eq 'HASH'; |
36
|
64
|
|
|
|
|
93
|
my( %config, %params ); |
37
|
64
|
|
|
|
|
169
|
for( keys %$args ) { |
38
|
194
|
100
|
|
|
|
1040
|
$self->can( $_ ) |
39
|
|
|
|
|
|
|
? $config{ $_ } = $args->{ $_ } |
40
|
|
|
|
|
|
|
: $params{ $_ } = $args->{ $_ }; |
41
|
|
|
|
|
|
|
} |
42
|
64
|
|
|
|
|
259
|
$self->SUPER::init( \%config ); |
43
|
64
|
|
|
|
|
231
|
for( keys %params ) { |
44
|
5
|
|
|
|
|
16
|
$params{ $_ }->{ name } = $_; |
45
|
5
|
|
|
|
|
13
|
$self->add_param( $params{ $_ }); |
46
|
|
|
|
|
|
|
} |
47
|
64
|
|
|
|
|
342
|
$self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
51
|
|
|
|
|
|
|
# takes a hashref specifying a parameter |
52
|
|
|
|
|
|
|
sub add_param { |
53
|
207
|
|
|
207
|
0
|
666
|
my $self = shift; |
54
|
207
|
|
|
|
|
346
|
my( $vars ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
207
|
100
|
100
|
|
|
941
|
if( defined $vars and ref $vars eq '' ) { |
57
|
151
|
|
|
|
|
6061
|
$vars = { name => $vars }; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
207
|
|
|
|
|
696
|
$vars->{ on_error_return } = $self->on_error_return; |
61
|
207
|
50
|
|
|
|
1089
|
croak 'no param created' |
62
|
|
|
|
|
|
|
unless my $param = CGI::ValidOp::Param->new( $vars ); |
63
|
202
|
|
|
|
|
554
|
$param->error_decoration( $self->error_decoration ); |
64
|
202
|
|
|
|
|
608
|
$self->{ _params }{ $param->name } = $param; |
65
|
202
|
|
|
|
|
748
|
$param; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
69
|
|
|
|
|
|
|
# returns all Param objects unless asked for one |
70
|
|
|
|
|
|
|
# also sets new checks for a param if they're given |
71
|
|
|
|
|
|
|
sub Param { |
72
|
412
|
|
|
412
|
0
|
2026
|
my $self = shift; |
73
|
412
|
|
|
|
|
789
|
my( $param_name, $checks ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
412
|
100
|
|
|
|
1019
|
if( $param_name ) { |
76
|
276
|
|
|
|
|
735
|
my $param = $self->{ _params }{ $param_name }; |
77
|
276
|
100
|
100
|
|
|
1153
|
$param->checks( $checks ) if $param and $checks; |
78
|
276
|
|
|
|
|
1233
|
return $param; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
136
|
|
|
|
|
187
|
my @params; |
82
|
|
|
|
|
|
|
push @params => $self->{ _params }{ $_ } |
83
|
136
|
|
|
|
|
210
|
for sort keys %{ $self->{ _params }}; |
|
136
|
|
|
|
|
2433
|
|
84
|
136
|
100
|
|
|
|
556
|
return unless @params; |
85
|
94
|
100
|
|
|
|
647
|
wantarray ? @params : \@params; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |