line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::WWW::Mechanize::LibXML; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21451
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
20
|
use 5.008; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
50
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Test::WWW::Mechanize::LibXML - use HTML::TreeBuilder::LibXML for testing |
11
|
|
|
|
|
|
|
web-sites. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.0.4 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Test::WWW::Mechanize::LibXML; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $mech = Test::WWW::Mechanize::LibXML->new(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# TEST |
24
|
|
|
|
|
|
|
$mech->get_ok('http://www.shlomifish.org/'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# TEST |
27
|
|
|
|
|
|
|
$mech->tree_matches_xpath('//p', "There are paragraphs in the page."); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module inherits from L, and allows one to utilize |
32
|
|
|
|
|
|
|
L to perform XPath and L |
33
|
|
|
|
|
|
|
queries on the tree. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $VERSION = '0.0.4'; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
5
|
use base 'Test::WWW::Mechanize'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1095
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
247497
|
use HTML::TreeBuilder::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use MRO::Compat; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Test::More; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 $mech->libxml_tree() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns the L tree of the current page. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub libxml_tree |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if (@_) |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
$self->{libxml_tree} = shift; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return $self->{libxml_tree}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _update_page |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $ret = $self->maybe::next::method(@_); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $tree = HTML::TreeBuilder::LibXML->new; |
74
|
|
|
|
|
|
|
$tree->parse($self->content()); |
75
|
|
|
|
|
|
|
$tree->eof(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->libxml_tree($tree); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return $ret; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 my $tag = $mech->contains_tag($tag_spec, $blurb) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
See if the tree contains a tag using C< look_down(@$tag_spec) > and |
85
|
|
|
|
|
|
|
returns it. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub contains_tag |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $mech = shift; |
94
|
|
|
|
|
|
|
my $tag_spec = shift; |
95
|
|
|
|
|
|
|
my $blurb = shift; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $ret = $mech->libxml_tree->look_down(@$tag_spec); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
ok($ret, $blurb); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return $ret; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 $mech->tree_matches_xpath($xpath, $blurb) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Determines whether the tree matches the XPath expression $xpath and returns |
107
|
|
|
|
|
|
|
it. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub tree_matches_xpath |
112
|
|
|
|
|
|
|
{ |
113
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $mech = shift; |
116
|
|
|
|
|
|
|
my $xpath = shift; |
117
|
|
|
|
|
|
|
my $blurb = shift; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my @nodes = $mech->libxml_tree->findnodes($xpath); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return ok(scalar(@nodes), $blurb); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Shlomi Fish, C<< >> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 BUGS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
131
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
132
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SUPPORT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
perldoc Test::WWW::Mechanize::LibXML |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can also look for information at: |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * CPAN Ratings |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * Search CPAN |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Thanks to Insurgent Software for sponsoring this work. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 TODO |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
At the moment, there's a very minimal number of methods here. More should |
169
|
|
|
|
|
|
|
be added as needed. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright 2010 Shlomi Fish. (C, |
174
|
|
|
|
|
|
|
L ) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is distributed under the MIT (X11) License: |
177
|
|
|
|
|
|
|
L |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person |
180
|
|
|
|
|
|
|
obtaining a copy of this software and associated documentation |
181
|
|
|
|
|
|
|
files (the "Software"), to deal in the Software without |
182
|
|
|
|
|
|
|
restriction, including without limitation the rights to use, |
183
|
|
|
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
184
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the |
185
|
|
|
|
|
|
|
Software is furnished to do so, subject to the following |
186
|
|
|
|
|
|
|
conditions: |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be |
189
|
|
|
|
|
|
|
included in all copies or substantial portions of the Software. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
192
|
|
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
193
|
|
|
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
194
|
|
|
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
195
|
|
|
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
196
|
|
|
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
197
|
|
|
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
198
|
|
|
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; # End of Test::WWW::Mechanize::LibXML |