line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Mechanize::Firefox::Extended; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
63862
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
124
|
|
4
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
103
|
|
5
|
3
|
|
|
3
|
|
14
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
165
|
|
6
|
3
|
|
|
3
|
|
1537
|
use parent 'WWW::Mechanize::Firefox'; |
|
3
|
|
|
|
|
1043
|
|
|
3
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
311206
|
use Time::HiRes qw/usleep/; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
my $USLEEP_INTERVAL = 200000; # 200 milliseconds |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
WWW::Mechanize::Firefox::Extended - Adds handy functions to WWW::Mechanize::Firefox |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.03 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Module provides handy functions to check existence of selectors on a page and |
27
|
|
|
|
|
|
|
to wait for selectors to come into existence. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use WWW::Mechanize::Firefox::Extended; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $mech = WWW::Mechanize::Firefox::Extended->new(); |
32
|
|
|
|
|
|
|
$mech->get('https://www.example.com/'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$mech->hasAll('#username', '#password', '#Image1'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$mech->hasAny('.close-button', '.exit-button', '.out-button'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$mech->waitAll(5, '#slow-loading-element') |
39
|
|
|
|
|
|
|
or die "Expected element not found"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$mech->waitAny(5, '#slow-loading-element', '#another-element') |
42
|
|
|
|
|
|
|
or die "Expected element not found"; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 hasAll( $mech, @selectors ) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Returns true if all selectors exists. False otherwise. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
sub hasAll { |
52
|
0
|
|
|
0
|
1
|
|
my $m = shift; |
53
|
0
|
|
|
|
|
|
for (@_) { |
54
|
0
|
0
|
|
|
|
|
return 0 if scalar ($m->selector($_,all=>1)) == 0; # short-circuit |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 hasAny( $mech, @selectors ) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns true if any selector exists. False if none exists. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
sub hasAny { |
65
|
0
|
|
|
0
|
1
|
|
my $m = shift; |
66
|
0
|
|
|
|
|
|
for (@_) { |
67
|
0
|
0
|
|
|
|
|
return 1 if scalar ($m->selector($_,all=>1)) > 0; # short-circuit |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 waitAll( $mech, $max_wait_seconds, @selectors ) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Wait until all selectors are present or the wait times out. |
75
|
|
|
|
|
|
|
Returns true if all selectors found or false if none found |
76
|
|
|
|
|
|
|
within the timeout period. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Uses Time::HiRes |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub waitAll { |
82
|
0
|
|
|
0
|
1
|
|
my ($m, $timeout, @selectors) = @_; |
83
|
0
|
|
|
|
|
|
my ($slept, $max_sleep) = (0, $timeout * 1000000); # microseconds |
84
|
0
|
|
|
|
|
|
while ($slept < $max_sleep) { |
85
|
0
|
0
|
|
|
|
|
return 1 if (hasAll($m, @selectors)); |
86
|
0
|
|
|
|
|
|
usleep($USLEEP_INTERVAL); # sleep 200 milliseconds |
87
|
0
|
|
|
|
|
|
$slept += $USLEEP_INTERVAL; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 waitAny( $mech, $max_wait_seconds, @selectors ) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Wait until any selectors are present or the wait times out. |
95
|
|
|
|
|
|
|
Returns true if any selectors are or false if none found |
96
|
|
|
|
|
|
|
within the timeout period. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Uses Time::HiRes |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
sub waitAny { |
102
|
0
|
|
|
0
|
1
|
|
my ($m, $timeout, @selectors) = @_; |
103
|
0
|
|
|
|
|
|
my ($slept, $max_sleep) = (0, $timeout * 1000000); # microseconds |
104
|
0
|
|
|
|
|
|
while ($slept < $max_sleep) { |
105
|
0
|
0
|
|
|
|
|
return 1 if (hasAny($m, @selectors)); |
106
|
0
|
|
|
|
|
|
usleep($USLEEP_INTERVAL); # sleep 200 milliseconds |
107
|
0
|
|
|
|
|
|
$slept += $USLEEP_INTERVAL; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
return 0; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Hoe-Kit Chew, C<< >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 BUGS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
121
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
122
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SUPPORT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
perldoc WWW::Mechanize::Firefox::Extended |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can also look for information at: |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * CPAN Ratings |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * Search CPAN |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 REPOSITORY AND PULL REQUESTS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This module is available on GitHub at |
156
|
|
|
|
|
|
|
L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Pull requests welcomed. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2015 Hoe-Kit Chew. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
165
|
|
|
|
|
|
|
under the same terms as Perl itself, either Perl version 5.10.0 or, at |
166
|
|
|
|
|
|
|
your option, any later version of Perl 5 you may have available. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; # End of WWW::Mechanize::Firefox::Extended |