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.52 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
14
|
|
|
|
|
|
|
# Copyright - Paul Seamons # |
15
|
|
|
|
|
|
|
# Distributed under the Perl Artistic License without warranty # |
16
|
|
|
|
|
|
|
###----------------------------------------------------------------### |
17
|
|
|
|
|
|
|
|
18
|
22
|
|
|
22
|
|
13147
|
use strict; |
|
22
|
|
|
|
|
40
|
|
|
22
|
|
|
|
|
600
|
|
19
|
22
|
|
|
22
|
|
92
|
use warnings; |
|
22
|
|
|
|
|
35
|
|
|
22
|
|
|
|
|
550
|
|
20
|
22
|
|
|
22
|
|
87
|
use Exporter qw(import); |
|
22
|
|
|
|
|
31
|
|
|
22
|
|
|
|
|
59896
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '2.52'; # 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
|
76769
|
my $text = shift; |
49
|
68
|
100
|
|
|
|
164
|
my $ref = ref($text) ? $text : \$text; |
50
|
68
|
|
|
|
|
93
|
my $form = shift; |
51
|
68
|
|
|
|
|
82
|
my $target = shift; |
52
|
68
|
|
|
|
|
79
|
my $fill_password = shift; |
53
|
68
|
|
100
|
|
|
241
|
my $ignore = shift || {}; |
54
|
|
|
|
|
|
|
|
55
|
68
|
|
|
|
|
267
|
fill({ |
56
|
|
|
|
|
|
|
text => $ref, |
57
|
|
|
|
|
|
|
form => $form, |
58
|
|
|
|
|
|
|
target => $target, |
59
|
|
|
|
|
|
|
fill_password => $fill_password, |
60
|
|
|
|
|
|
|
ignore_fields => $ignore, |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
68
|
100
|
|
|
|
268
|
return ref($text) ? 1 : $$ref; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub fill { |
67
|
142
|
|
|
142
|
0
|
176
|
my $args = shift; |
68
|
142
|
|
|
|
|
177
|
my $ref = $args->{'text'}; |
69
|
142
|
|
|
|
|
173
|
my $form = $args->{'form'}; |
70
|
142
|
|
|
|
|
155
|
my $target = $args->{'target'}; |
71
|
142
|
|
|
|
|
196
|
my $ignore = $args->{'ignore_fields'}; |
72
|
142
|
|
|
|
|
169
|
my $fill_password = $args->{'fill_password'}; |
73
|
|
|
|
|
|
|
|
74
|
142
|
100
|
|
|
|
372
|
my $forms = UNIVERSAL::isa($form, 'ARRAY') ? $form : [$form]; |
75
|
142
|
100
|
|
|
|
304
|
$ignore = {map {$_ => 1} @$ignore} if UNIVERSAL::isa($ignore, 'ARRAY'); |
|
5
|
|
|
|
|
11
|
|
76
|
142
|
100
|
|
|
|
241
|
$fill_password = 1 if ! defined $fill_password; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
### allow for optionally removing comments and script |
80
|
142
|
|
|
|
|
172
|
my @comment; |
81
|
|
|
|
|
|
|
my @script; |
82
|
142
|
100
|
|
|
|
311
|
if (defined($args->{'remove_script'}) ? $args->{'remove_script'} : $REMOVE_SCRIPT) { |
|
|
100
|
|
|
|
|
|
83
|
139
|
|
|
|
|
551
|
$$ref =~ s|( |