| 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.54 |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
|
14
|
|
|
|
|
|
|
# Copyright - Paul Seamons # |
|
15
|
|
|
|
|
|
|
# Distributed under the Perl Artistic License without warranty # |
|
16
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
|
17
|
|
|
|
|
|
|
|
|
18
|
22
|
|
|
22
|
|
13031
|
use strict; |
|
|
22
|
|
|
|
|
38
|
|
|
|
22
|
|
|
|
|
557
|
|
|
19
|
22
|
|
|
22
|
|
91
|
use warnings; |
|
|
22
|
|
|
|
|
31
|
|
|
|
22
|
|
|
|
|
511
|
|
|
20
|
22
|
|
|
22
|
|
83
|
use Exporter qw(import); |
|
|
22
|
|
|
|
|
31
|
|
|
|
22
|
|
|
|
|
60042
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '2.54'; # 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
|
80933
|
my $text = shift; |
|
49
|
68
|
100
|
|
|
|
170
|
my $ref = ref($text) ? $text : \$text; |
|
50
|
68
|
|
|
|
|
87
|
my $form = shift; |
|
51
|
68
|
|
|
|
|
88
|
my $target = shift; |
|
52
|
68
|
|
|
|
|
82
|
my $fill_password = shift; |
|
53
|
68
|
|
100
|
|
|
247
|
my $ignore = shift || {}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
68
|
|
|
|
|
244
|
fill({ |
|
56
|
|
|
|
|
|
|
text => $ref, |
|
57
|
|
|
|
|
|
|
form => $form, |
|
58
|
|
|
|
|
|
|
target => $target, |
|
59
|
|
|
|
|
|
|
fill_password => $fill_password, |
|
60
|
|
|
|
|
|
|
ignore_fields => $ignore, |
|
61
|
|
|
|
|
|
|
}); |
|
62
|
|
|
|
|
|
|
|
|
63
|
68
|
100
|
|
|
|
292
|
return ref($text) ? 1 : $$ref; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub fill { |
|
67
|
142
|
|
|
142
|
0
|
175
|
my $args = shift; |
|
68
|
142
|
|
|
|
|
181
|
my $ref = $args->{'text'}; |
|
69
|
142
|
|
|
|
|
174
|
my $form = $args->{'form'}; |
|
70
|
142
|
|
|
|
|
163
|
my $target = $args->{'target'}; |
|
71
|
142
|
|
|
|
|
180
|
my $ignore = $args->{'ignore_fields'}; |
|
72
|
142
|
|
|
|
|
164
|
my $fill_password = $args->{'fill_password'}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
142
|
100
|
|
|
|
371
|
my $forms = UNIVERSAL::isa($form, 'ARRAY') ? $form : [$form]; |
|
75
|
142
|
100
|
|
|
|
297
|
$ignore = {map {$_ => 1} @$ignore} if UNIVERSAL::isa($ignore, 'ARRAY'); |
|
|
5
|
|
|
|
|
14
|
|
|
76
|
142
|
100
|
|
|
|
240
|
$fill_password = 1 if ! defined $fill_password; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
### allow for optionally removing comments and script |
|
80
|
142
|
|
|
|
|
177
|
my @comment; |
|
81
|
|
|
|
|
|
|
my @script; |
|
82
|
142
|
100
|
|
|
|
322
|
if (defined($args->{'remove_script'}) ? $args->{'remove_script'} : $REMOVE_SCRIPT) { |
|
|
|
100
|
|
|
|
|
|
|
83
|
139
|
|
|
|
|
544
|
$$ref =~ s|( |