line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::Role::SubmitForm; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
116265
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
292
|
use Role::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
201
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1088
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.004003'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub click_ok { |
10
|
16
|
|
|
16
|
1
|
392838
|
my ( $self, $selector_or_dom, $extra_params ) = @_; |
11
|
16
|
|
100
|
|
|
163
|
$extra_params ||= {}; |
12
|
|
|
|
|
|
|
|
13
|
16
|
100
|
66
|
|
|
42
|
my $el = eval { $selector_or_dom->isa('Mojo::DOM') } |
|
16
|
|
|
|
|
295
|
|
14
|
|
|
|
|
|
|
? $selector_or_dom |
15
|
|
|
|
|
|
|
: $self->tx->res->dom->at($selector_or_dom) |
16
|
|
|
|
|
|
|
|| croak 'Test::Mojo::Role::SubmitForm::click_ok()' |
17
|
|
|
|
|
|
|
. " Did not find element matching selector $selector_or_dom"; |
18
|
15
|
100
|
|
|
|
116766
|
unless ( $el->tag eq 'form' ) { |
19
|
7
|
50
|
|
|
|
152
|
if (length $el->{name}) { |
20
|
7
|
100
|
50
|
|
|
154
|
if ( ($el->{type}//'') eq 'image' ) { |
21
|
2
|
|
|
|
|
36
|
$extra_params->{ $el->{name} . '.x' } = 1; |
22
|
2
|
|
|
|
|
38
|
$extra_params->{ $el->{name} . '.y' } = 1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
5
|
|
|
|
|
102
|
$extra_params->{ $el->{name} } = $el->val; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
|
|
362
|
$el = $el->ancestors('form')->first; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
15
|
|
|
|
|
3424
|
for ( sort keys %$extra_params ) { |
33
|
19
|
100
|
|
|
|
126
|
next unless ref $extra_params->{$_} eq 'CODE'; |
34
|
5
|
|
|
|
|
22
|
( my $name = $_ ) =~ s/"/\\"/g; |
35
|
5
|
|
|
|
|
33
|
$extra_params->{$_} = $extra_params->{$_}->( |
36
|
|
|
|
|
|
|
$self->_gather_vals( $el->find(qq{[name="$name"]})->each ) |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
15
|
|
|
|
|
88
|
my %form = ( |
41
|
|
|
|
|
|
|
$self->_get_controls($el), |
42
|
|
|
|
|
|
|
%$extra_params, |
43
|
|
|
|
|
|
|
); |
44
|
15
|
|
|
|
|
72
|
for (keys %form) { |
45
|
82
|
100
|
|
|
|
200
|
delete $form{$_} unless defined $form{$_} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
15
|
50
|
|
|
|
84
|
if ( $ENV{MOJO_SUBMITFORM_DEBUG} ) { |
49
|
0
|
|
|
|
|
0
|
warn "\n########## SUBMITTING FORM ##########\n"; |
50
|
0
|
|
|
|
|
0
|
require Mojo::Util; |
51
|
0
|
|
|
|
|
0
|
warn Mojo::Util::dumper(\%form); |
52
|
0
|
|
|
|
|
0
|
warn "########## END FORM ##########\n\n"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $tx = $self->ua->build_tx( |
56
|
15
|
100
|
100
|
|
|
113
|
$el->{method}||'GET' => defined $el->{action} && $el->{action} ne '' ? $el->{action} : $self->tx->req->url |
|
|
|
100
|
|
|
|
|
57
|
|
|
|
|
|
|
=> form => \%form, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
15
|
|
|
|
|
18199
|
$self->request_ok( $tx ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _gather_vals { |
64
|
123
|
|
|
123
|
|
11947
|
my ( $self, @els ) = @_; |
65
|
123
|
|
|
|
|
234
|
my @vals; |
66
|
123
|
|
|
|
|
257
|
for ( @els ) { |
67
|
125
|
100
|
|
|
|
336
|
next if $_ |
68
|
|
|
|
|
|
|
->matches('[type=radio]:not(:checked), [type=checkbox]:not(:checked)'); |
69
|
|
|
|
|
|
|
|
70
|
109
|
100
|
|
|
|
44772
|
defined( my $val = $_->val ) or next; |
71
|
104
|
100
|
|
|
|
41624
|
push @vals, ref $val ? @$val : $val; |
72
|
|
|
|
|
|
|
} |
73
|
123
|
100
|
|
|
|
8984
|
return @vals == 1 ? $vals[0] : @vals ? \@vals : undef; |
|
|
100
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _get_controls { |
77
|
15
|
|
|
15
|
|
58
|
my ( $self, $form ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
15
|
|
|
|
|
93
|
my @els = $form->find( |
80
|
|
|
|
|
|
|
'input:not([type=button]):not([type=submit]):not([type=image]):not([disabled]),' . |
81
|
|
|
|
|
|
|
'select:not([disabled]),' . |
82
|
|
|
|
|
|
|
'textarea:not([disabled])' |
83
|
|
|
|
|
|
|
)->each; |
84
|
|
|
|
|
|
|
|
85
|
15
|
|
|
|
|
54389
|
my %controls; |
86
|
15
|
|
|
|
|
60
|
for ( @els ) { |
87
|
118
|
100
|
|
|
|
1690
|
defined(my $vals = $self->_gather_vals( $_ )) or next; |
88
|
98
|
100
|
|
|
|
180
|
push @{ $controls{$_->{name}} }, ref $vals ? @$vals : $vals; |
|
98
|
|
|
|
|
231
|
|
89
|
|
|
|
|
|
|
} |
90
|
15
|
|
100
|
|
|
278
|
$#$_ or $_= $_->[0] for values %controls; # chage 1-el arrayrefs to strings |
91
|
|
|
|
|
|
|
|
92
|
15
|
|
|
|
|
260
|
return %controls; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
q| |
96
|
|
|
|
|
|
|
The fantastic element that explains the appeal of games to |
97
|
|
|
|
|
|
|
many developers is neither the fire-breathing monsters nor the |
98
|
|
|
|
|
|
|
milky-skinned, semi-clad sirens; it is the experience of |
99
|
|
|
|
|
|
|
carrying out a task from start to finish without any change |
100
|
|
|
|
|
|
|
in the user requirements. |
101
|
|
|
|
|
|
|
|; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |