| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::ValidOp::Base; |
|
2
|
23
|
|
|
23
|
|
47283
|
use strict; |
|
|
23
|
|
|
|
|
46
|
|
|
|
23
|
|
|
|
|
730
|
|
|
3
|
23
|
|
|
23
|
|
115
|
use warnings; |
|
|
23
|
|
|
|
|
41
|
|
|
|
23
|
|
|
|
|
520
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
23
|
|
|
23
|
|
122
|
use Data::Dumper; |
|
|
23
|
|
|
|
|
39
|
|
|
|
23
|
|
|
|
|
1212
|
|
|
6
|
23
|
|
|
23
|
|
132
|
use Carp qw/ croak confess /; |
|
|
23
|
|
|
|
|
44
|
|
|
|
23
|
|
|
|
|
9189
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
1845
|
|
|
1845
|
0
|
23004
|
my $proto = shift; |
|
11
|
1845
|
|
66
|
|
|
8893
|
my $class = ref $proto || $proto; |
|
12
|
1845
|
|
|
|
|
6025
|
my $self = bless {}, $class; |
|
13
|
1845
|
|
|
|
|
7651
|
$self->init( @_ ); |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
17
|
|
|
|
|
|
|
# if the calling object has a PROPERTIES method, this |
|
18
|
|
|
|
|
|
|
# 1) creates accessor methods for each key returned, |
|
19
|
|
|
|
|
|
|
# 2) and calls the method with the value |
|
20
|
|
|
|
|
|
|
# if the key is prefixed with a '-', only (2) is performed |
|
21
|
|
|
|
|
|
|
sub init { |
|
22
|
1894
|
|
|
1894
|
0
|
3552
|
my $self = shift; |
|
23
|
1894
|
|
|
|
|
2789
|
my( $args ) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
1894
|
100
|
|
|
|
7687
|
return $self unless $self->can( 'PROPERTIES' ); |
|
26
|
1891
|
|
|
|
|
4694
|
$self->{ in_init } = 1; # tells other methods that we're not baked yet |
|
27
|
1891
|
|
|
|
|
5522
|
my $config = $self->PROPERTIES; |
|
28
|
1891
|
|
|
|
|
49572
|
for( keys %$config ) { |
|
29
|
10349
|
100
|
|
|
|
42944
|
$self->method( $_ ) |
|
30
|
|
|
|
|
|
|
unless $_ =~ /^-/; |
|
31
|
10349
|
|
|
|
|
20810
|
( my $prop = $_ ) =~ s/^-//; |
|
32
|
10349
|
|
|
|
|
30282
|
$self->$prop( $config->{ $_ }); # set default |
|
33
|
10349
|
100
|
100
|
|
|
62252
|
$self->$prop( $args->{ $prop }) # set incoming |
|
34
|
|
|
|
|
|
|
if ref $args eq 'HASH' and defined $args->{ $prop }; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
1891
|
|
|
|
|
5205
|
delete $self->{ in_init }; |
|
37
|
1891
|
|
|
|
|
11084
|
$self; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
41
|
|
|
|
|
|
|
# creates a method to store the property |
|
42
|
|
|
|
|
|
|
sub method { |
|
43
|
9312
|
|
|
9312
|
0
|
12249
|
my $self = shift; |
|
44
|
9312
|
|
|
|
|
12711
|
my( $property ) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
9312
|
|
|
|
|
13494
|
my $pkg = caller; |
|
47
|
9312
|
100
|
|
|
|
62324
|
return if $pkg->can( $property ); |
|
48
|
|
|
|
|
|
|
|
|
49
|
23
|
|
|
23
|
|
142
|
no strict 'refs'; |
|
|
23
|
|
|
|
|
47
|
|
|
|
23
|
|
|
|
|
37240
|
|
|
50
|
272
|
|
|
|
|
1896
|
*{ "${ pkg }::$property" } = |
|
51
|
|
|
|
|
|
|
sub { |
|
52
|
21794
|
|
|
21794
|
|
34793
|
my $self = shift; |
|
53
|
21794
|
|
|
|
|
28607
|
my( $value ) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
21794
|
100
|
|
|
|
52759
|
if( @_ ) { |
|
56
|
13564
|
100
|
100
|
|
|
48834
|
undef $value if defined $value and $value eq ''; |
|
57
|
13564
|
|
|
|
|
27367
|
$self->{ $property } = $value; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
21794
|
100
|
|
|
|
63744
|
return unless defined wantarray; |
|
60
|
8244
|
100
|
100
|
|
|
31778
|
return @{ $self->{ $property }} |
|
|
1927
|
|
|
|
|
11209
|
|
|
61
|
|
|
|
|
|
|
if wantarray and ref $self->{ $property } eq 'ARRAY'; |
|
62
|
6317
|
100
|
100
|
|
|
18523
|
return %{ $self->{ $property }} |
|
|
5
|
|
|
|
|
38
|
|
|
63
|
|
|
|
|
|
|
if wantarray and ref $self->{ $property } eq 'HASH'; |
|
64
|
6312
|
|
|
|
|
39608
|
$self->{ $property }; |
|
65
|
272
|
|
|
|
|
1238
|
}; |
|
66
|
272
|
|
|
|
|
653
|
return; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
70
|
|
|
|
|
|
|
# accessor for object name; will accept a scalar word |
|
71
|
|
|
|
|
|
|
# or a hashref containing a 'name' key |
|
72
|
|
|
|
|
|
|
sub set_name { |
|
73
|
758
|
|
|
758
|
0
|
9262
|
my $self = shift; |
|
74
|
758
|
|
|
|
|
1013
|
my( $args ) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
758
|
|
|
|
|
2938
|
my %e = ( |
|
77
|
|
|
|
|
|
|
api => q/ERROR: set_name() API./, |
|
78
|
|
|
|
|
|
|
preq => q/Parameter names are required for all values./, |
|
79
|
|
|
|
|
|
|
regex => q/Parameter names must contain only letters, numbers, underscores, and square brackets./, |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
758
|
|
|
|
|
897
|
my $name; |
|
83
|
758
|
100
|
|
|
|
2007
|
if( ref $args ) { |
|
84
|
748
|
100
|
100
|
|
|
4469
|
croak $e{ api } unless ref $args eq 'HASH' and keys %$args; |
|
85
|
745
|
100
|
|
|
|
4683
|
croak $e{ api } unless grep /^name$/ => keys %$args; |
|
86
|
740
|
100
|
|
|
|
2024
|
croak $e{ preq } unless $args->{ name }; |
|
87
|
738
|
|
|
|
|
1380
|
$name = $args->{ name }; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
748
|
|
100
|
|
|
1784
|
$name ||= $args; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
croak $e{ preq } |
|
92
|
748
|
100
|
|
|
|
1791
|
unless $name; |
|
93
|
|
|
|
|
|
|
croak $e{ regex } |
|
94
|
745
|
100
|
|
|
|
3155
|
unless $name =~ /^[\w\[\]-]+$/; |
|
95
|
|
|
|
|
|
|
|
|
96
|
742
|
|
|
|
|
1791
|
$self->{ name } = $name; |
|
97
|
742
|
|
|
|
|
11308
|
$self->{ name }; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
101
|
|
|
|
|
|
|
# adapted from 'CGI Programming with Perl' |
|
102
|
|
|
|
|
|
|
sub is_tainted { |
|
103
|
443
|
|
|
443
|
0
|
694
|
my $self = shift; |
|
104
|
443
|
|
|
|
|
729
|
my( $value ) = @_; |
|
105
|
|
|
|
|
|
|
|
|
106
|
443
|
100
|
|
|
|
1669
|
return unless defined $value; |
|
107
|
282
|
|
|
|
|
733
|
my $blank = substr( $value, 0, 0 ); |
|
108
|
282
|
50
|
|
|
|
440
|
return not eval { eval "1 || $blank" || 1 }; |
|
|
282
|
|
|
|
|
11292
|
|
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
112
|
|
|
|
|
|
|
sub error_decoration { |
|
113
|
1678
|
|
|
1678
|
0
|
2360
|
my $self = shift; |
|
114
|
1678
|
|
|
|
|
2338
|
my( $begin, $end ) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# must accept arrayref |
|
117
|
1678
|
100
|
|
|
|
4468
|
( $begin, $end ) = @$begin |
|
118
|
|
|
|
|
|
|
if ref $begin eq 'ARRAY'; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# we have to be able to pass undef as the second param |
|
121
|
1678
|
100
|
100
|
|
|
7407
|
$end = $begin if ! defined $end and @_ == 1; |
|
122
|
1678
|
100
|
|
|
|
4049
|
if( @_ ) { |
|
123
|
923
|
|
|
|
|
2683
|
$self->{ error_decoration } = [ $begin, $end ]; |
|
124
|
923
|
|
|
|
|
2044
|
return( $begin, $end ); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
754
|
|
|
|
|
5372
|
( $begin, $end ) = @{ $self->{ error_decoration }} |
|
128
|
755
|
100
|
|
|
|
1939
|
if $self->{ error_decoration }; |
|
129
|
755
|
100
|
100
|
|
|
4969
|
return @{ $self->{ error_decoration }} |
|
|
100
|
|
|
|
|
445
|
|
|
130
|
|
|
|
|
|
|
if defined $begin or defined $end; |
|
131
|
655
|
|
|
|
|
1957
|
return; |
|
132
|
|
|
|
|
|
|
}; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |