line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Ex::Fill; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
CGI::Ex::Fill - Fast but compliant regex based form filler |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
version 2.53 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
14
|
|
|
|
|
|
|
# Copyright - Paul Seamons # |
15
|
|
|
|
|
|
|
# Distributed under the Perl Artistic License without warranty # |
16
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
17
|
|
|
|
|
|
|
|
18
|
22
|
|
|
22
|
|
13331
|
use strict; |
|
22
|
|
|
|
|
42
|
|
|
22
|
|
|
|
|
565
|
|
19
|
22
|
|
|
22
|
|
92
|
use warnings; |
|
22
|
|
|
|
|
35
|
|
|
22
|
|
|
|
|
651
|
|
20
|
22
|
|
|
22
|
|
119
|
use Exporter qw(import); |
|
22
|
|
|
|
|
31
|
|
|
22
|
|
|
|
|
59786
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '2.53'; # VERSION |
23
|
|
|
|
|
|
|
our @EXPORT = qw(form_fill); |
24
|
|
|
|
|
|
|
our @EXPORT_OK = qw(fill form_fill html_escape get_tagval_by_key swap_tagval_by_key); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
### These directives are used to determine whether or not to |
27
|
|
|
|
|
|
|
### remove html comments and script sections while filling in |
28
|
|
|
|
|
|
|
### a form. Default is on. This may give some trouble if you |
29
|
|
|
|
|
|
|
### have a javascript section with form elements that you would |
30
|
|
|
|
|
|
|
### like filled in. |
31
|
|
|
|
|
|
|
our $REMOVE_SCRIPT = 1; |
32
|
|
|
|
|
|
|
our $REMOVE_COMMENT = 1; |
33
|
|
|
|
|
|
|
our $MARKER_SCRIPT = "\0SCRIPT\0"; |
34
|
|
|
|
|
|
|
our $MARKER_COMMENT = "\0COMMENT\0"; |
35
|
|
|
|
|
|
|
our $OBJECT_METHOD = "param"; |
36
|
|
|
|
|
|
|
our $_TEMP_TARGET; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
### Regex based filler - as opposed to HTML::Parser based HTML::FillInForm |
41
|
|
|
|
|
|
|
### arguments are positional |
42
|
|
|
|
|
|
|
### pos1 - text or textref - if textref it is modified in place |
43
|
|
|
|
|
|
|
### pos2 - hash or cgi obj ref, or array ref of hash and cgi obj refs |
44
|
|
|
|
|
|
|
### pos3 - target - to be used for choosing a specific form - default undef |
45
|
|
|
|
|
|
|
### pos4 - boolean fill in password fields - default is true |
46
|
|
|
|
|
|
|
### pos5 - hashref or arrayref of fields to ignore |
47
|
|
|
|
|
|
|
sub form_fill { |
48
|
68
|
|
|
68
|
0
|
82046
|
my $text = shift; |
49
|
68
|
100
|
|
|
|
173
|
my $ref = ref($text) ? $text : \$text; |
50
|
68
|
|
|
|
|
84
|
my $form = shift; |
51
|
68
|
|
|
|
|
87
|
my $target = shift; |
52
|
68
|
|
|
|
|
86
|
my $fill_password = shift; |
53
|
68
|
|
100
|
|
|
237
|
my $ignore = shift || {}; |
54
|
|
|
|
|
|
|
|
55
|
68
|
|
|
|
|
251
|
fill({ |
56
|
|
|
|
|
|
|
text => $ref, |
57
|
|
|
|
|
|
|
form => $form, |
58
|
|
|
|
|
|
|
target => $target, |
59
|
|
|
|
|
|
|
fill_password => $fill_password, |
60
|
|
|
|
|
|
|
ignore_fields => $ignore, |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
68
|
100
|
|
|
|
273
|
return ref($text) ? 1 : $$ref; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub fill { |
67
|
142
|
|
|
142
|
0
|
168
|
my $args = shift; |
68
|
142
|
|
|
|
|
198
|
my $ref = $args->{'text'}; |
69
|
142
|
|
|
|
|
207
|
my $form = $args->{'form'}; |
70
|
142
|
|
|
|
|
179
|
my $target = $args->{'target'}; |
71
|
142
|
|
|
|
|
166
|
my $ignore = $args->{'ignore_fields'}; |
72
|
142
|
|
|
|
|
161
|
my $fill_password = $args->{'fill_password'}; |
73
|
|
|
|
|
|
|
|
74
|
142
|
100
|
|
|
|
377
|
my $forms = UNIVERSAL::isa($form, 'ARRAY') ? $form : [$form]; |
75
|
142
|
100
|
|
|
|
310
|
$ignore = {map {$_ => 1} @$ignore} if UNIVERSAL::isa($ignore, 'ARRAY'); |
|
5
|
|
|
|
|
13
|
|
76
|
142
|
100
|
|
|
|
253
|
$fill_password = 1 if ! defined $fill_password; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
### allow for optionally removing comments and script |
80
|
142
|
|
|
|
|
187
|
my @comment; |
81
|
|
|
|
|
|
|
my @script; |
82
|
142
|
100
|
|
|
|
352
|
if (defined($args->{'remove_script'}) ? $args->{'remove_script'} : $REMOVE_SCRIPT) { |
|
|
100
|
|
|
|
|
|
83
|
139
|
|
|
|
|
555
|
$$ref =~ s|( |