line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Brownie::Driver::Mechanize; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
1635752
|
use strict; |
|
19
|
|
|
|
|
44
|
|
|
19
|
|
|
|
|
1010
|
|
4
|
19
|
|
|
19
|
|
206
|
use warnings; |
|
19
|
|
|
|
|
39
|
|
|
19
|
|
|
|
|
645
|
|
5
|
19
|
|
|
19
|
|
14043
|
use parent 'Brownie::Driver'; |
|
19
|
|
|
|
|
1474
|
|
|
19
|
|
|
|
|
164
|
|
6
|
19
|
|
|
19
|
|
30181
|
use WWW::Mechanize; |
|
19
|
|
|
|
|
3470048
|
|
|
19
|
|
|
|
|
887
|
|
7
|
19
|
|
|
19
|
|
22492
|
use HTML::TreeBuilder::XPath; |
|
19
|
|
|
|
|
1484204
|
|
|
19
|
|
|
|
|
274
|
|
8
|
19
|
|
|
19
|
|
1118
|
use constant HAS_LIBXML => eval { require HTML::TreeBuilder::LibXML; 1 }; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
44
|
|
|
19
|
|
|
|
|
10112
|
|
|
0
|
|
|
|
|
0
|
|
9
|
19
|
|
|
19
|
|
108
|
use Scalar::Util qw(blessed); |
|
19
|
|
|
|
|
39
|
|
|
19
|
|
|
|
|
1260
|
|
10
|
|
|
|
|
|
|
|
11
|
19
|
|
|
19
|
|
11961
|
use Brownie; |
|
19
|
|
|
|
|
59
|
|
|
19
|
|
|
|
|
697
|
|
12
|
19
|
|
|
19
|
|
124
|
use Brownie::XPath; |
|
19
|
|
|
|
|
38
|
|
|
19
|
|
|
|
|
370
|
|
13
|
19
|
|
|
19
|
|
13014
|
use Brownie::Node::Mechanize; |
|
19
|
|
|
|
|
56
|
|
|
19
|
|
|
|
|
14188
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $NodeClass = 'Brownie::Node::Mechanize'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub DESTROY { |
18
|
20
|
|
|
20
|
|
125790
|
my $self = shift; |
19
|
20
|
|
|
|
|
1634
|
delete $self->{browser}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub browser { |
23
|
478
|
|
|
478
|
1
|
3921
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
478
|
|
66
|
|
|
3602
|
$self->{browser} ||= WWW::Mechanize->new( |
26
|
|
|
|
|
|
|
agent => "Brownie/${Brownie::VERSION}", |
27
|
|
|
|
|
|
|
cookie_jar => +{}, |
28
|
|
|
|
|
|
|
quiet => 1, |
29
|
|
|
|
|
|
|
stack_depth => 1, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
478
|
|
|
|
|
380378
|
return $self->{browser}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub visit { |
36
|
89
|
|
|
89
|
1
|
485497
|
my ($self, $url) = @_; |
37
|
89
|
|
|
|
|
475
|
$self->browser->get("$url"); # stringify for URI |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub current_url { |
41
|
114
|
|
|
114
|
1
|
19572
|
my $self = shift; |
42
|
114
|
|
|
|
|
443
|
return $self->browser->uri->clone; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub current_path { |
46
|
46
|
|
|
46
|
1
|
17637
|
my $self = shift; |
47
|
46
|
|
|
|
|
607
|
return $self->current_url->path; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub status_code { |
51
|
4
|
|
|
4
|
1
|
62534
|
my $self = shift; |
52
|
4
|
|
|
|
|
22
|
return $self->browser->status; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub response_headers { |
56
|
1
|
|
|
1
|
1
|
1673
|
my $self = shift; |
57
|
1
|
|
|
|
|
42
|
return $self->browser->res->headers; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub title { |
61
|
1
|
|
|
1
|
1
|
66950
|
my $self = shift; |
62
|
1
|
|
|
|
|
5
|
return $self->browser->title; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub source { |
66
|
137
|
|
|
137
|
1
|
3080
|
my $self = shift; |
67
|
137
|
|
|
|
|
484
|
my $content = $self->browser->content; |
68
|
|
|
|
|
|
|
# TODO: consider gzip and deflate |
69
|
137
|
|
|
|
|
6580
|
return $content; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _root { |
73
|
133
|
|
|
133
|
|
223
|
my $self = shift; |
74
|
133
|
50
|
|
|
|
865
|
my $builder = HAS_LIBXML ? 'HTML::TreeBuilder::LibXML' : 'HTML::TreeBuilder::XPath'; |
75
|
133
|
|
|
|
|
480
|
my $tree = $builder->new_from_content($self->source); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub find { |
79
|
281
|
|
|
281
|
1
|
228109
|
my ($self, $locator, %args) = @_; |
80
|
|
|
|
|
|
|
|
81
|
281
|
|
|
|
|
1107
|
my @elements = $self->all($locator, %args); |
82
|
281
|
50
|
|
|
|
3652
|
return @elements ? shift(@elements) : undef; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub all { |
86
|
287
|
|
|
287
|
1
|
669
|
my ($self, $locator, %args) = @_; |
87
|
|
|
|
|
|
|
|
88
|
287
|
|
|
|
|
567
|
my @elements = (); |
89
|
287
|
|
|
|
|
1377
|
my $xpath = Brownie::XPath::to_xpath($locator); |
90
|
|
|
|
|
|
|
|
91
|
287
|
100
|
|
|
|
3032
|
if (my $base = $args{base}) { |
92
|
154
|
50
|
33
|
|
|
2490
|
my $node = (blessed($base) and $base->can('native')) ? $base->native : $base; |
93
|
154
|
50
|
|
|
|
1023
|
$xpath = ".$xpath" unless $xpath =~ /^\./; |
94
|
154
|
|
|
|
|
693
|
@elements = $node->findnodes($xpath); # abs2rel |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
133
|
|
|
|
|
653
|
@elements = $self->_root->findnodes($xpath); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
287
|
100
|
|
|
|
8678767
|
return @elements ? map { $NodeClass->new(driver => $self, native => $_) } @elements : (); |
|
305
|
|
|
|
|
3179
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Brownie::Driver::Mechanize - WWW::Mechanize bridge implementation |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $driver = Brownie::Driver::Mechanize->new; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$driver->visit($url); |
114
|
|
|
|
|
|
|
my $title = $driver->title; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 IMPLEMENTED |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * C |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * C |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * C |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * C |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * C |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * C |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * C |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * C |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * C |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * C |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=back |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 NOT SUPPORTED |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * C |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * C |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * C |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
NAKAGAWA Masaki Emasaki@cpan.orgE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 LICENSE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
163
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L, L, L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |