Scripter.pm

filter: Statementstmt 22.0% 212 / 960 Branchbran 2.2% 10 / 450 Conditioncond 0.4% 1 / 210 MC/DCmcdc 0.0% 0 / 122 Subroutinesub 24.8% 49 / 197 Podpod 98.3% 58 / 59 totaltotal 16.5% 330 / 1998 SCAR 111.0
CC
320
Cov
14%
find_target
415.3
request
306.0
__ANON__
240.0
CRAP 65986.5
↑ Summary Scripter/WindowGroup.pm »
1 26 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package WWW::Scripter;
4  
5 26 our $VERSION = '0.030';
6  
7 26 ▶use strict; use warnings; no warnings qw 'utf8 parenthesis bareword';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 26 ▶use CSS'DOM'Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 26 ▶use Encode qw'encode decode';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 26 ▶use HTML::DOM 0.045; # weaken_response
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 ▶use HTML::DOM::EventTarget 0.053; # DOMAttrModified with correct type and
Subroutine BEGIN: called CC=1 SCAR=0.0
14 26 ▶use HTML::DOM::Interface 0.019 ':all'; # cancellability
Subroutine BEGIN: called CC=1 SCAR=0.0
15 26 ▶use HTML::DOM::View 0.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 26 ▶use HTTP::Headers::Util 'split_header_words';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 26 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 26 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 26 ▶use Scalar::Util 1.09 qw 'blessed weaken reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 26 ▶use List'Util 'sum';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 26 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 26 ▶use Time::HiRes 'time';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 BEGIN {
24 26 ▶ require constant;
Subroutine BEGIN: called CC=2 SCAR=7.0
25 26 require WWW::Mechanize;
26 26 ▶ VERSION WWW::Mechanize $LWP::UserAgent::VERSION >= 5.815 ? 1.52 : 1.2;
Branch: 1 branch
BranchTrueFalseTotal
$LWP::UserAgent::VERSION >= 5.815 ? : 26 0 26
27 # Version 1.52 is necessary for LWP 5.815 compatibility. Version 1.2 is
28 # needed otherwise for its handling of cookie jars during cloning.
29 26 import constant Mech => 'WWW::Mechanize';
30 }
31  
32 BEGIN {
33 26 ▶ if(eval { require Hash::Util::FieldHash }) {
Subroutine BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Hash::Util::FieldHash } }) { } 26 0 26
34 26 import Hash::Util::FieldHash qw < fieldhash fieldhashes >;
35 } else {
36 0 require Tie::RefHash::Weak;
37 0 VERSION Tie::RefHash::Weak 0.08; # fieldhash
38 0 import Tie::RefHash::Weak qw < fieldhash fieldhashes >;
39 }
40 }
41  
42 26 our @ISA = (Mech, qw( HTML::DOM::View HTML::DOM::EventTarget ));
43  
44 26 ▶eval <<'' unless exists &UNIVERSAL'DOES;
Branch: 1 branch
BranchTrueFalseTotal
unless exists &UNIVERSAL::DOES 0 26 26
45 sub DOES {
46 goto &{$_[0]->can("SUPER::DOES")||$_[0]->can("isa")}
47 }
48  
49 26 our @EXPORT_OK = qw/abort/;
50 26 our %EXPORT_TAGS = (
51 all => \@EXPORT_OK,
52 );
53  
54 # Fields that we don’t want fiddled with when the page stack is
55 # manipulated:
56 26 fieldhashes \my( %scriptable, %script_handlers, %scrn,
57 %class_info, %navi );
58 # ~~~ Actually, most of these can be eliminated, since we can store them
59 # directly in the object, as we are not doing that cloning that Mech
60 # used to do between pages.
61  
62 # Fields keyed by document:
63 26 fieldhashes \my( %timeouts, %timers, %frames, %evtg, %status, %dstatus );
64  
65 26 fieldhash my %document; # keyed by response — we actually use
66 # HTML::DOM::View’s storage for the current doc,
67 # but this field hash is necessary when we return
68 # to a page.
69  
70 # These are used to create a link between a WWW::Mechanize::(Image|Link)
71 # object and the DOM equivalent.
72 26 fieldhash my %dom_obj;
73  
74 # ------------- Mech overrides (or does it?) ------------- #
75  
76 sub new {
77 26 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=12.8
Pod documented
78 26 my %args = @_;
79 exists $args{max_docs}
80 26 ▶ and $args{stack_depth} = -1+delete$args{max_docs};
Branch: 1 branch
BranchTrueFalseTotal
exists $args{"max_docs"} and $args{"stack_depth"} = -1 + delete $args{"max_docs"} 0 26 26
81 26 my $max_history = delete $args{max_history};
82  
83 26 my $self = $class->SUPER::new(%args);
84  
85 26 $$self{Scripter_max_hist} = $max_history;
86 26 $script_handlers{$self} = {};
87 26 $scriptable{$self} = 1;
88  
89 26 $self->{page_stack} = WWW'Scripter'History->new( $self );
90  
91 26 weaken(my $self_fc = $self); # for closures
92 $class_info{$self} = [
93 \(%HTML::DOM'Interface, %CSS'DOM'Interface, our%Interface), {
94 'WWW::Scripter::Image' => "Image",
95 Image => {
96 _constructor => sub {
97 0 ▶ my $i = $self_fc->document->createElement('img');
Subroutine __ANON__: not called CC=3 SCAR=24.8
98 0 ▶ @_ and $i->attr('width',shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $i->attr("width", shift()) 0 0 0
99 0 ▶ @_ and $i->attr('height',shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $i->attr("height", shift()) 0 0 0
100 0 $i
101 }
102 },
103 }
104 26 ];
105  
106 26 ▶ unless(exists $args{agent}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"agent"}) 26 0 26
107 26 $self->agent("WWW::Scripter/$VERSION");
108 }
109  
110 # I would like to avoid doing this when it is not necessary, but
111 # the alternative would require overriding HTML::DOM::View’s
112 # document method, and that might slow things down more, since
113 # document is called more often than new Scripter objects
114 # are created.
115 26 _initial_page($self);
116  
117 0 $self;
118 }
119  
120 sub _initial_page {
121 26 ▶ my $req = new HTTP::Request 'GET', 'about:blank';
Subroutine _initial_page: called CC=1 SCAR=0.0
122 26 my $res = new HTTP::Response 200, OK => [
123 'content-length' => 0,
124 'content-type' => 'text/html',
125 ], '';
126 26 $res->request($req);
127 shift->_update_page(
128 26 $req, $res
129 );
130 }
131  
132 sub clone {
133 0 ▶ my $clone = (my $self = shift)->SUPER::clone(@_);
Subroutine clone: not called CC=2 SCAR=17.9
Pod documented
134 0 $$_{$clone}=$$_{$self} for \(
135 %scriptable,%script_handlers
136 );
137 0 $class_info{$clone} = [@{$class_info{$self}}];
138 0 $clone->{handlers} = $self->{handlers};
139 0 $clone->{page_stack} = WWW'Scripter'History->new($clone);
140 0 delete @$clone{<Scripter_loc Scripter_nm>};
141 0 $clone->_clone_plugins;
142 0 $clone;
143 }
144  
145 0 ▶sub title { (shift->document||return)->title(@_) }
Subroutine title: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
(shift())->document || (return)
l!l
00
MC/DC0%0/1
(shift())->document || (return)
(shift())->document
Truth table0%0/2
A
A= (shift())->document
Aresult
11
00
146  
147 sub content {
148 0 ▶ my $self = shift;
Subroutine content: not called CC=7 SCAR=40.3
Pod documented
149 0 ▶ if($self->is_html && $self->document) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_html and $self->document) 0 0 0
Condition0%0/3
$self->is_html and $self->document
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_html and $self->document
$self->is_html $self->document
Truth table0%0/3
A and B
A= $self->is_htmlB= $self->document
ABresult
0X0
100
111
150 0 my %parms = @_;
151 0 my $cs = (my $doc = $self->document)->charset;;
152 0 ▶ if(exists $parms{format} && $parms{format} eq 'text') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parms{"format"} and $parms{"format"} eq "text") 0 0 0
Condition0%0/3
exists $parms{"format"} and $parms{"format"} eq "text"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $parms{"format"} and $parms{"format"} eq "text"
exists $parms{"format"} $parms{"format"} eq "text"
Truth table0%0/3
A and B
A= exists $parms{"format"}B= $parms{"format"} eq "text"
ABresult
0X0
100
111
153 0 my $text = $doc->documentElement->as_text;
154 0 ▶ return defined $cs ? encode $cs, $text : $text;
Branch: 1 branch
BranchTrueFalseTotal
defined $cs ? : 0 0 0
155 }
156 0 my $content = $doc->innerHTML;
157 0 ▶ $content = encode $cs, $content if defined $cs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cs 0 0 0
158 0 $self->{content} = $content; # banana
159 }
160 0 $self->SUPER::content(@_);
161 }
162  
163 #sub discontent { ... }
164  
165 # Some parts of this were taken straight from WWW::Mechanize.
166 sub follow_link {
167 26 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
168 0 ▶ my $self = shift;
Subroutine follow_link: not called CC=7 SCAR=40.3
Pod documented
169 0 my %parms = ( n=>1, @_ );
170  
171 0 ▶ if ( $parms{n} eq 'all' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parms{"n"} eq "all") 0 0 0
172 0 delete $parms{n};
173 0 $self->warn( q{follow_link(n=>"all") is not valid} );
174 }
175  
176 0 my $link = $self->find_link(%parms);
177 0 ▶ if($link and tag $link =~ '^a') {
Branch: 1 branch
BranchTrueFalseTotal
if ($link and $link->tag =~ /^a/) { } 0 0 0
Condition0%0/3
$link and $link->tag =~ /^a/
!ll&&!rl&&r
000
MC/DC0%0/2
$link and $link->tag =~ /^a/
$link $link->tag =~ /^a/
Truth table0%0/3
A and B
A= $linkB= $link->tag =~ /^a/
ABresult
0X0
100
111
178 0 my $follow;
179 0 my $dom_link = $dom_obj{$link};
180 $dom_link->trigger_event('click',
181 # We used to have simply DOMActivate_default => ...
182 # but that did absolutely nothing, since the
183 # *_default arguments apply solely to the current
184 # event (which is a click event). So we have
185 # to override HTML::DOM::Element’s click_default
186 # to trigger the DOMActivate event with the
187 # DOMActivate_default argument. And, no, some sort
188 # of localisation mechanism would not do instead,
189 # because event handlers could click other links
190 # (or even this one again), which events should
191 # remain unaffected by this *_default override.
192 # ~~~ Or should they???
193 click_default => sub {
194 $dom_link->trigger_event('DOMActivate',
195 0 ▶ DOMActivate_default => sub { ++$follow }
Subroutine __ANON__: not called CC=1 SCAR=6.9
196 )
197 0 ▶ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
198 0 );
199 0 ▶ return unless $follow;
Branch: 1 branch
BranchTrueFalseTotal
unless $follow 0 0 0
200 0 ▶ return ($self->find_target($dom_link->target)||$self)
Condition0%0/3
$self->find_target($dom_link->target) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->find_target($dom_link->target) || $self
$self->find_target($dom_link->target) $self
Truth table0%0/3
A || B
A= $self->find_target($dom_link->target)B= $self
ABresult
1X1
011
000
201 ->get($link->url);
202 }
203 else {
204 $self->die(
205 'Link not found: ',
206 join ", ", map "$_ => '$parms{$_}'", sort keys %parms
207 )
208 0 ▶ if $self->{autocheck};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"autocheck"} 0 0 0
209 }
210 Scripter_plit:
211 }
212  
213  
214 sub request {
215 0 ▶ for (my $foo) { # protect against tied $_
Subroutine request: not called CC=17 SCAR=57.2
Pod documented
216 0 my $self = shift;
217 0 ▶ return unless defined(my $request = shift);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $request = shift()) 0 0 0
218  
219 0 $request = $self->_modify_request( $request );
220  
221 0 my $meth = $request->method;
222 0 my $orig_uri = $request->uri;
223 0 my $new_uri;
224 0 ▶ if ((my $path = $orig_uri->path) =~ s-^(/*)/\.\./-$1||'/'-e) {
Branch: 2 branches
BranchTrueFalseTotal
if ((my $path = $orig_uri->path) =~ s[^(/*)/\.\./][$1 or "/";]e) 0 0 0
$1 or "/" 0 0 0
225 0 ▶ 0while $path =~ s\\$1||'/'\e;
Branch: 2 branches
BranchTrueFalseTotal
$path =~ s[][$1 or "/";]e and do { '???' } 0 0 0
$1 or "/" 0 0 0
226 0 ($new_uri = $orig_uri->clone)->path($path)
227 }
228 0 my $skip_fetch;
229 0 ▶ if(defined($orig_uri->fragment)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $orig_uri->fragment) 0 0 0
230 0 ▶ ($new_uri ||= $orig_uri->clone)->fragment(undef);
Condition0%0/3
$new_uri ||= $orig_uri->clone
l!l&&r!l&&!r
000
MC/DC0%0/2
$new_uri ||= $orig_uri->clone
$new_uri $orig_uri->clone
Truth table0%0/3
A ||= B
A= $new_uriB= $orig_uri->clone
ABresult
1X1
011
000
231  
232 # Skip fetching the URL if it is the same (and there is a fragment).
233 # We don’t need to strip the fragment from $self->uri before compari-
234 # son as that always contains the actual URL sent in the request.
235 0 ▶ $meth eq "GET" and $new_uri->eq($self->uri) and ++$skip_fetch;
Branch: 1 branch
BranchTrueFalseTotal
$meth eq "GET" and $new_uri->eq($self->uri) and ++$skip_fetch 0 0 0
Condition0%0/3
$meth eq "GET" and $new_uri->eq($self->uri)
!ll&&!rl&&r
000
MC/DC0%0/2
$meth eq "GET" and $new_uri->eq($self->uri)
$meth eq "GET" $new_uri->eq($self->uri)
Truth table0%0/3
A and B
A= $meth eq "GET"B= $new_uri->eq($self->uri)
ABresult
0X0
100
111
236 }
237 0 ▶ if ($new_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_uri) 0 0 0
238 0 $request->uri($new_uri);
239 }
240  
241 0 my $response;
242  
243 0 ▶ if($skip_fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_fetch) { } 0 0 0
244 0 $response = $self->response;
245 }
246 else {
247 Scripter_REQUEST: {
248 0 Scripter_ABORT: {
249 0 $response = $self->_make_request( $request, @_ );
250 0 last Scripter_REQUEST;
251 }
252 0 return 1
253 }
254 }
255  
256 0 ▶ if ( $meth eq 'GET' || $meth eq 'POST' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meth eq "GET" or $meth eq "POST") 0 0 0
Condition0%0/3
$meth eq "GET" or $meth eq "POST"
l!l&&r!l&&!r
000
MC/DC0%0/2
$meth eq "GET" or $meth eq "POST"
$meth eq "GET" $meth eq "POST"
Truth table0%0/3
A or B
A= $meth eq "GET"B= $meth eq "POST"
ABresult
1X1
011
000
257 $self->get_event_listeners('unload') and
258 $self->trigger_event('unload'),
259 0 ▶ $self->{page_stack}->_delete_res;
Branch: 1 branch
BranchTrueFalseTotal
$self->get_event_listeners("unload") and $self->trigger_event("unload"), $self->{"page_stack"}->_delete_res 0 0 0
260  
261 0 $self->{page_stack}->${\(
262 0 ▶ $self->{Scripter_replace} ? '_replace' : '_add'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Scripter_replace'} ? : 0 0 0
263 )}($request, $response, $orig_uri);
264 }
265  
266 0 return $self->_update_page($request, $response);
267 }
268 }
269  
270 # Protect against tied $_
271 0 ▶sub get { return SUPER::get{@_} for my $foo }
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
272 0 ▶sub put { return SUPER::put{@_} for my $foo }
Subroutine put: not called CC=2 SCAR=17.9
Pod documented
273 0 ▶sub post { return SUPER::post{@_} for my $foo }
Subroutine post: not called CC=2 SCAR=17.9
Pod documented
274 0 ▶sub head { return SUPER::head{@_} for my $foo }
Subroutine head: not called CC=2 SCAR=17.9
Pod documented
275  
276  
277 # The only difference between this one and Mech is the args to
278 # decoded_content. I.e., this is the way Mech *used* to work.
279 sub _update_page {
280 26 ▶ my ($self, $request, $res) = @_;
Subroutine _update_page: called CC=9 SCAR=29.5
281  
282 26 $self->{req} = $request;
283 26 $self->{redirected_uri} = $request->uri->as_string;
284  
285 26 $self->{res} = $res;
286  
287 26 $self->{status} = $res->code;
288 26 $self->{base} = $res->base;
289 26 ▶ $self->{ct} = $res->content_type || '';
Condition50%1/2
$res->content_type || ''
l!l
260
MC/DC0%0/1
$res->content_type || ''
$res->content_type
Truth table50%1/2
A
A= $res->content_type
Aresult
11
00
290  
291 26 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 26 0 26
292 26 $self->{uri} = $self->{redirected_uri};
293 26 $self->{last_uri} = $self->{uri};
294 }
295  
296 26 ▶ if ( $res->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_error) 0 26 26
297 0 ▶ if ( $self->{autocheck} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"autocheck"}) 0 0 0
298 0 $self->die( 'Error ', $request->method, 'ing ', $request->uri, ': ', $res->message );
299 }
300 }
301  
302 26 $self->_reset_page;
303  
304 # Try to decode the content. Undef will be returned if there's nothing to decompress.
305 # See docs in HTTP::Message for details. Do we need to expose the options there?
306 26 my $content = $res->decoded_content(charset => "none");
307 26 ▶ $content = $res->content if (not defined $content);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 26 26
308  
309 26 $content .= &{\&{Mech."::_taintedness"}};
310  
311 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($self->{'Scripter_dumb'}) || $self->{'Scripter_dumb'} and $self->is_html) { } 0 0 0
Condition0%0/6
!defined($self->{"Scripter_dumb"}) || $self->{"Scripter_dumb"} and $self->is_html
!ll&&!rl&&r
000
not defined $self->{"Scripter_dumb"} or $self->{"Scripter_dumb"}
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($self->{"Scripter_dumb"}) || $self->{"Scripter_dumb"} and $self->is_html
not defined $self->{"Scripter_dumb"} $self->{"Scripter_dumb"} $self->is_html
Truth table0%0/5
not(A) or B and C
A= not defined $self->{"Scripter_dumb"}B= $self->{"Scripter_dumb"}C= $self->is_html
ABCresult
00X0
1X00
0100
1X11
0111
312 !defined $$self{Scripter_dumb} || $$self{Scripter_dumb}
313 and $self->is_html
314 ) {
315 0 $res = $self->update_html($content);
316 }
317 else {
318 0 $self->{content} = $content;
319 0 $self->document(undef);
320 }
321  
322 0 return $res;
323 } # _update_page
324  
325 sub _fetch_url {
326 0 ▶ my ($self) = @'_;
Subroutine _fetch_url: not called CC=3 SCAR=24.8
327 my $fetcher = $self->{Scripter_f}
328 0 ▶ ||= do {
Condition0%0/3
$self->{"Scripter_f"} ||= do { (my $clone = $self->clone->clear_history(1))->dom_enabled(0); $clone->max_history(1); $clone }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Scripter_f"} ||= do { (my $clone = $self->clone->clear_history(1))->dom_enabled(0); $clone->max_history(1); $clone }
$self->{"Scripter_f"} do { (my $clone = $self->clone->clear_history(1))->dom_enabled(0); $clone->max_history(1); $clone }
Truth table0%0/3
A ||= B
A= $self->{"Scripter_f"}B= do { (my $clone = $self->clone->clear_history(1))->dom_enabled(0); $clone->max_history(1); $clone }
ABresult
1X1
011
000
329 (
330 0 my $clone = $self->clone->clear_history(1)
331 )->dom_enabled(0);
332 0 $clone->max_history(1);
333 0 $clone;
334 };
335 0 $fetcher->{last_uri} = $self->{uri};
336 0 require URI;
337 0 my $base = $self->base;
338 0 ▶ $_[1] = URI->new_abs( $_[1], $base )
Branch: 1 branch
BranchTrueFalseTotal
if $base 0 0 0
339 if $base;
340 0 $fetcher->get($_[1]);
341 }
342  
343 sub update_html {
344 0 ▶ my ($self,$src) = @_;
Subroutine update_html: not called CC=11 SCAR=48.4
Pod documented
345  
346 # Restore an existing document (in case we are coming back from
347 # another page).
348 0 my $res = $self->{res};
349 0 ▶ if(my $doc = $document{$res}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $document{$res}) 0 0 0
350 0 $self->document($doc);
351 0 $self->{form} = ($self->{forms} = $doc->forms)->[0];
352 0 return $res;
353 }
354  
355 0 my $life_raft = $self;
356 0 weaken($self);
357  
358 0 $self->document($document{$res} = my $tree = new HTML::DOM
359 response => $res,
360 weaken_response => 1,
361 cookie_jar => $self->cookie_jar);
362  
363 0 ▶ $tree->error_handler(sub{$self->warn($@)});
Subroutine __ANON__: not called CC=1 SCAR=6.9
364  
365 $tree->default_event_handler_for( link => sub {
366 0 ▶ my $link = shift->target;
Subroutine __ANON__: not called CC=2 SCAR=17.9
367 0 ▶ ($self->find_target($link->target)||$self)
Condition0%0/3
$self->find_target($link->target) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->find_target($link->target) || $self
$self->find_target($link->target) $self
Truth table0%0/3
A || B
A= $self->find_target($link->target)B= $self
ABresult
1X1
011
000
368 ->get($link->href)
369 0 });
370 $tree->default_event_handler_for( submit => sub {
371 0 ▶ my $form = shift->target;
Subroutine __ANON__: not called CC=2 SCAR=17.9
372 0 ▶ ($self->find_target($form->target)||$self)
Condition0%0/3
$self->find_target($form->target) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->find_target($form->target) || $self
$self->find_target($form->target) $self
Truth table0%0/3
A || B
A= $self->find_target($form->target)B= $self
ABresult
1X1
011
000
373 ->request($form->make_request);
374 0 });
375  
376 0 ▶ if(%{$script_handlers{$self}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$script_handlers{$self};}) 0 0 0
377 0 my $script_type = $res->header(
378 'Content-Script-Type');
379 defined $script_type or $tree->elem_handler(meta =>
380 sub {
381 0 ▶ my($tree, $elem) = @_;
Subroutine __ANON__: not called CC=2 SCAR=10.9
382 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
383 0 ▶ return unless lc $elem->attr('http-equiv')
Branch: 1 branch
BranchTrueFalseTotal
unless lc $elem->attr("http-equiv") eq "content-script-type" 0 0 0
384 eq 'content-script-type';
385 0 $script_type = $elem->attr('content');
386 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $script_type or $tree->elem_handler("meta", sub { my($tree, $elem) = @_; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x45\x54\x55\x51\x54\x01\x55\x55\x55\x55\x55\x55\x55\x55\x55"} return unless lc $elem->attr("http-equiv") eq "content-script-type"; $script_type = $elem->attr("content"); } ) 0 0 0
387  
388 $tree->elem_handler(script => sub {
389 0 ▶ return unless $scriptable{$self};
Subroutine __ANON__: not called CC=15 SCAR=54.8
Branch: 1 branch
BranchTrueFalseTotal
unless $scriptable{$self} 0 0 0
390 0 my($tree, $elem) = @_;
391  
392 0 my $lang = $elem->attr('type');
393 0 ▶ defined $lang
Branch: 1 branch
BranchTrueFalseTotal
defined $lang or $lang = $elem->attr("language") 0 0 0
394 or $lang = $elem->attr('language');
395 0 ▶ defined $lang or $lang = $script_type;
Branch: 1 branch
BranchTrueFalseTotal
defined $lang or $lang = $script_type 0 0 0
396  
397 0 my $uri;
398 0 my($inline, $code, $line) = 0;
399 0 ▶ if($uri = $elem->attr('src')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri = $elem->attr('src')) { } 0 0 0
400 0 my $res = _fetch_url($self, $uri);
401 0 ▶ $res->is_success or do {
Branch: 1 branch
BranchTrueFalseTotal
$res->is_success or do { my $url = $self->uri; my $offset = $elem->content_offset; if (not defined $offset) { $url .= ' (generated HTML)'; } else { $url .= ' line ' . _line_no($src, $offset); } ; $self->warn("couldn't get script ${uri}: " . $res->status_line . " at $url"), return } 0 0 0
402 0 my $url = $self->uri;
403 0 my $offset = $elem->content_offset;
404 0 ▶ if (!defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $offset) { } 0 0 0
405 0 $url .= ' (generated HTML)';
406 }
407 else {
408 0 $url .= ' line '
409 . _line_no($src,$offset);
410 }
411 0 $self->warn("couldn't get script $uri: "
412 . $res->status_line . " at $url"
413 ),
414 return;
415 };
416  
417 # Find out the encoding:
418 my $cs = {
419 map @$_,
420 split_header_words $res->header(
421 'Content-Type'
422 )
423 0 }->{charset};
424  
425 0 ▶ $code = decode $cs||$elem->charset
Condition0%0/8
$cs || $elem->charset || $tree->charset || 'latin1'
l!l
00
$cs or $elem->charset or $tree->charset
l!l&&r!l&&!r
000
$cs or $elem->charset
l!l&&r!l&&!r
000
MC/DC0%0/3
$cs || $elem->charset || $tree->charset || 'latin1'
$cs $elem->charset $tree->charset
Truth table0%0/4
A or B or C
A= $csB= $elem->charsetC= $tree->charset
ABCresult
1XX1
01X1
0011
0000
426 ||$tree->charset||'latin1',
427 $res->decoded_content(charset=>'none');
428
429
430 0 $line = 1;
431 }
432 else {
433 0 ▶ $code = ($elem->firstChild||return)->data;
Condition0%0/2
$elem->firstChild || (return)
l!l
00
MC/DC0%0/1
$elem->firstChild || (return)
$elem->firstChild
Truth table0%0/2
A
A= $elem->firstChild
Aresult
11
00
434 0 ++$inline;
435 0 $uri = $self->uri;
436 0 ▶ if(defined(
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $offset = $elem->content_offset)) { } 0 0 0
437 my $offset = $elem->content_offset
438 )) {
439 0 $line = _line_no(
440 $src,$elem->content_offset
441 );
442 }
443 0 else { $uri .= " (generated HTML)" }
444 };
445 0 ▶ length $code or return; # optimisation
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $code or return 0 0 0
446
447 0 my $h = $self->_handler_for_lang($lang);
448 0 ▶ $h && $h->eval($self, $code,
Branch: 1 branch
BranchTrueFalseTotal
$h and $h->eval($self, $code, $uri, $line, $inline) 0 0 0
449 $uri, $line, $inline);
450 0 ▶ $@ and $self->warn($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ and $self->warn($@) 0 0 0
451 0 });
452  
453 $tree->elem_handler(noscript => sub {
454 0 ▶ return unless $scriptable{$self};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $scriptable{$self} 0 0 0
455 0 $_[1]->detach#->delete;
456 # ~~~ delete currently stops it from work-
457 # ing; I need to looook into this.
458 0 });
459  
460 $tree->event_attr_handler(sub {
461 0 ▶ return unless $scriptable{$self};
Subroutine __ANON__: not called CC=6 SCAR=37.4
Branch: 1 branch
BranchTrueFalseTotal
unless $scriptable{$self} 0 0 0
462 0 my($elem, $event, $code, $offset) = @_;
463 0 my $lang = $elem->attr('language');
464 0 ▶ defined $lang or $lang = $script_type;
Branch: 1 branch
BranchTrueFalseTotal
defined $lang or $lang = $script_type 0 0 0
465  
466 0 my $uri = $self->uri;
467 0 ▶ my $line = defined $offset ? _line_no(
Branch: 1 branch
BranchTrueFalseTotal
defined $offset ? : 0 0 0
468 $src, $offset
469 ) : undef;
470  
471 0 local *@;
472 0 ▶ if(my $h = $self->_handler_for_lang($lang))
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $self->_handler_for_lang($lang)) 0 0 0
473 {
474 0 my $ret = $h->event2sub(
475 $self,$elem,$event,$code,$uri,$line
476 );
477 0 ▶ $@ and $self->warn($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ and $self->warn($@) 0 0 0
478 0 return $ret;
479 }
480 0 });
481 }
482  
483 $tree->elem_handler(noscript => sub {
484 0 ▶ return if $scriptable{$self} && %{$script_handlers{$self}};
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if $scriptable{$self} and %{$script_handlers{$self};} 0 0 0
Condition0%0/3
$scriptable{$self} and %{$script_handlers{$self};}
!ll&&!rl&&r
000
MC/DC0%0/2
$scriptable{$self} and %{$script_handlers{$self};}
$scriptable{$self} %{$script_handlers{$self};}
Truth table0%0/3
A and B
A= $scriptable{$self}B= %{$script_handlers{$self};}
ABresult
0X0
100
111
485 0 $_[1]->replace_with_content->delete;
486 # ~~~ why does this need delete?
487 0 });
488  
489 0 ▶ if($self->{Scripter_i}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Scripter_i"}) 0 0 0
490 $tree->elem_handler(img => my $img_cb = sub {
491 0 ▶ return unless defined (my $src = $_[1]->attr('src'));
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $src = $_[1]->attr("src")) 0 0 0
492 0 my $res = _fetch_url($self, $src);
493 defined $self->{Scripter_ih} &&
494 0 ▶ $self->{Scripter_ih}($self,$_[1],$res);
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"Scripter_ih"} and $self->{"Scripter_ih"}->($self, $_[1], $res) 0 0 0
495 0 });
496 $tree->elem_handler(input => sub {
497 0 ▶ return unless $_[1]->type eq 'image';
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->type eq "image" 0 0 0
498 0 goto &$img_cb;
499 0 });
500 $tree->default_event_handler(sub {
501 0 ▶ return unless (my $event = shift)->type eq 'DOMAttrModified';
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless (my $event = shift())->type eq "DOMAttrModified" 0 0 0
502 0 ▶ return unless (my $target = target $event)->tag=~/^i(mg|nput)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless (my $target = $event->target)->tag =~ /^i(mg|nput)\z/ 0 0 0
503 0 ▶ return if $1 eq 'nput' && $target->type ne 'image';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "nput" and $target->type ne "image" 0 0 0
Condition0%0/3
$1 eq "nput" and $target->type ne "image"
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq "nput" and $target->type ne "image"
$1 eq "nput" $target->type ne "image"
Truth table0%0/3
A and B
A= $1 eq "nput"B= $target->type ne "image"
ABresult
0X0
100
111
504 0 &$img_cb(undef, $target);
505 0 });
506 }
507  
508 $tree->defaultView(
509 0 $self
510 );
511 0 $tree->event_parent($self);
512 0 $tree->set_location_object($self->location);
513  
514 $tree->elem_handler(iframe => my $frame_handler = sub {
515 0 ▶ my ($doc,$elem) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
516 0 my $subwin = $self->clone->clear_history(1);
517 0 ▶ if(defined(my $name = attr $elem 'name')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $elem->attr("name"))) 0 0 0
518 0 name $subwin $name
519 }
520 0 $elem->contentWindow($subwin);
521 0 $subwin->_set_parent(my $parent = $doc->defaultView);
522 0 ▶ length(my $src = $elem->src) or return;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length(my $src = $elem->src) or return 0 0 0
523 0 $subwin->get(new_abs URI $src, $parent->base);
524 0 });
525 0 $tree->elem_handler(frame => $frame_handler);
526  
527 # Find out the encoding:
528 my $cs = {
529 map @$_,
530 split_header_words $res->header('Content-Type')
531 0 }->{charset};
532 0 ▶ $cs or $res->can('content_charset')
Branch: 2 branches
BranchTrueFalseTotal
$cs or $res->can("content_charset") and $cs = ($LWP::UserAgent::VERSION <= "5.834" && local *_, $res->content_charset) 0 0 0
$LWP::UserAgent::VERSION <= "5.834" and local *_ 0 0 0
Condition0%0/6
$cs || $res->can('content_charset') && ($cs = ($LWP::UserAgent::VERSION <= 5.834 && local *_, $res->content_charset))
l!l&&r!l&&!r
000
$res->can("content_charset") and $cs = ($LWP::UserAgent::VERSION <= "5.834" && local *_, $res->content_charset)
!ll&&!rl&&r
000
MC/DC0%0/3
$cs || $res->can('content_charset') && ($cs = ($LWP::UserAgent::VERSION <= 5.834 && local *_, $res->content_charset))
$cs $res->can("content_charset") $cs = ($LWP::UserAgent::VERSION <= "5.834" && local *_, $res->content_charset)
Truth table0%0/4
A || B and C
A= $csB= $res->can("content_charset")C= $cs = ($LWP::UserAgent::VERSION <= "5.834" && local *_, $res->content_charset)
ABCresult
1XX1
0111
00X0
0100
533 and $cs = (
534 $LWP::UserAgent::VERSION <= 5.834 && local *_,
535 $res->content_charset
536 );
537 0 ▶ $tree->charset($cs||'iso-8859-1');
Condition0%0/2
$cs || 'iso-8859-1'
l!l
00
MC/DC0%0/1
$cs || 'iso-8859-1'
$cs
Truth table0%0/2
A
A= $cs
Aresult
11
00
538  
539 # banana
540 0 $self->{form} = undef;
541 0 $self->{forms} = $tree->forms;
542  
543 0 ▶ $tree->write(defined $cs ? decode $cs, $src : $src);
Branch: 1 branch
BranchTrueFalseTotal
defined $cs ? : 0 0 0
544 0 $tree->close;
545  
546 # This used to trigger the load event on the body element (which
547 # conformed to HTML 5 at the time [10 June 2008 draft]), but which
548 # was not fully compatible with any existing browser. HTML 5
549 # changed to what Firefox and Safari did (some time before Septem-
550 # ber, 2009), which is what we now have here. (It still doesn’t
551 # quite make sense, as the document is not actually the target.)
552 0 $self->trigger_event('load', target => $tree);
553  
554 # banana
555 0 ▶ $self->{form} ||= $self->{forms}[0];
Condition0%0/3
$self->{"form"} ||= $self->{"forms"}[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"form"} ||= $self->{"forms"}[0]
$self->{"form"} $self->{"forms"}[0]
Truth table0%0/3
A ||= B
A= $self->{"form"}B= $self->{"forms"}[0]
ABresult
1X1
011
000
556  
557 0 return $self->{res};
558 }
559  
560 # Not an override, but used by update_html
561 sub _handler_for_lang {
562 0 ▶ my ($self,$lang) = @_;
Subroutine _handler_for_lang: not called CC=6 SCAR=37.4
563 0 ▶ if(defined $lang) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lang) 0 0 0
564 0 ▶ while(my($lang_re,$handler) = each
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$script_handlers{$self};}) 0 0 0
565 0 %{$script_handlers{$self}}) {
566 0 ▶ next if $lang_re eq 'default';
Branch: 1 branch
BranchTrueFalseTotal
if $lang_re eq "default" 0 0 0
567 $lang =~ $lang_re and
568 # reset iterator:
569 0 ▶ keys %{$script_handlers{$self}},
Branch: 1 branch
BranchTrueFalseTotal
$lang =~ /$lang_re/ and keys %{$script_handlers{$self};}, (return $handler) 0 0 0
570 return $handler;
571 }
572 }
573 0 ▶ return $script_handlers{$self}{default} || ();
Condition0%0/3
$script_handlers{$self}{'default'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$script_handlers{$self}{'default'} || ()
$script_handlers{$self}{'default'} ()
Truth table0%0/3
A || B
A= $script_handlers{$self}{'default'}B= ()
ABresult
1X1
011
000
574 }
575  
576 # Not an override, but used by update_html
577 sub _line_no {
578 0 ▶ my ($src,$offset) = @_;
Subroutine _line_no: not called CC=2 SCAR=17.9
579 0 ▶defined $offset or Carp::cluck;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or Carp::cluck() 0 0 0
580 0 return 1 + (() =
581 substr($src,0,$offset)
582 =~ /\cm\cj?|[\cj\x{2028}\x{2029}]/g
583 );
584 }
585  
586 26 my %link_tags = (
587 a => 'href',
588 area => 'href',
589 frame => 'src',
590 iframe => 'src',
591 link => 'href',
592 meta => 'content',
593 );
594  
595 # ~~~ This ends up creating a new WSL object every time we come back to the
596 # same page. We need a way to make this more efficient. The same goes
597 # for images.
598 sub _extract_links {
599 0 ▶ my $self = shift;
Subroutine _extract_links: not called CC=2 SCAR=15.6
600 0 my @links;
601 0 ▶ if (my $doc = $self->document) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $self->document) 0 0 0
602 tie @links, WWW'Scripter'Links:: =>
603 HTML::DOM::NodeList::Magic->new(
604 sub { grep {
605 0 ▶ my $tag = tag $_;
Subroutine __ANON__: not called CC=4 SCAR=25.6
606 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
607 exists $link_tags{$tag}
608 0 ▶ and defined $_->attr($link_tags{$tag})
Branch: 1 branch
BranchTrueFalseTotal
exists $link_tags{$tag} and defined $_->attr($link_tags{$tag}) and $tag ne "meta" || lc $_->attr("http-equiv") eq "refresh" 0 0 0
Condition0%0/9
exists $link_tags{$tag} && defined $_->attr($link_tags{$tag}) && ($tag ne 'meta' || lc $_->attr('http-equiv') eq 'refresh')
!ll&&!rl&&r
000
exists $link_tags{$tag} and defined $_->attr($link_tags{$tag})
!ll&&!rl&&r
000
$tag ne "meta" or lc $_->attr("http-equiv") eq "refresh"
l!l&&r!l&&!r
000
MC/DC0%0/4
exists $link_tags{$tag} && defined $_->attr($link_tags{$tag}) && ($tag ne 'meta' || lc $_->attr('http-equiv') eq 'refresh')
exists $link_tags{$tag} defined $_->attr($link_tags{$tag}) $tag ne "meta" lc $_->attr("http-equiv") eq "refresh"
Truth table0%0/5
A and B && C or D
A= exists $link_tags{$tag}B= defined $_->attr($link_tags{$tag})C= $tag ne "meta"D= lc $_->attr("http-equiv") eq "refresh"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
609 and $tag ne 'meta'
610 || lc $_->attr('http-equiv') eq 'refresh'
611 0 } $doc->descendants }, $doc
612 );
613 }
614 # banana
615 0 $self->{links} = \@links;
616 0 $self->{_extracted_links} = 1;
617  
618 0 return;
619 }
620  
621 sub _extract_images {
622 0 ▶ my $doc = (my $self= shift)->document;
Subroutine _extract_images: not called CC=1 SCAR=6.9
623 my $list = HTML::DOM::NodeList::Magic->new(
624 0 ▶ sub { grep tag $_ =~ /^i(?:mg|nput)\z/,
Subroutine __ANON__: not called CC=1 SCAR=6.9
625 $doc->descendants },
626 0 $doc
627 );
628 0 tie my @images, WWW'Scripter'Images:: => $list;
629  
630 # banana
631 0 $self->{images} = \@images;
632 0 $self->{_extracted_images} = 1;
633  
634 0 return;
635 }
636  
637 sub back {
638 0 ▶ shift->{page_stack}->go(-1)
Subroutine back: not called CC=1 SCAR=6.9
Pod documented
639 }
640  
641 sub submit {
642 0 ▶ if(defined wantarray) {
Subroutine submit: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
643 # We have to return the response object if a request was made, so we
644 # override the default event handler for this particular case.
645 0 my $go_for_it;
646 (my $form = $_[0]->current_form)->trigger_event(
647 'submit',
648 0 ▶ submit_default => sub { ++$go_for_it }
Subroutine __ANON__: not called CC=1 SCAR=6.9
649 0 );
650 0 ▶ $go_for_it
Branch: 1 branch
BranchTrueFalseTotal
$go_for_it ? : 0 0 0
Condition0%0/3
$_[0]->find_target($form->target) || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]->find_target($form->target) || $_[0]
$_[0]->find_target($form->target) $_[0]
Truth table0%0/3
A || B
A= $_[0]->find_target($form->target)B= $_[0]
ABresult
1X1
011
000
651 ? ($_[0]->find_target($form->target)||$_[0])
652 ->request($form->make_request)
653 : ()
654 }
655 else {
656 shift->current_form->submit
657 0 }
658 }
659  
660 sub base {
661 0 ▶ my $self = shift;
Subroutine base: not called CC=5 SCAR=34.0
Pod documented
662 0 ▶ my $base = ($self->document || return SUPER'base $self @_)->base;
Condition0%0/2
$self->document || (return $self->SUPER::base(@_))
l!l
00
MC/DC0%0/1
$self->document || (return $self->SUPER::base(@_))
$self->document
Truth table0%0/2
A
A= $self->document
Aresult
11
00
663 0 ▶ if($base eq 'about:blank' and (my $parent = $self->parent) != $self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base eq "about:blank" and (my $parent = $self->parent) != $self) 0 0 0
Condition0%0/3
$base eq "about:blank" and (my $parent = $self->parent) != $self
!ll&&!rl&&r
000
MC/DC0%0/2
$base eq "about:blank" and (my $parent = $self->parent) != $self
$base eq "about:blank" (my $parent = $self->parent) != $self
Truth table0%0/3
A and B
A= $base eq "about:blank"B= (my $parent = $self->parent) != $self
ABresult
0X0
100
111
664 0 return $parent->base;
665 }
666 0 ▶ length $base ? $base : undef;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $base ? : 0 0 0
667 }
668  
669 sub click { # This duplicates a lot of code from WWW::Mechanize::click,
670 # HTML::DOM::Element::Form::click and HTML::DOM::Ele-
671 # ment::Input, but I don’t see a way around it.
672 0 ▶ if(defined wantarray) {
Subroutine click: not called CC=13 SCAR=52.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
673 # We have to return the response object if a request was made, so we
674 # override the default event handler for this particular case.
675 0 my ($self, $button, $x, $y) = @_;
676  
677 # From HTML::DOM::Element::Form (ultimately from HTML::Form):
678 # try to find first submit button to activate
679 0 my $input;
680 0 my $form = $self->current_form;
681 0 for ($form->inputs) {
682 0 ▶ next unless $_->type =~ /^(?:submit|image)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->type =~ /^(?:submit|image)\z/ 0 0 0
683 0 ▶ next if $button && $_->name ne $button;
Branch: 1 branch
BranchTrueFalseTotal
if $button and $_->name ne $button 0 0 0
Condition0%0/3
$button and $_->name ne $button
!ll&&!rl&&r
000
MC/DC0%0/2
$button and $_->name ne $button
$button $_->name ne $button
Truth table0%0/3
A and B
A= $buttonB= $_->name ne $button
ABresult
0X0
100
111
684 0 ▶ next if $_->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $_->disabled 0 0 0
685 0 $input = $_;
686 0 last;
687 }
688 0 ▶ Carp::croak("No clickable input with name $button")
Branch: 1 branch
BranchTrueFalseTotal
if $button and not $input 0 0 0
Condition0%0/3
$button and not $input
!ll&&!rl&&r
000
MC/DC0%0/2
$button and not $input
$button not $input
Truth table0%0/3
A and not(B)
A= $buttonB= not $input
ABresult
0X0
100
111
689 if $button && !$input;
690  
691 # From HTML::DOM::Element::Input:
692 # We can’t put this in multiple statements, as the ‘local’ would go out
693 # of scope too soon.
694 0 my $continue;
695 $input and
696 # ~~~ We are breaking encapsulation here.
697 local($$input{_HTML_DOM_clicked}) = [$x,$y],
698 $input->trigger_event(
699 'click',
700 click_default => sub {
701 $input->trigger_event(
702 0 ▶ 'DOMActivate', DOMActivate_default => sub { ++$continue }
Subroutine __ANON__: not called CC=1 SCAR=6.9
703 )
704 0 ▶ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
705 0 ▶ ),
Branch: 1 branch
BranchTrueFalseTotal
$input and local(local $input->{"_HTML_DOM_clicked"}) = [$x, $y], $input->trigger_event("click", "click_default", sub { $input->trigger_event("DOMActivate", "DOMActivate_default", sub { ++$continue; } ); } ), $continue || (return) 0 0 0
Condition0%0/2
$continue or return
l!l
00
MC/DC0%0/1
$continue or return
$continue
Truth table0%0/2
A
A= $continue
Aresult
11
00
706 $continue || return;
707  
708 0 my $go_for_it;
709 $form->trigger_event(
710 'submit',
711 0 ▶ submit_default => sub { ++$go_for_it }
Subroutine __ANON__: not called CC=1 SCAR=6.9
712 0 );
713 0 ▶ $go_for_it
Branch: 1 branch
BranchTrueFalseTotal
$go_for_it ? : 0 0 0
Condition0%0/3
$self->find_target($form->target) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->find_target($form->target) || $self
$self->find_target($form->target) $self
Truth table0%0/3
A || B
A= $self->find_target($form->target)B= $self
ABresult
1X1
011
000
714 ? ($self->find_target($form->target)||$self)
715 ->request($form->make_request)
716 : ()
717 }
718 else {
719 # Unlike the submit method, we *can* delegate to the superclass here,
720 # as the form’s click method (which Mech->click calls) calls our
721 # default_event_handler_for submit, which chooses the right target.
722 0 shift->SUPER::click(@_);
723 }
724 }
725  
726  
727 # ------------- Window interface ------------- #
728  
729 # This does not follow the same format as %HTML::DOM::Interface; this cor-
730 # responds to the format of hashes *within* %H:D:I. The other format does
731 # not apply here, since we can’t bind the class like other classes. This
732 # needs to be bound to the global object (at least in JavaScript).
733 our %WindowInterface = (
734 26 %{$HTML::DOM::Interface{AbstractView}},
735 26 %{$HTML::DOM::Interface{EventTarget}},
736 alert => VOID|METHOD,
737 confirm => BOOL|METHOD,
738 prompt => STR|METHOD,
739 location => OBJ,
740 setTimeout => NUM|METHOD,
741 clearTimeout => NUM|METHOD,
742 setInterval => NUM|METHOD,
743 clearInterval => NUM|METHOD,
744 open => OBJ|METHOD,
745 blur => VOID|METHOD,
746 close => VOID|METHOD,
747 focus => VOID|METHOD,
748 window => OBJ|READONLY,
749 self => OBJ|READONLY,
750 navigator => OBJ|READONLY,
751 screen => OBJ|READONLY,
752 top => OBJ|READONLY,
753 frames => OBJ|READONLY,
754 length => NUM|READONLY,
755 parent => OBJ|READONLY,
756 name => STR,
757 scroll => VOID|METHOD,
758 scrollBy => VOID|METHOD,
759 scrollTo => VOID|METHOD,
760 history => OBJ|READONLY,
761 # See the comment preceding the commented-out subs.
762 # status => STR,
763 # defaultStatus => STR,
764 );
765  
766 sub alert {
767 0 ▶ my $self = shift;
Subroutine alert: not called CC=2 SCAR=17.9
Pod documented
768 0 ▶ &{$$self{Scripter_alert}||sub{print @_,"\n";()}}(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->{"Scripter_alert"} or sub { print @_, "\n"; (); } 0 0 0
769 }
770 sub confirm {
771 0 ▶ my $self = shift;
Subroutine confirm: not called CC=2 SCAR=17.9
Pod documented
772 0 ▶ ($$self{Scripter_confirm}||$self->die(
Condition0%0/3
$self->{'Scripter_confirm'} || $self->die('There is no default confirm function')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'Scripter_confirm'} || $self->die('There is no default confirm function')
$self->{'Scripter_confirm'} $self->die('There is no default confirm function')
Truth table0%0/3
A || B
A= $self->{'Scripter_confirm'}B= $self->die('There is no default confirm function')
ABresult
1X1
011
000
773 "There is no default confirm function"
774 ))->(@_)
775 }
776 sub prompt {
777 0 ▶ my $self = shift;
Subroutine prompt: not called CC=2 SCAR=17.9
Pod documented
778 0 ▶ ($$self{Scripter_prompt}||$self->die(
Condition0%0/3
$self->{'Scripter_prompt'} || $self->die('There is no default prompt function')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'Scripter_prompt'} || $self->die('There is no default prompt function')
$self->{'Scripter_prompt'} $self->die('There is no default prompt function')
Truth table0%0/3
A || B
A= $self->{'Scripter_prompt'}B= $self->die('There is no default prompt function')
ABresult
1X1
011
000
779 "There is no default prompt function"
780 ))->(@_)
781 }
782  
783 sub location {
784 0 ▶ my $self = shift;
Subroutine location: not called CC=3 SCAR=24.8
Pod documented
785 0 ▶ my $loc = $self->{Scripter_loc} ||= WWW::Scripter::Location->new(
Condition0%0/3
$self->{"Scripter_loc"} ||= "WWW::Scripter::Location"->new($self)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Scripter_loc"} ||= "WWW::Scripter::Location"->new($self)
$self->{"Scripter_loc"} "WWW::Scripter::Location"->new($self)
Truth table0%0/3
A ||= B
A= $self->{"Scripter_loc"}B= "WWW::Scripter::Location"->new($self)
ABresult
1X1
011
000
786 $self
787 );
788 0 ▶ $loc->href(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
789 0 $loc;
790 }
791  
792 sub navigator {
793 0 ▶ my $self = shift;
Subroutine navigator: not called CC=2 SCAR=17.9
Pod documented
794 0 ▶ $navi{$self} ||=
Condition0%0/3
$navi{$self} ||= "WWW::Scripter::Navigator"->new($self)
l!l&&r!l&&!r
000
MC/DC0%0/2
$navi{$self} ||= "WWW::Scripter::Navigator"->new($self)
$navi{$self} "WWW::Scripter::Navigator"->new($self)
Truth table0%0/3
A ||= B
A= $navi{$self}B= "WWW::Scripter::Navigator"->new($self)
ABresult
1X1
011
000
795 new WWW::Scripter::Navigator:: $self;
796 }
797  
798 sub screen {
799 0 ▶ my $self = shift;
Subroutine screen: not called CC=2 SCAR=17.9
Pod documented
800 0 ▶ $scrn{$self} ||=
Condition0%0/2
$scrn{$self} ||= bless(\my $foo, "WWW::Scripter::Screen")
l!l
00
MC/DC0%0/1
$scrn{$self} ||= bless(\my $foo, "WWW::Scripter::Screen")
$scrn{$self}
Truth table0%0/2
A
A= $scrn{$self}
Aresult
11
00
801 bless \my $foo, WWW::Scripter::Screen::;
802 }
803 26 @WWW::Scripter::Interface{WWW::Scripter::Screen::,'Screen'} = (
804 'Screen', {}
805 );
806  
807 sub setTimeout {
808 0 ▶ my $doc = shift->document;
Subroutine setTimeout: not called CC=2 SCAR=17.9
Pod documented
809 0 my $time = time;
810 0 my ($code, $ms) = (shift,shift);
811 0 $ms /= 1000;
812 0 ▶ my $t_o = $timeouts{$doc}||=[];
Condition0%0/2
$timeouts{$doc} ||= []
l!l
00
MC/DC0%0/1
$timeouts{$doc} ||= []
$timeouts{$doc}
Truth table0%0/2
A
A= $timeouts{$doc}
Aresult
11
00
813 0 $$t_o[my $id = @$t_o] =
814 [$ms+$time, $code, @_];
815 0 return $id;
816 }
817  
818 sub clearTimeout {
819 0 ▶ delete $timeouts{shift->document}[shift];
Subroutine clearTimeout: not called CC=1 SCAR=6.9
Pod documented
820 0 return;
821 }
822  
823 sub setInterval {
824 0 ▶ my $doc = shift->document;
Subroutine setInterval: not called CC=2 SCAR=17.9
Pod documented
825 0 my $time = time;
826 0 my ($code, $ms) = (shift,shift);
827 0 $ms /= 1000;
828 0 ▶ my $t_o = $timers{$doc}||=[];
Condition0%0/2
$timers{$doc} ||= []
l!l
00
MC/DC0%0/1
$timers{$doc} ||= []
$timers{$doc}
Truth table0%0/2
A
A= $timers{$doc}
Aresult
11
00
829 0 $$t_o[my $id = @$t_o] =
830 [$ms+$time, $code, @_];
831 0 return $id;
832 }
833  
834 sub clearInterval {
835 0 ▶ delete $timers{shift->document}[shift];
Subroutine clearInterval: not called CC=1 SCAR=6.9
Pod documented
836 0 return;
837 }
838  
839 sub open {
840 0 ▶ my($self,$url,$target,undef,$replace) = @_;
Subroutine open: not called CC=8 SCAR=42.8
Pod documented
841 0 ▶ $target
Branch: 1 branch
BranchTrueFalseTotal
defined $target ? : 0 0 0
842 = $self->find_target(defined $target ? $target : '_blank');
843 0 ▶ if(defined $url and length $url) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $url and CORE::length $url) { } 0 0 0
elsif (not $target) { } 0 0 0
Condition0%0/3
defined $url and CORE::length $url
!ll&&!rl&&r
000
MC/DC0%0/2
defined $url and CORE::length $url
defined $url CORE::length $url
Truth table0%0/3
A and B
A= defined $urlB= CORE::length $url
ABresult
0X0
100
111
844 0 ▶ if(my $base = $self->base) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $base = $self->base) 0 0 0
845 0 require URI;
846 0 $url = URI->new_abs( $url, $base );
847 }
848 0 ▶ $target||=$self->top;
Condition0%0/3
$target ||= $self->top
l!l&&r!l&&!r
000
MC/DC0%0/2
$target ||= $self->top
$target $self->top
Truth table0%0/3
A ||= B
A= $targetB= $self->top
ABresult
1X1
011
000
849 0 ▶ $replace
Branch: 1 branch
BranchTrueFalseTotal
$replace ? : 0 0 0
850 ? $target->location->replace($url)
851 : $target->get($url);
852 0 $target;
853 }
854 elsif(!$target) {
855 # undef or "" in single-window mode: append an ‘unbrowsed’
856 # history entry to simulate a new window
857 0 (my $ret = $self->top)->{page_stack}->_add();
858 0 _initial_page($ret);
859 0 $ret;
860 }
861 else {
862 # open("") with existing window; do nothing
863 0 $target
864 }
865 }
866  
867 sub close {
868 0 ▶ if(my $g = $_[0]{Scripter_g}) {
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (my $g = $_[0]{'Scripter_g'}) { } 0 0 0
869 0 $g->detach($_[0]);
870 }
871 else {
872 0 $_[0]->history->go(-1);
873 }
874 _:
875 }
876  
877 sub focus {
878 0 ▶ my $g = $_[0]{Scripter_g} or return;
Subroutine focus: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $g = $_[0]{"Scripter_g"} or return 0 0 0
879 0 $g->bring_to_front(shift);
880 0 return;
881 }
882  
883 sub blur {
884 0 ▶ my $g = $_[0]{Scripter_g} or return;
Subroutine blur: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $g = $_[0]{"Scripter_g"} or return 0 0 0
885 0 my($maybe_self,$next) = $g->windows;
886 0 ▶ $next or return;
Branch: 1 branch
BranchTrueFalseTotal
$next or return 0 0 0
887 0 ▶ $maybe_self == $_[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
$maybe_self == $_[0] or return 0 0 0
888 0 $g->bring_to_front($next);
889 0 return;
890 }
891  
892  
893 0 ▶sub history { $_[0]{page_stack} }
Subroutine history: not called CC=1 SCAR=6.9
Pod documented
894  
895 sub frames {
896 0 ▶ my $doc = $_[0]->document;
Subroutine frames: not called CC=4 SCAR=30.0
Pod documented
897 0 ▶ my $frames = $frames{$doc||''} # the ||'' is for non-HTML docu-
Condition0%0/5
$frames{$doc or ""} ||= "WWW::Scripter::Frames"->new($_[0], $doc)
l!l&&r!l&&!r
000
$doc || ''
l!l
00
MC/DC0%0/2
$frames{$doc or ""} ||= "WWW::Scripter::Frames"->new($_[0], $doc)
$frames{$doc or ""} "WWW::Scripter::Frames"->new($_[0], $doc)
MC/DC0%0/1
$doc || ''
$doc
Truth table0%0/3
A ||= B
A= $frames{$doc or ""}B= "WWW::Scripter::Frames"->new($_[0], $doc)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $doc
Aresult
11
00
898 ||= WWW::Scripter'Frames->new( $_[0], $doc ); # ments, which all share
899 0 ▶ wantarray ? @$frames : $frames # an empty frames
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
900 } # collection
901  
902 0 ▶sub window { $_[0] }
Subroutine window: not called CC=1 SCAR=6.9
Pod documented
903 26 *self = *window;
904 0 ▶sub length { $frames{$_[0]->document}->length }
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
905  
906 sub top {
907 0 ▶ my $self = shift;
Subroutine top: not called CC=3 SCAR=24.8
Pod documented
908 0 ▶ $$self{Scripter_t} || do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"Scripter_t"} or do { my $parent = $self; while (1) { $parent->{"Scripter_pa"} or builtin::weaken($self->{"Scripter_t"} = $parent), last; $parent = $parent->{"Scripter_pa"}; } ; $self->{"Scripter_t"} } 0 0 0
909 0 my $parent = $self;
910 0 while() {
911 $$parent{Scripter_pa} or
912 0 ▶ weaken( $$self{Scripter_t} = $parent), last;
Branch: 1 branch
BranchTrueFalseTotal
$parent->{"Scripter_pa"} or builtin::weaken($self->{"Scripter_t"} = $parent), last 0 0 0
913 0 $parent = $$parent{Scripter_pa};
914 }
915 $$self{Scripter_t}
916 0 };
917 }
918  
919 sub parent {
920 0 ▶ my $self = shift;
Subroutine parent: not called CC=2 SCAR=17.9
Pod documented
921 0 ▶ $$self{Scripter_pa} || $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"Scripter_pa"} or $self 0 0 0
922 }
923  
924 0 ▶sub _set_parent { weaken( $_[0]{Scripter_pa} = $_[1] ) }
Subroutine _set_parent: not called CC=1 SCAR=6.9
925  
926 sub name {
927 0 ▶ my $self = shift;
Subroutine name: not called CC=2 SCAR=17.9
Pod documented
928 0 my $old = $$self{Scripter_nm};
929 0 ▶ $$self{Scripter_nm} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
930 0 $old;
931 }
932  
933 26 ▶sub scroll{}; *scrollBy=*scrollTo=*scroll;
Subroutine scroll: not called CC=1 SCAR=0.0
Pod documented
934  
935 # ~~~ This conflicts with Mech’s method. We probably need to bite the
936 # bullet and provide a separate window object for scripts.
937 #sub status {
938 # my $old = $status{my $doc = shift->document};
939 # no warnings 'uninitialized';
940 # $status{$doc} = "$_[0]" if @_;
941 # defined $old ? $old : ''
942 #}
943 #
944 # ~~~ This one is commented out because it makes no sense without the
945 # previous one.
946 #sub defaultStatus {
947 # my $old = $dstatus{my $doc = shift->document};
948 # no warnings 'uninitialized';
949 # $dstatus{$doc} = "$_[0]" if @_;
950 # defined $old ? $old : ''
951 #}
952  
953 # ------------- Window-Related Public Methods -------------- #
954  
955 0 ▶sub set_alert_function { ${$_[0]}{Scripter_alert} = $_[1]; }
Subroutine set_alert_function: not called CC=1 SCAR=6.9
Pod documented
956 0 ▶sub set_confirm_function { ${$_[0]}{Scripter_confirm} = $_[1]; }
Subroutine set_confirm_function: not called CC=1 SCAR=6.9
Pod documented
957 0 ▶sub set_prompt_function { ${$_[0]}{Scripter_prompt} = $_[1]; }
Subroutine set_prompt_function: not called CC=1 SCAR=6.9
Pod documented
958  
959 sub check_timers {
960 0 ▶ my $time = time;
Subroutine check_timers: not called CC=15 SCAR=52.9
Pod documented
961 0 my $self = shift;
962 0 local *_;
963 0 my $doing_timers_now;
964 my $jh;
965 0 for my $timers(\%timeouts, \%timers) {
966 0 ▶ my $t_o = $$timers{$self->document}||next;
Condition0%0/2
$$timers{$self->document} || (next)
l!l
00
MC/DC0%0/1
$$timers{$self->document} || (next)
$$timers{$self->document}
Truth table0%0/2
A
A= $$timers{$self->document}
Aresult
11
00
967 0 for my $id(0..$#$t_o) {
968 0 ▶ next unless $_ = $$t_o[$id];
Branch: 1 branch
BranchTrueFalseTotal
unless $_ = $t_o->[$id] 0 0 0
969 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
970 0 local *@;
971 $$_[0] <= $time and
972 reftype $$_[1] eq 'CODE' || (
973 exists $INC{'overload.pm'}
974 && defined blessed $$_[1]
975 && overload'Method($$_[1],'&{}')
976 )
977 0 ▶ ? eval { $$_[1]->(@$_[2..$#$_]) }
Branch: 3 branches
BranchTrueFalseTotal
$_->[0] <= $time and builtin::reftype($_->[1]) eq "CODE" || exists $INC{"overload.pm"} && defined builtin::blessed($_->[1]) && overload::Method($_->[1], "&{}") ? eval { do { $_->[1]->(@$_[2 .. $_->$#*]) } } : ($jh ||= $self->_handler_for_lang("JavaScript")) && $jh->eval($self, $_->[1]), $@ && $self->warn($@), $doing_timers_now ? $_->[0] = &WWW::Scripter::time() : delete $t_o->[$id] 0 0 0
builtin::reftype($_->[1]) eq 'CODE' || exists $INC{'overload.pm'} && defined builtin::blessed($_->[1]) && overload::Method($_->[1], '&{}') ? : 0 0 0
$doing_timers_now ? : 0 0 0
Condition0%0/18
builtin::reftype($_->[1]) eq "CODE" or exists $INC{"overload.pm"} and defined builtin::blessed($_->[1]) and overload::Method($_->[1], "&{}")
l!l&&r!l&&!r
000
exists $INC{"overload.pm"} and defined builtin::blessed($_->[1]) and overload::Method($_->[1], "&{}")
!ll&&!rl&&r
000
exists $INC{"overload.pm"} and defined builtin::blessed($_->[1])
!ll&&!rl&&r
000
$jh ||= $self->_handler_for_lang("JavaScript") and $jh->eval($self, $_->[1])
!ll&&!rl&&r
000
$jh ||= $self->_handler_for_lang("JavaScript")
l!l&&r!l&&!r
000
$@ and $self->warn($@)
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::reftype($_->[1]) eq "CODE" or exists $INC{"overload.pm"} and defined builtin::blessed($_->[1]) and overload::Method($_->[1], "&{}")
builtin::reftype($_->[1]) eq "CODE" exists $INC{"overload.pm"} defined builtin::blessed($_->[1]) overload::Method($_->[1], "&{}")
MC/DC0%0/3
$jh ||= $self->_handler_for_lang("JavaScript") and $jh->eval($self, $_->[1])
$jh $self->_handler_for_lang("JavaScript") $jh->eval($self, $_->[1])
MC/DC0%0/2
$@ and $self->warn($@)
$@ $self->warn($@)
Truth table0%0/5
A or B and C and D
A= builtin::reftype($_->[1]) eq "CODE"B= exists $INC{"overload.pm"}C= defined builtin::blessed($_->[1])D= overload::Method($_->[1], "&{}")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
Truth table0%0/5
A ||= B and C
A= $jhB= $self->_handler_for_lang("JavaScript")C= $jh->eval($self, $_->[1])
ABCresult
00X0
1X00
0100
1X11
0111
Truth table0%0/3
A and B
A= $@B= $self->warn($@)
ABresult
0X0
100
111
978 : (
979 $jh ||= $self->_handler_for_lang('JavaScript')
980 and $jh->eval($self,$$_[1])
981 ),
982 $@ && $self->warn($@),
983 $doing_timers_now ? $$_[0] = time : delete $$t_o[$id];
984 }
985 0 } continue { ++$doing_timers_now }
986 0 $_->check_timers for $self->frames;
987 # ~~~ Should we try to trigger the timers in the right order if,
988 # exempli gratia, an iframe’s timer was registered with 200 as
989 # the timeout, and then the main window with 210 immediately
990 # thereafter?
991 return
992 0 }
993  
994 sub count_timers {
995 0 ▶ my $self = shift;
Subroutine count_timers: not called CC=7 SCAR=40.3
Pod documented
996 0 my $count;
997 0 for(\%timeouts, \%timers) {
998 0 ▶ if(my $t_o = $$_{$self->document}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t_o = $$_{$self->document}) 0 0 0
999 #use DDS; Dump [map $_&&[map "$_", @$_], @$t_o];
1000 0 for my $id(0..$#$t_o) {
1001 0 ▶ next unless $$t_o[$id];
Branch: 1 branch
BranchTrueFalseTotal
unless $t_o->[$id] 0 0 0
1002 0 ++$count
1003 }
1004 }
1005 }
1006 0 ▶ sum $count||(), map $_->count_timers, $self->frames or 0;
Branch: 1 branch
BranchTrueFalseTotal
&sum($count || (), map($_->count_timers, $self->frames)) or 0 0 0 0
Condition0%0/3
$count || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$count || ()
$count ()
Truth table0%0/3
A || B
A= $countB= ()
ABresult
1X1
011
000
1007 }
1008  
1009 sub wait_for_timers {
1010 0 ▶ my($self, %args) = @_;
Subroutine wait_for_timers: not called CC=7 SCAR=40.3
Pod documented
1011 0 ▶ my $start_time = time if $args{max_wait};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"max_wait"} 0 0 0
1012 0 ▶ my $interval = $args{interval} || .1;
Condition0%0/2
$args{'interval'} || 0.1
l!l
00
MC/DC0%0/1
$args{'interval'} || 0.1
$args{'interval'}
Truth table0%0/2
A
A= $args{'interval'}
Aresult
11
00
1013 0 ▶ my $min = $args{min_timers} || 0;
Condition0%0/2
$args{'min_timers'} || 0
l!l
00
MC/DC0%0/1
$args{'min_timers'} || 0
$args{'min_timers'}
Truth table0%0/2
A
A= $args{'min_timers'}
Aresult
11
00
1014 0 $self->check_timers;
1015 0 ▶ while(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->count_timers > $min and !$args{"max_wait"} || &WWW::Scripter::time() - $start_time < $args{"max_wait"}) 0 0 0
Condition0%0/6
$self->count_timers > $min and !$args{"max_wait"} || &WWW::Scripter::time() - $start_time < $args{"max_wait"}
!ll&&!rl&&r
000
not $args{"max_wait"} or &WWW::Scripter::time() - $start_time < $args{"max_wait"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->count_timers > $min and !$args{"max_wait"} || &WWW::Scripter::time() - $start_time < $args{"max_wait"}
$self->count_timers > $min not $args{"max_wait"} &WWW::Scripter::time() - $start_time < $args{"max_wait"}
Truth table0%0/4
A and not(B) or C
A= $self->count_timers > $minB= not $args{"max_wait"}C= &WWW::Scripter::time() - $start_time < $args{"max_wait"}
ABCresult
0XX0
1000
11X1
1011
1016 $self->count_timers > $min
1017 and !$args{max_wait} || time-$start_time < $args{max_wait}
1018 ) {
1019 0 select(undef,undef,undef,$interval);
1020 0 $self->check_timers;
1021 }
1022 _:
1023 }
1024  
1025 sub window_group {
1026 0 ▶ my $old = (my $self = shift)->{Scripter_g};
Subroutine window_group: not called CC=2 SCAR=17.9
Pod documented
1027 0 ▶ @_ and weaken($self->{Scripter_g} = shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and builtin::weaken($self->{"Scripter_g"} = shift()) 0 0 0
1028 0 $old
1029 }
1030  
1031 sub find_target {
1032 0 ▶ my $self = shift;
Subroutine find_target: not called CC=21 SCAR=60.3
Pod documented
1033 0 my $name = shift;
1034 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1035 0 ▶ if(!CORE::length $name and my $doc = document $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (not CORE::length $name and my $doc = $self->document) 0 0 0
Condition0%0/3
not CORE::length $name and my $doc = $self->document
!ll&&!rl&&r
000
MC/DC0%0/2
not CORE::length $name and my $doc = $self->document
not CORE::length $name my $doc = $self->document
Truth table0%0/3
not(A) and B
A= not CORE::length $nameB= my $doc = $self->document
ABresult
0X0
100
111
1036 0 ▶ if(my $base_elem = $doc->look_down(_tag => 'base', target => qr)(?:\)))){
Branch: 1 branch
BranchTrueFalseTotal
if (my $base_elem = $doc->look_down("_tag", "base", "target", qr/(?:)/)) 0 0 0
1037 0 $name = $base_elem->attr('target');
1038 }
1039 }
1040 0 ▶ CORE::length $name or return $self;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $name or return $self 0 0 0
1041 0 ▶ if($name =~ /^_[Bb][Ll][Aa][Nn][Kk]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^_[Bb][Ll][Aa][Nn][Kk]\z/) 0 0 0
1042 0 ▶ if(my $g = $$self{Scripter_g}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $g = $self->{"Scripter_g"}) 0 0 0
1043 0 attach $g my $neww = $self->clone->clear_history(1);
1044 0 return $neww;
1045 }
1046 0 return undef;
1047 }
1048 0 ▶ $name =~ /^_[Ss][Ee][Ll][Ff]\z/ and return $self;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^_[Ss][Ee][Ll][Ff]\z/ and return $self 0 0 0
1049 0 ▶ $name =~ /^_[Pp][Aa][Rr][Ee][Nn][Tt]\z/ and return $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^_[Pp][Aa][Rr][Ee][Nn][Tt]\z/ and return $self->parent 0 0 0
1050 0 ▶ $name =~ /^_[Tt][Oo][Pp]\z/ and return $self->top;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^_[Tt][Oo][Pp]\z/ and return $self->top 0 0 0
1051  
1052 # Search subframes, and then ancestors (including their subframes), in
1053 # breadth-first order
1054 0 my $current_ancestor = $self;
1055 0 my $prev_ancestor;
1056 0 while() {
1057 0 ▶ $current_ancestor->name eq $name and return $current_ancestor;
Branch: 1 branch
BranchTrueFalseTotal
$current_ancestor->name eq $name and return $current_ancestor 0 0 0
1058 0 ▶ my $next_level = [
Branch: 1 branch
BranchTrueFalseTotal
$prev_ancestor ? : 0 0 0
1059 $prev_ancestor
1060 ? grep $_ != $prev_ancestor, $current_ancestor->frames
1061 : $current_ancestor->frames
1062 ];
1063 0 ▶ while($next_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_level) 0 0 0
1064 0 my $tmp = $next_level; $next_level = undef;
1065 0 for(@$tmp) {
1066 0 ▶ if($_->name eq $name) { return $_ }
Branch: 1 branch
BranchTrueFalseTotal
if ($_->name eq $name) 0 0 0
1067 0 push @$next_level, $_->frames;
1068 }
1069 }
1070 0 $prev_ancestor = $current_ancestor;
1071 0 $current_ancestor = $current_ancestor->parent;
1072 0 ▶ last if $prev_ancestor == $current_ancestor;
Branch: 1 branch
BranchTrueFalseTotal
if $prev_ancestor == $current_ancestor 0 0 0
1073 }
1074  
1075 # If we reach this point, there are no frames named $name. Return undef
1076 # in single-window mode, or look for a window.
1077 0 ▶ my $g = $$self{Scripter_g} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $g = $self->{"Scripter_g"} or return undef 0 0 0
1078 0 ▶ my $named = ($$self{Scripter_n}||=&fieldhash({}))->{$self->response}||={};
Condition0%0/5
($self->{"Scripter_n"} ||= &fieldhash(scalar {}))->{$self->response} ||= {}
l!l
00
$self->{"Scripter_n"} ||= &fieldhash(scalar {})
l!l&&r!l&&!r
000
MC/DC0%0/1
($self->{"Scripter_n"} ||= &fieldhash(scalar {}))->{$self->response} ||= {}
($self->{"Scripter_n"} ||= &fieldhash(scalar {}))->{$self->response}
MC/DC0%0/2
$self->{"Scripter_n"} ||= &fieldhash(scalar {})
$self->{"Scripter_n"} &fieldhash(scalar {})
Truth table0%0/2
A
A= ($self->{"Scripter_n"} ||= &fieldhash(scalar {}))->{$self->response}
Aresult
11
00
Truth table0%0/3
A ||= B
A= $self->{"Scripter_n"}B= &fieldhash(scalar {})
ABresult
1X1
011
000
1079 # The extra ${} is there since a reference in a tied hash element cannot
1080 # be weakened directly, as the element is just temporary each time.
1081 0 $$named{$name} && ${$$named{$name}}->window_group
1082 0 ? ${$$named{$name}}
1083 0 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
$named->{$name} && ${$$named{$name};}->window_group ? : 0 0 0
Condition0%0/3
$named->{$name} and ${$$named{$name};}->window_group
!ll&&!rl&&r
000
MC/DC0%0/2
$named->{$name} and ${$$named{$name};}->window_group
$named->{$name} ${$$named{$name};}->window_group
Truth table0%0/3
A and B
A= $named->{$name}B= ${$$named{$name};}->window_group
ABresult
0X0
100
111
1084 0 attach $g my $neww = $self->clone->clear_history(1);
1085 0 weaken(${$$named{$name}} = $neww);
1086 0 $neww
1087 }
1088 }
1089  
1090 # ------------- EventTarget interface ------------- #
1091  
1092 26 *event_listeners_enabled = *scripts_enabled;
1093  
1094 # What we are doing here is delegating event handler/listener storage to
1095 # a response object (and fooling EventTarget into thinking that the
1096 # response object is an EventTarget). This is so that each page has its own
1097 # set of event handlers, but we still use the WWW::Scripter object as the
1098 # event target.
1099 26 for my $meth (qw b addEventListener removeEventListener event_handler
1100 get_event_listeners b) {
1101 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1102 104 my $full_meth= "HTML::DOM::EventTarget::$meth";
1103 *$meth = sub {
1104 0 ▶ shift->response->$full_meth(@_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
1105 }
1106 104 }
1107  
1108  
1109 # ------------- Image Hooks -------------- #
1110  
1111 sub fetch_images {
1112 0 ▶ my $old = (my $self = shift)->{Scripter_i};
Subroutine fetch_images: not called CC=2 SCAR=17.9
Pod documented
1113 0 ▶ @_ and $self->{Scripter_i} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"Scripter_i"} = shift() 0 0 0
1114 0 $old
1115 }
1116  
1117 sub image_handler {
1118 0 ▶ my $old = (my $self = shift)->{Scripter_ih};
Subroutine image_handler: not called CC=2 SCAR=17.9
Pod documented
1119 0 ▶ @_ and $self->{Scripter_ih} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"Scripter_ih"} = shift() 0 0 0
1120 0 $old
1121 }
1122  
1123 # ------------- Scripting hooks and what-not ------------- #
1124  
1125 sub eval {
1126 0 ▶ my ($self,$code) = (shift,shift);
Subroutine eval: not called CC=4 SCAR=30.0
Pod documented
1127 0 my $h = $self->_handler_for_lang(my $lang = shift);
1128 0 ▶ my $ret = (
Branch: 1 branch
BranchTrueFalseTotal
defined $lang ? : 0 0 0
Condition0%0/3
$h || $self->die(defined $lang ? "No scripting handlers have been registered for $lang" : 'No scripting handlers have been registered')
l!l&&r!l&&!r
000
MC/DC0%0/2
$h || $self->die(defined $lang ? "No scripting handlers have been registered for $lang" : 'No scripting handlers have been registered')
$h $self->die(defined $lang ? "No scripting handlers have been registered for $lang" : 'No scripting handlers have been registered')
Truth table0%0/3
A || B
A= $hB= $self->die(defined $lang ? "No scripting handlers have been registered for $lang" : 'No scripting handlers have been registered')
ABresult
1X1
011
000
1129 $h or $self->die(
1130 defined $lang ? "No scripting handlers have been registered for $lang"
1131 : "No scripting handlers have been registered"
1132 )
1133 )->eval($self,$code);
1134 0 ▶ $@ and $self->warn($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ and $self->warn($@) 0 0 0
1135 0 $ret;
1136 }
1137  
1138 sub use_plugin {
1139 0 ▶ my ($self, $plugin, @opts) = (shift, shift, @_);
Subroutine use_plugin: not called CC=6 SCAR=37.4
Pod documented
1140 0 ▶ my $plugins = $self->{plugins} ||= {};
Condition0%0/2
$self->{"plugins"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"plugins"} ||= {}
$self->{"plugins"}
Truth table0%0/2
A
A= $self->{"plugins"}
Aresult
11
00
1141 0 $plugin = _plugin2module($plugin);
1142 0 ▶ return $plugins->{$plugin} if $self->{cloning};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cloning"} 0 0 0
1143 0 ▶ if(exists $plugins->{$plugin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $plugins->{$plugin}) { } 0 0 0
1144 0 ▶ $plugins->{$plugin}->options(@opts) if @opts;
Branch: 1 branch
BranchTrueFalseTotal
if @opts 0 0 0
1145 }
1146 else {
1147 0 (my $plugin_file = $plugin) =~ s-::-/-g;
1148 0 require "$plugin_file.pm";
1149 0 $plugins->{$plugin} = $plugin->init($self, \@opts);
1150 0 ▶ $plugins->{$plugin}->options(@opts) if @opts;
Branch: 1 branch
BranchTrueFalseTotal
if @opts 0 0 0
1151 }
1152 0 $plugins->{$plugin};
1153 }
1154  
1155 sub plugin {
1156 0 ▶ my $self = shift;
Subroutine plugin: not called CC=3 SCAR=24.8
Pod documented
1157 0 my $plugin = _plugin2module(shift);
1158 return exists $self->{plugins}{$plugin}
1159 0 ▶ ? $self->{plugins}{$plugin} || 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'plugins'}{$plugin} ? : 0 0 0
Condition0%0/2
$self->{"plugins"}{$plugin} or 1
l!l
00
MC/DC0%0/1
$self->{"plugins"}{$plugin} or 1
$self->{"plugins"}{$plugin}
Truth table0%0/2
A
A= $self->{"plugins"}{$plugin}
Aresult
11
00
1160 }
1161  
1162 sub _plugin2module { # This is NOT a method
1163 0 ▶ my $name = shift;
Subroutine _plugin2module: not called CC=2 SCAR=17.9
1164 0 ▶ return $name if $name =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /::/ 0 0 0
1165 0 $name =~ s/-/::/g;
1166 0 return __PACKAGE__."::Plugin::$name";
1167 }
1168  
1169 sub _clone_plugins {
1170 0 ▶ my $self = shift;
Subroutine _clone_plugins: not called CC=6 SCAR=37.4
1171 0 ▶ return unless $self->{plugins};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"plugins"} 0 0 0
1172 0 my $plugins = $self->{plugins} = { %{$self->{plugins}} };
1173 0 ▶ while ( my($pn,$po) = each %$plugins ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$plugins) 0 0 0
1174 # plugin name, plugin object
1175 0 ▶ next unless $po && defined blessed $po && $po->can('clone');
Branch: 1 branch
BranchTrueFalseTotal
unless $po and defined builtin::blessed($po) and $po->can("clone") 0 0 0
Condition0%0/6
$po and defined builtin::blessed($po) and $po->can("clone")
!ll&&!rl&&r
000
$po and defined builtin::blessed($po)
!ll&&!rl&&r
000
MC/DC0%0/3
$po and defined builtin::blessed($po) and $po->can("clone")
$po defined builtin::blessed($po) $po->can("clone")
Truth table0%0/4
A and B and C
A= $poB= defined builtin::blessed($po)C= $po->can("clone")
ABCresult
0XX0
10X0
1100
1111
1176 0 $plugins->{$pn} = $po->clone($self);
1177 }
1178 }
1179  
1180 sub dom_enabled {
1181 0 ▶ my $old = (my $self = shift)->{Scripter_dumb};
Subroutine dom_enabled: not called CC=3 SCAR=24.8
Pod documented
1182 0 ▶ defined $old or $old = 1; # default
Branch: 1 branch
BranchTrueFalseTotal
defined $old or $old = 1 0 0 0
1183 0 ▶ if(@_) {{
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1184 0 $$self{Scripter_dumb} = !!$_[0]; # We don’t want undef
1185 }} # resetting it.
1186 $old
1187 0 }
1188  
1189 sub scripts_enabled {
1190 0 ▶ my $old = $scriptable{my $self = shift};
Subroutine scripts_enabled: not called CC=4 SCAR=30.0
Pod documented
1191 0 ▶ defined $old or $old = 1; # default
Branch: 1 branch
BranchTrueFalseTotal
defined $old or $old = 1 0 0 0
1192 0 ▶ if(@_) {{
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1193 0 $scriptable{$self} = !!$_[0]; # We don’t want undef resetting it.
1194 0 ▶ ($self->document ||last) ->event_listeners_enabled(shift) ;
Condition0%0/2
$self->document || (last)
l!l
00
MC/DC0%0/1
$self->document || (last)
$self->document
Truth table0%0/2
A
A= $self->document
Aresult
11
00
1195 }}
1196 $old
1197 0 }
1198 # used by HTML::DOM::EventTarget:
1199 26 *event_listeners_enabled = *scripts_enabled;
1200  
1201 sub script_handler {
1202 0 ▶ my($self,$key) = (shift,shift);
Subroutine script_handler: not called CC=2 SCAR=17.9
Pod documented
1203 0 my $old = $script_handlers{$self}{$key};
1204 0 ▶ @_ and $script_handlers{$self}{$key} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $script_handlers{$self}{$key} = shift() 0 0 0
1205 0 $old
1206 }
1207  
1208 sub class_info {
1209 0 ▶ my $self = shift;
Subroutine class_info: not called CC=3 SCAR=24.8
Pod documented
1210 0 ▶ @_ and push @{ $class_info{$self} }, shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and push @{$class_info{$self};}, shift() 0 0 0
1211 0 ▶ @{ $class_info{$self} } if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
1212 }
1213  
1214 # ------------- Miss Elaine E. S. ------------- #
1215  
1216 # This function is exported upon request.
1217 sub abort {
1218 26 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
1219 0 ▶ last Scripter_ABORT;
Subroutine abort: not called CC=1 SCAR=6.9
Pod undocumented
1220 }
1221  
1222 sub forward {
1223 0 ▶ my $self = shift;
Subroutine forward: not called CC=1 SCAR=6.9
Pod documented
1224 0 $self->{page_stack}->go(1);
1225 }
1226  
1227 sub clear_history {
1228 0 ▶ my $self = shift;
Subroutine clear_history: not called CC=3 SCAR=24.8
Pod documented
1229 0 $$self{'page_stack'}->_clear(@_);
1230 0 ▶ if (shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift()) 0 0 0
1231 0 $self->_reset_page;
1232  
1233 # list of keys taken from _update_page
1234 0 delete $self->{$_} for qw[ req redirected_url res status base ct
1235 uri last_uri content ];
1236 0 _initial_page($self);
1237 }
1238 0 return $self;
1239 }
1240  
1241 sub max_docs {
1242 0 ▶ my $self= shift;
Subroutine max_docs: not called CC=3 SCAR=24.8
Pod documented
1243 0 ▶ defined wantarray and my $old = $self->stack_depth+1;
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray and my $old = $self->stack_depth + 1 0 0 0
1244 0 ▶ $self->stack_depth(shift()-1) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1245 0 $old;
1246 }
1247  
1248 sub max_history {
1249 0 ▶ my $old = (my $self = shift)->{Scripter_max_hist};
Subroutine max_history: not called CC=2 SCAR=17.9
Pod documented
1250 0 ▶ @_ and $self->{Scripter_max_hist} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"Scripter_max_hist"} = shift() 0 0 0
1251 0 $old
1252 }
1253  
1254 # ------------- History object ------------- #
1255  
1256 package WWW::Scripter::History;
1257  
1258 26 <<'mldistwatch' if 0;
1259 use WWW::Scripter; $VERSION = $WWW'Scripter'VERSION;
1260 mldistwatch
1261 26 our $VERSION = $WWW'Scripter'VERSION;
1262  
1263 26 ▶BEGIN { *fieldhashes = *WWW::Scripter::fieldhashes }
Subroutine BEGIN: called CC=1 SCAR=0.0
1264 26 ▶use HTML::DOM::Interface qw 'NUM STR READONLY METHOD VOID';
Subroutine BEGIN: called CC=1 SCAR=0.0
1265 26 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
1266  
1267 =begin comment
1268  
1269 History notes
1270  
1271 A history object is a blessed array ref. That array ref holds the browser
1272 history entries. Each entry is itself an array ref containing:
1273  
1274 0 - request object
1275 1 - response object
1276 2 - URL
1277 3 - state info
1278 4 - title
1279  
1280 The length of the array tells us whether it is a state-info entry. The URL
1281 is used both for fragments and for state objects. The second element will
1282 be blank if it has been erased because of max_docs.
1283  
1284 The history object has a pointer to the ‘current’ history item
1285 ($index{$self}).
1286  
1287 Document objects are referenced by response: $document{$response}. The
1288 window’s ‘document’ method is inherited from HTML::DOM::View, and we set it
1289 whenever history is browsed, retrieving it from %document.
1290  
1291 The ‘unbrowsed’ state that used to be mentioned in HTML 5 (before it got
1292 really convoluted) is represented by an empty array. An empty array can
1293 exist alongside other entries, as we add one when we simulate a
1294 new window in single-window mode.
1295  
1296 Response objects are also listed in the array ref stored in $res{$self} in
1297 the order in which they were accessed. Subroutines that add to this array
1298 then call _clean($self), which then eliminates duplicate entries and
1299 deletes from the history object itself as many of the oldest response
1300 objects as are necessary to satisfy max_docs.
1301  
1302 =end comment
1303  
1304 =cut
1305  
1306 $$_{~~__PACKAGE__} = 'History',
1307 $$_{History} = {
1308 length => NUM|READONLY,
1309 index => NUM|READONLY,
1310 userAgent => STR|READONLY,
1311 go => METHOD|VOID,
1312 back => METHOD|VOID,
1313 forward => METHOD|VOID,
1314 pushState => METHOD|VOID,
1315 }
1316 26 for \%WWW::Scripter::Interface;
1317  
1318 26 fieldhashes \my ( %w, %index, %res );
1319  
1320 sub new {
1321 26 ▶ my ($pack,$mech) = @_;
Subroutine new: called CC=1 SCAR=0.0
1322 26 my $self = bless [[]], $pack;
1323 26 weaken(${$w{$self}} = $mech);
1324 26 $index{$self} = 0;
1325 26 $res{$self} = [];
1326 26 $self
1327 }
1328  
1329 sub _add {
1330 0 ▶ my $self = shift;
Subroutine _add: not called CC=4 SCAR=30.0
1331 0 ▶ if(defined $$self[-1][0]) { # if there is no ‘undef’ entry
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[-1][0]) { } 0 0 0
1332 0 splice @$self, ++$index{$self};
1333 0 push @$self, \@_;
1334 0 ▶ $_[1] and push(@{$res{$self}}, $_[1]), _clean($self,1);
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and push(@{$res{$self};}, $_[1]), _clean($self, 1) 0 0 0
1335 }
1336 else {
1337 0 $$self[-1] = \@_;
1338 0 ▶ push @{$res{$self}}, $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
1339 }
1340 }
1341  
1342 # Called when browsing to a stale history entry and also by
1343 # location->replace
1344 sub _replace {
1345 0 ▶ my $self = shift;
Subroutine _replace: not called CC=4 SCAR=30.0
1346 0 ▶ if(defined $$self[-1][0]) { # if browsing has occurred
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[-1][0]) { } 0 0 0
1347 0 $$self[$index{$self}] = \@_;
1348 0 ▶ $_[1] and push(@{$res{$self}}, $_[1]), _clean($self);
Branch: 1 branch
BranchTrueFalseTotal
$_[1] and push(@{$res{$self};}, $_[1]), _clean($self) 0 0 0
1349 }
1350 else {
1351 0 $$self[-1] = \@_;
1352 0 ▶ push @{$res{$self}}, $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
1353 }
1354 }
1355  
1356 sub _delete_res {
1357 0 ▶ delete $_[0][$index{$_[0]}][1];
Subroutine _delete_res: not called CC=1 SCAR=6.9
1358 }
1359  
1360 sub _clear { # called by Scripter->clear_history
1361 0 ▶ my $self = shift;
Subroutine _clear: not called CC=2 SCAR=17.9
1362 0 ▶ @$self = shift() ? undef : $$self[$index{$self}];
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 0 0 0
1363 0 $index{$self} = 0;
1364 }
1365  
1366 sub length {
1367 0 ▶ scalar @{+shift}
Subroutine length: not called CC=1 SCAR=6.9
1368 }
1369  
1370 sub index { # ~~~ We can probably make this modifiable later.
1371 $index{+shift}
1372 0 ▶}
Subroutine index: not called CC=1 SCAR=6.9
1373  
1374 sub go {
1375 0 ▶ my $self = shift;
Subroutine go: not called CC=5 SCAR=34.0
1376 0 ▶ if(0==$_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == $_[0]) { } 0 0 0
1377 0 ${$w{$self}}->reload;
1378 }
1379 else {
1380 0 my $new_pos = $index{$self}+shift;
1381 0 ▶ $new_pos < 0 || $new_pos > $#$self and return;
Branch: 1 branch
BranchTrueFalseTotal
$new_pos < 0 || $new_pos > $self->$#* and return 0 0 0
Condition0%0/3
$new_pos < 0 or $new_pos > $self->$#*
l!l&&r!l&&!r
000
MC/DC0%0/2
$new_pos < 0 or $new_pos > $self->$#*
$new_pos < 0 $new_pos > $self->$#*
Truth table0%0/3
A or B
A= $new_pos < 0B= $new_pos > $self->$#*
ABresult
1X1
011
000
1382 0 $index{$self} = $new_pos;
1383  
1384 # ~~~ trigger popstate
1385  
1386 # If there is a response object, we just reset the page from that. If
1387 # there isn’t then this is a stale entry and we need to
1388 # re-fetch the page.
1389 0 my $entry = $$self[$new_pos];
1390 0 ▶ if(defined $$entry[1]) { # response
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry->[1]) { } 0 0 0
1391 0 ${$w{$self}}->_update_page(@$entry)
1392 }
1393 else {
1394 0 local(my $w = ${$w{$self}})->{Scripter_replace} = 1;
1395 0 $w->request($$entry[0]);
1396 }
1397 }
1398 0 return;
1399 }
1400  
1401 0 ▶sub back { shift->go(-1) }
Subroutine back: not called CC=1 SCAR=6.9
1402 0 ▶sub forward { shift->go(1) }
Subroutine forward: not called CC=1 SCAR=6.9
1403  
1404 sub pushState {
1405 0 ▶ my $self = shift;
Subroutine pushState: not called CC=5 SCAR=34.0
1406  
1407 0 my $index = $index{$self}++;
1408 0 my($req,$res) = @{$$self[$index]}[0,1];
1409  
1410 # count future entries that share the same doc
1411 0 my $to_delete;
1412 0 for($index+1..$#$self) {
1413 0 ▶ ($$self[$_][1]||0) == $res ? ++$to_delete : last;
Branch: 1 branch
BranchTrueFalseTotal
($self->[$_][1] || 0) == $res ? : 0 0 0
Condition0%0/2
$self->[$_][1] || 0
l!l
00
MC/DC0%0/1
$self->[$_][1] || 0
$self->[$_][1]
Truth table0%0/2
A
A= $self->[$_][1]
Aresult
11
00
1414 }
1415  
1416 # replace those future entries with the new item
1417 0 ▶ splice @$self, $index+1, $to_delete||0, [ $req, $res, $_[2], @_ ];
Condition0%0/2
$to_delete || 0
l!l
00
MC/DC0%0/1
$to_delete || 0
$to_delete
Truth table0%0/2
A
A= $to_delete
Aresult
11
00
1418  
1419 0 _clean($self);
1420  
1421 0 return;
1422 }
1423  
1424 sub _clean {
1425 0 ▶ my($self, $check_max_hist) = @_;
Subroutine _clean: not called CC=14 SCAR=53.5
1426 0 ▶ if($check_max_hist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_max_hist) 0 0 0
1427 0 my $max = (my $w = ${$w{$self}})->{Scripter_max_hist};
1428 0 ▶ if($max && @$self > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max and @$self > $max) 0 0 0
Condition0%0/3
$max and @$self > $max
!ll&&!rl&&r
000
MC/DC0%0/2
$max and @$self > $max
$max @$self > $max
Truth table0%0/3
A and B
A= $maxB= @$self > $max
ABresult
0X0
100
111
1429 0 my $diff = @$self-$max;
1430 0 $index{$self} -= $diff;
1431 0 splice @$self, 0, $diff;
1432 }
1433 }
1434 0 my $max = ${$w{$self}}->stack_depth + 1;
1435 0 my $res = $res{$self};
1436 0 my %res;
1437 0 for(@$self) {
1438 0 ▶ defined $$_[1] and $res{0+$$_[1]}++
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[1] and ++$res{0 + $_->[1]} 0 0 0
1439 }
1440 0 ▶ if($max) { # ~~~ It may be more efficient if, instead of searching for
Branch: 1 branch
BranchTrueFalseTotal
if ($max) { } 0 0 0
1441 0 my @res; # duplicates here, we scan for the ones we know we’ve added
1442 my %seen; # in _add and _replace.
1443 0 for(reverse @$res) {
1444 0 my $refaddr = 0+$_;
1445 0 ▶ unshift @res, $_ if exists $res{$refaddr} && !$seen{$refaddr}++;
Branch: 1 branch
BranchTrueFalseTotal
if exists $res{$refaddr} and not $seen{$refaddr}++ 0 0 0
Condition0%0/3
exists $res{$refaddr} and not $seen{$refaddr}++
!ll&&!rl&&r
000
MC/DC0%0/2
exists $res{$refaddr} and not $seen{$refaddr}++
exists $res{$refaddr} not $seen{$refaddr}++
Truth table0%0/3
A and not(B)
A= exists $res{$refaddr}B= not $seen{$refaddr}++
ABresult
0X0
100
111
1446 }
1447 0 ▶ @$res = @res, return unless @res > $max;
Branch: 1 branch
BranchTrueFalseTotal
unless @res > $max 0 0 0
1448 0 my $diff = @res-$max;
1449 0 my %to_delete;
1450 0 @to_delete{map 0+$_, splice @res, 0,$diff}=();
1451 0 @$res = @res;
1452 0 for(@$self) {
1453 0 ▶ next unless defined $$_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_->[1] 0 0 0
1454 0 ▶ delete $$_[1] if exists $to_delete{0+$$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $to_delete{0 + $_->[1]} 0 0 0
1455 }
1456 }
1457 else {
1458 0 @$res = grep exists $res{refaddr $_}, @$res;
1459 }
1460 }
1461  
1462 sub _uri {
1463 0 ▶ my $self = shift;
Subroutine _uri: not called CC=2 SCAR=17.9
1464 0 ▶ $$self[$index{$self}][2] || ${$w{$self}}->uri;
Branch: 1 branch
BranchTrueFalseTotal
$$self[$index{$self}][2] or ${$w{$self};}->uri 0 0 0
1465 }
1466  
1467 # ~~~
1468  
1469 # ------------- Location object ------------- #
1470  
1471 package WWW'Scripter'Location;
1472  
1473 26 ▶use HTML::DOM::Interface qw'STR METHOD VOID';
Subroutine BEGIN: called CC=1 SCAR=0.0
1474 26 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
1475  
1476 26 ▶use overload fallback => 1, '""' => sub{${+shift}->history->_uri};
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
1477  
1478 $$_{~~__PACKAGE__} = 'Location',
1479 $$_{Location} = {
1480 assign => VOID|METHOD,
1481 hash => STR,
1482 host => STR,
1483 hostname => STR,
1484 href => STR,
1485 pathname => STR,
1486 port => STR,
1487 protocol => STR,
1488 search => STR,
1489 reload => VOID|METHOD,
1490 replace => VOID|METHOD,
1491 }
1492 26 for \%WWW::Scripter::Interface;
1493  
1494 sub new { # usage: new .....::Location $mech
1495 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
1496 0 weaken (my $mech = shift);
1497 0 my $self = bless \$mech, $class;
1498 0 $self;
1499 }
1500  
1501 sub hash {
1502 0 ▶ my $loc = shift;
Subroutine hash: not called CC=5 SCAR=34.0
1503 0 my $old = (my $uri = $$loc->history->_uri)->fragment;
1504 0 ▶ $old = "#$old" if defined $old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old 0 0 0
1505 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1506 0 shift() =~ /#?(.*)/s;
1507 0 (my $uri_copy = $uri->clone)->fragment($1);
1508 0 ▶ $uri_copy->eq($uri) or $$loc->get($uri_copy);
Branch: 1 branch
BranchTrueFalseTotal
$uri_copy->eq($uri) or $$loc->get($uri_copy) 0 0 0
1509 }
1510 0 ▶ $old||''
Branch: 1 branch
BranchTrueFalseTotal
$old or "" 0 0 0
1511 }
1512  
1513 sub host {
1514 0 ▶ my $loc = shift;
Subroutine host: not called CC=3 SCAR=24.8
1515 0 my $uri = $$loc->history->_uri;
1516 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1517 0 (my $uri = $uri->clone)->port("");
1518 0 $uri->host_port(shift);
1519 0 $$loc->get($uri);
1520 }
1521 0 ▶ defined wantarray ? $uri->host_port : ()
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
1522 }
1523  
1524 sub hostname {
1525 0 ▶ my $loc = shift;
Subroutine hostname: not called CC=3 SCAR=24.8
1526 0 my $uri = $$loc->history->_uri;
1527 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1528 0 (my $uri = $uri->clone)->host(shift);
1529 0 $$loc->get($uri);
1530 }
1531 0 ▶ defined wantarray ? $uri->host : ()
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
1532 }
1533  
1534 sub href {
1535 0 ▶ my $loc = shift;
Subroutine href: not called CC=3 SCAR=24.8
1536 0 ▶ my $old = $$loc->history->_uri->as_string if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
1537 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1538 0 $$loc->get(shift);
1539 }
1540 0 $old;
1541 }
1542  
1543 0 ▶sub assign { ${$_[0]}->get($_[1]); () }
Subroutine assign: not called CC=1 SCAR=6.9
1544  
1545 sub pathname {
1546 0 ▶ my $loc = shift;
Subroutine pathname: not called CC=3 SCAR=24.8
1547 0 my $uri = $$loc->history->_uri;
1548 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1549 0 (my $uri = $uri->clone)->path(shift);
1550 0 $$loc->get($uri);
1551 }
1552 0 ▶ defined wantarray ? $uri->path : ()
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
1553 }
1554  
1555 sub port {
1556 0 ▶ my $loc = shift;
Subroutine port: not called CC=3 SCAR=24.8
1557 0 my $uri = $$loc->history->_uri;
1558 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1559 0 (my $uri = $uri->clone)->port(shift);
1560 0 $$loc->get($uri);
1561 }
1562 0 ▶ defined wantarray ? $uri->port : ()
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
1563 }
1564  
1565 sub protocol {
1566 0 ▶ my $loc = shift;
Subroutine protocol: not called CC=3 SCAR=24.8
1567 0 my $uri = $$loc->history->_uri;
1568 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1569 0 shift() =~ /(.*):?/s;
1570 0 (my $uri = $uri->clone)->scheme($1);
1571 0 $$loc->get($uri);
1572 }
1573 0 ▶ defined wantarray ? $uri->scheme . ':' : ()
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
1574 }
1575  
1576 sub search {
1577 0 ▶ my $loc = shift;
Subroutine search: not called CC=6 SCAR=37.4
1578 0 my $uri = $$loc->history->_uri;
1579 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1580 0 shift() =~ /(\??)(.*)/s;
1581 (
1582 0 ▶ my $uri_copy = $uri->clone
Branch: 1 branch
BranchTrueFalseTotal
$1 || length $2 ? : 0 0 0
Condition0%0/3
$1 or length $2
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 or length $2
$1 length $2
Truth table0%0/3
A or B
A= $1B= length $2
ABresult
1X1
011
000
1583 )->query(
1584 $1||length$2 ? "$2" : undef
1585 );
1586 0 $$loc->get($uri_copy);
1587 }
1588 0 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
1589 0 my $q = $uri->query;
1590 0 ▶ defined $q ? "?$q" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $q ? : 0 0 0
1591 }
1592  
1593  
1594 # ~~~ Safari doesn't support forceGet. Do I need to?
1595 sub reload { # args (forceGet)
1596 0 ▶ ${+shift}->reload
Subroutine reload: not called CC=1 SCAR=6.9
1597 }
1598 sub replace { # args (URL)
1599 0 ▶ my $mech = ${+shift};
Subroutine replace: not called CC=1 SCAR=6.9
1600 0 local $$mech{Scripter_replace } = 1;
1601 0 $mech->get(shift);
1602 }
1603  
1604  
1605 # ------------- Navigator object ------------- #
1606  
1607 package WWW::Scripter::Navigator;
1608  
1609 26 ▶use HTML::DOM::Interface qw'STR READONLY METHOD BOOL';
Subroutine BEGIN: called CC=1 SCAR=0.0
1610 26 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
1611  
1612 $$_{~~__PACKAGE__} = 'Navigator',
1613 $$_{Navigator} = {
1614 appName => STR|READONLY,
1615 appCodeName => STR|READONLY,
1616 appVersion => STR|READONLY,
1617 userAgent => STR|READONLY,
1618 javaEnabled => METHOD|BOOL,
1619 platform => STR|READONLY,
1620 taintEnabled => METHOD|BOOL,
1621 cookieEnabled => BOOL|READONLY,
1622 }
1623 26 for \%WWW::Scripter::Interface;
1624  
1625 26 use constant 1.03 our $_const = {
1626 mech => 0,
1627 name => 1,
1628 vers => 2,
1629 cnam => 3,
1630 plat => 4,
1631 26 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
1632 26 ▶{ no strict; delete @{__PACKAGE__.::}{_const => keys %$_const} }
Subroutine BEGIN: called CC=1 SCAR=0.0
1633  
1634 sub new {
1635 0 ▶ weaken((my $self = bless[],pop)->[mech] = pop);
Subroutine new: not called CC=1 SCAR=6.9
1636 0 $self;
1637 }
1638  
1639 sub appName {
1640 0 ▶ my $self = shift;
Subroutine appName: not called CC=3 SCAR=24.8
1641 0 my $old = $self->[name];
1642 0 ▶ defined $old or $old = ref $self->[mech];
Branch: 1 branch
BranchTrueFalseTotal
defined $old or $old = ref $self->[0] 0 0 0
1643 0 ▶ @_ and $self->[name] = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->[1] = shift() 0 0 0
1644 0 return $old;
1645 }
1646  
1647 sub appCodeName {
1648 0 ▶ my $self = shift;
Subroutine appCodeName: not called CC=3 SCAR=24.8
1649 0 my $old = $self->[cnam];
1650 0 ▶ defined $old or $old = ref $self->[mech];
Branch: 1 branch
BranchTrueFalseTotal
defined $old or $old = ref $self->[0] 0 0 0
1651 0 ▶ @_ and $self->[cnam] = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->[3] = shift() 0 0 0
1652 0 return $old;
1653 }
1654  
1655 sub appVersion {
1656 0 ▶ my $self = shift;
Subroutine appVersion: not called CC=5 SCAR=34.0
1657 0 my $old = $self->[vers];
1658 0 ▶ if(!defined $old and defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old and defined wantarray) 0 0 0
Condition0%0/3
not defined $old and defined wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $old and defined wantarray
not defined $old defined wantarray
Truth table0%0/3
not(A) and B
A= not defined $oldB= defined wantarray
ABresult
0X0
100
111
1659 0 $old = $self->userAgent;
1660 0 ▶ $old =~ /(\d.*)/s
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /(\d.*)/s ? : 0 0 0
1661 ? $old = $1
1662 : $old = ref($self->[mech])->VERSION;
1663 }
1664 0 ▶ @_ and $self->[vers] = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->[2] = shift() 0 0 0
1665 0 return $old;
1666 }
1667  
1668 sub userAgent {
1669 0 ▶ shift->[mech]->agent;
Subroutine userAgent: not called CC=1 SCAR=6.9
1670 }
1671  
1672 sub platform {
1673 0 ▶ my $self = shift;
Subroutine platform: not called CC=13 SCAR=49.6
1674 0 my $old = $self->[plat];
1675 0 ▶ if(!defined $old and defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old and defined wantarray) 0 0 0
Condition0%0/3
not defined $old and defined wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $old and defined wantarray
not defined $old defined wantarray
Truth table0%0/3
not(A) and B
A= not defined $oldB= defined wantarray
ABresult
0X0
100
111
1676 0 my $ua = $self->[mech]->agent;
1677 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1678 0 ▶ $old
Branch: 9 branches
BranchTrueFalseTotal
$ua =~ /\bWin(?:dows|32)?\b/ ? : 0 0 0
$ua =~ /\bMac(?:intosh)\b/ ? : 0 0 0
$ua =~ /\bIntel\b/ ? : 0 0 0
$ua =~ /\b(FreeBSD(?: i386)?|Linux)\b/ ? : 0 0 0
$^O eq 'MSWin32' ? : 0 0 0
$^O eq 'MacOS' ? : 0 0 0
$^O eq 'freebsd' ? : 0 0 0
$^O eq 'linux' ? : 0 0 0
$^O ne 'darwin' ? : 0 0 0
1679 = $ua =~ /\bWin(?:dows|32)?\b/ ? 'Win32'
1680 : $ua =~ /\bMac(?:intosh)\b/ ? $ua =~ /\bIntel\b/
1681 ? 'MacIntel' : 'MacPPC'
1682 : $ua =~ /\b(FreeBSD(?: i386)?|Linux)\b/
1683 ? $1
1684 : $^O eq 'MSWin32' ? 'Win32'
1685 : $^O eq 'MacOS' ? 'MacPPC'
1686 : $^O eq 'freebsd' ? 'FreeBSD'
1687 : $^O eq 'linux' ? 'Linux'
1688 : $^O ne 'darwin' ? $^O
1689 : pack "s", 28526, eq 'on' ? 'MacPPC' : 'MacIntel';
1690 }
1691 0 ▶ @_ and $self->[plat] = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->[4] = shift() 0 0 0
1692 0 return $old;
1693 }
1694  
1695 ▶sub javaEnabled{}
Subroutine javaEnabled: not called CC=1 SCAR=0.0
1696 26 *taintEnabled=*javaEnabled;
1697  
1698 0 ▶sub cookieEnabled { defined $_[0][mech]->cookie_jar }
Subroutine cookieEnabled: not called CC=1 SCAR=6.9
1699  
1700 # ------------- about: protocol ------------- #
1701  
1702 package WWW'Scripter'_about_protocol;
1703  
1704 # ~~~ This method may be a bad idea if someone else wants to implement
1705 # other aspects of the about: protocol. Maybe we should use an LWP
1706 # handler. (Then we would, of course, require a later LWP.)
1707  
1708 26 <<'mldistwatch' if 0;
1709 use WWW::Scripter; $VERSION = $WWW'Scripter'VERSION;
1710 mldistwatch
1711 26 our $VERSION = $WWW'Scripter'VERSION;
1712  
1713 26 ▶use LWP::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
1714  
1715 26 our @ISA = LWP::Protocol::;
1716  
1717 26 LWP::Protocol'implementor about => __PACKAGE__;
1718  
1719 sub request { # based on the one in LWP::Protocol::file
1720 0 ▶ my($self, $request, $proxy, $arg) = @_;
Subroutine request: not called CC=4 SCAR=30.0
1721  
1722 0 ▶ if(defined $proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proxy) 0 0 0
1723 0 return new HTTP::Response 400,,
1724 'The about: protocol does not work with proxies';
1725 }
1726  
1727 0 my $url= $request->url;
1728 0 my $scheme = $url->scheme;
1729  
1730 0 ▶ if ($scheme ne 'about') {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme ne "about") 0 0 0
1731 0 return new HTTP::Response 500,
1732 "WWW::Scripter::_about_protocol called for $scheme";
1733 }
1734  
1735 0 ▶ return new HTTP::Response 404,
Branch: 1 branch
BranchTrueFalseTotal
unless $url eq "about:blank" 0 0 0
1736 "Nothing exists at $url" unless $url eq 'about:blank';
1737  
1738 0 my $response = new HTTP::Response 200, 'OK', [
1739 Content_Length=>0,
1740 Content_Type =>'text/html',
1741 ];
1742  
1743 0 ▶ $self->collect($arg, $response, sub {\''});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1744 }
1745  
1746 # ------------- Link and image lists for Mech ------------- #
1747  
1748 package WWW::Scripter::Links;
1749  
1750 26 ▶BEGIN { eval "require ".WWW'Scripter'Mech."::Link" or die $@ }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
eval "require WWW::Mechanize::Link" or die $@ 0 26 26
1751  
1752 sub TIEARRAY {
1753 0 ▶ bless \(my $links = pop), shift;
Subroutine TIEARRAY: not called CC=1 SCAR=6.9
1754 }
1755  
1756 sub FETCH {
1757 0 ▶ my $link = ${$_[0]}->[$_[1]];
Subroutine FETCH: not called CC=1 SCAR=6.9
1758 0 my $mech_link = bless [], WWW'Scripter'Mech."::Link";
1759 0 tie @$mech_link, WWW'Scripter'Link::, $link;
1760 0 $dom_obj{$mech_link} = $link;
1761 0 $mech_link;
1762 }
1763 0 ▶sub FETCHSIZE { scalar @${$_[0]} }
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
1764 0 ▶sub EXISTS { exists ${$_[0]}->links->[$_[1]] }
Subroutine EXISTS: not called CC=1 SCAR=6.9
1765  
1766 package WWW::Scripter::Link;
1767  
1768 0 ▶sub TIEARRAY { bless \(my $x = $_[1]) }
Subroutine TIEARRAY: not called CC=1 SCAR=6.9
1769 sub FETCH {
1770 0 ▶ my $self = shift;
Subroutine FETCH: not called CC=12 SCAR=50.5
1771 0 for(shift) {
1772 return
1773 $_ == 0 ? $$self->tag eq 'meta' # url
1774 ? $$self->attr('content') =~ /^\d+\s*;\s*url\s*=\s*(\S+)/i
1775 0 ? do { my $url = $1;
1776 0 ▶ $url =~ s/^"(.+)"$/$1/ or $url =~ s/^'(.+)'$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ s/^"(.+)"$/$1/ or $url =~ s/^'(.+)'$/$1/ 0 0 0
1777 0 ▶ $url }
Branch: 6 branches
BranchTrueFalseTotal
$_ == 1 ? : 0 0 0
$$self->tag eq 'a' ? : 0 0 0
$_ == 2 ? : 0 0 0
$_ == 3 ? : 0 0 0
$_ == 4 ? : 0 0 0
$_ == 5 ? : 0 0 0
1778 : undef
1779 0 ▶ : $$self->attr($link_tags{$$self->tag}) :
Branch: 3 branches
BranchTrueFalseTotal
$_ == 0 ? : 0 0 0
$$self->tag eq 'meta' ? : 0 0 0
$$self->attr('content') =~ /^\d+\s*;\s*url\s*=\s*(\S+)/i ? : 0 0 0
1780 $_ == 1 ? $$self->tag eq 'a' ? $$self->as_text : undef : # text
1781 $_ == 2 ? $$self->attr('name') : # name
1782 $_ == 3 ? $$self->tag : # tag
1783 $_ == 4 ? $$self->ownerDocument->base : # base
1784 $_ == 5 ? {$$self->all_external_attr} : # attrs
1785 undef
1786 }
1787 }
1788 0 ▶sub FETCHSIZE { 6 }
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
1789  
1790 package WWW::Scripter::Images;
1791  
1792 26 ▶BEGIN { eval "require ".WWW'Scripter'Mech."::Image" or die $@ }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
eval "require WWW::Mechanize::Image" or die $@ 0 26 26
1793  
1794 sub TIEARRAY {
1795 0 ▶ bless \(my $links = pop), shift;
Subroutine TIEARRAY: not called CC=1 SCAR=6.9
1796 }
1797  
1798 sub FETCH {
1799 0 ▶ my $img = ${$_[0]}->[$_[1]];
Subroutine FETCH: not called CC=1 SCAR=6.9
1800 0 my $mech_img = new WWW'Scripter'Image:: $img;
1801 0 $dom_obj{$mech_img} = $img;
1802 0 $mech_img;
1803 }
1804 0 ▶sub FETCHSIZE { scalar @${$_[0]} }
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
1805 0 ▶sub EXISTS { exists ${$_[0]}->links->[$_[1]] }
Subroutine EXISTS: not called CC=1 SCAR=6.9
1806  
1807 package WWW::Scripter::Image;
1808 26 our @ISA = WWW::Scripter::Mech."::Image";
1809 0 ▶sub new { bless \(my $frin = pop) }
Subroutine new: not called CC=1 SCAR=6.9
1810 0 ▶sub url { ${$_[0]}->attr('src') }
Subroutine url: not called CC=1 SCAR=6.9
1811 0 ▶sub base { ${$_[0]}-ownerDocument->base }
Subroutine base: not called CC=1 SCAR=6.9
1812 0 ▶sub name { ${$_[0]}->attr('name') }
Subroutine name: not called CC=1 SCAR=6.9
1813 0 ▶sub tag { ${$_[0]}->tag }
Subroutine tag: not called CC=1 SCAR=6.9
1814 0 ▶sub height { ${$_[0]}->attr('height') }
Subroutine height: not called CC=1 SCAR=6.9
1815 0 ▶sub width { ${$_[0]}->attr('width') }
Subroutine width: not called CC=1 SCAR=6.9
1816 0 ▶sub alt { ${$_[0]}->attr('alt') }
Subroutine alt: not called CC=1 SCAR=6.9
1817  
1818  
1819 # ------------- Frames list ------------- #
1820  
1821 package WWW::Scripter::Frames;
1822  
1823 # ~~~ This is horribly inefficient and clunky. It probably needs to be
1824 # programmed in full here, or at least the ‘Collection’ part (a tiny
1825 # bit of copy&paste).
1826  
1827 26 ▶use HTML::DOM::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
1828 26 ▶use HTML::DOM::NodeList::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
1829 26 our @ISA = "HTML::DOM::Collection";
1830  
1831 {
1832 26 WWW::Scripter'fieldhash my %w;
1833 26 my @empty_array;
1834
1835 sub new {
1836 0 ▶ ; my($pack,$window,$doc) = @_
Subroutine new: not called CC=3 SCAR=24.8
1837 ; my $ret = $pack->SUPER'new(
1838 $doc
1839 ? HTML::DOM::NodeList::Magic->new(
1840 0 ▶ sub { $doc->look_down(_tag => qr/^i?frame\z/) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1841 0 ▶ $doc
Branch: 1 branch
BranchTrueFalseTotal
$doc ? : 0 0 0
1842 )
1843 : HTML'DOM'NodeList->new(\@empty_array)
1844 )
1845 0 ; Scalar'Util'weaken($_) for $doc, $window;
1846 0 ; $w{$ret} = \$window;
1847 0 ; $ret
1848 }
1849
1850 0 ▶ sub window { ${$w{+shift}||return undef} }
Subroutine window: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$w{shift()} or return undef 0 0 0
1851 }
1852  
1853 26 use overload fallback => 1,'@{}' => sub {
1854 0 ▶ [map $_->contentWindow, @{shift->${\'SUPER::(@{}'}}]
Subroutine __ANON__: not called CC=1 SCAR=6.9
1855 26 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
1856  
1857 0 ▶sub FETCH { (shift->SUPER::FETCH(@_)||return)->contentWindow }
Subroutine FETCH: not called CC=2 SCAR=17.9
Condition0%0/2
(shift())->SUPER::FETCH(@_) || (return)
l!l
00
MC/DC0%0/1
(shift())->SUPER::FETCH(@_) || (return)
(shift())->SUPER::FETCH(@_)
Truth table0%0/2
A
A= (shift())->SUPER::FETCH(@_)
Aresult
11
00
1858  
1859  
1860 26 ▶!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!*!!*!
Subroutine BEGIN: called CC=1 SCAR=0.0
↑ Summary Scripter/WindowGroup.pm »