Branch Coverage

blib/lib/WWW/Mechanize.pm
Criterion Covered Total %
branch 426 492 86.5


line true false branch
33 75 0 $class eq 'WWW::Mechanize' ? :
50 19 41 if (exists $mech_params{$key}) { }
66 75 0 unless $mech_params{'noproxy'}
70 0 75 unless defined $self->{'proxy'}
95 1 1 if (defined $known_agents{$alias}) { }
115 0 140 if ref $uri eq "WWW::Mechanize::Link"
117 85 55 $self->base ? :
131 0 1 if ref $uri eq "WWW::Mechanize::Link"
133 1 0 $self->base ? :
147 0 0 if ref $uri eq "WWW::Mechanize::Link"
149 0 0 $self->base ? :
172 0 2 if ref $uri eq "WWW::Mechanize::Link"
174 2 0 $self->base ? :
187 1 3 unless my $req = $self->{'req'}
213 3 24 unless $stack and @{$stack;}
239 1 14 unless $self->{'req'} and $self->{'res'}
243 1 13 unless $stack
253 1 9 unless $self->{'req'} and $self->{'res'}
255 8 1 if ($n == 0)
260 1 0 unless $stack and @$stack >= $n
276 50 1 $self->response ? :
295 2 21 unless $self->is_html
297 20 1 unless (defined $self->{'title'})
319 1 118 if (delete $params{'raw'}) { }
2 116 elsif (delete $params{'decoded_by_headers'}) { }
1 115 elsif (my $charset = delete $params{'charset'}) { }
106 9 elsif ($self->is_html) { }
329 2 104 if (exists $params{'base_href'})
334 2 104 if (my $format = delete $params{'format'})
335 1 1 if ($format eq 'text') { }
353 2 1 unless (defined $self->{'text'})
354 2 0 unless (exists $INC{'HTML::TreeBuilder'})
382 26 54 unless $self->{'links'}
384 80 0 if wantarray
391 1 15 if @_ % 2
394 0 15 if ($params{'n'} eq "all")
400 10 5 if ($link)
404 1 4 if ($self->{'autocheck'})
420 3 70 unless my(@links) = $self->links
425 107 463 if (_match_any_link_params($link, \%params))
426 23 84 if ($wantall) { }
431 55 29 if $nmatches >= $params{'n'}
436 6 9 if ($wantall)
437 4 2 if wantarray
451 0 570 unless keys %$p
453 93 477 if defined $p->{'url'} and not $link->url eq $p->{'url'}
454 63 414 if defined $p->{'url_regex'} and not $link->url =~ /$p->{'url_regex'}/
455 26 388 if defined $p->{'url_abs'} and not $link->url_abs eq $p->{'url_abs'}
456 24 364 if defined $p->{'url_abs_regex'} and not $link->url_abs =~ /$p->{'url_abs_regex'}/
457 67 297 if defined $p->{'text'} and not defined $link->text && $link->text eq $p->{'text'}
458 145 152 if defined $p->{'text_regex'} and not defined $link->text && $link->text =~ /$p->{'text_regex'}/
459 9 143 if defined $p->{'name'} and not defined $link->name && $link->name eq $p->{'name'}
460 15 128 if defined $p->{'name_regex'} and not defined $link->name && $link->name =~ /$p->{'name_regex'}/
461 4 124 if defined $p->{'tag'} and not $link->tag && $link->tag eq $p->{'tag'}
462 4 120 if defined $p->{'tag_regex'} and not $link->tag && $link->tag =~ /$p->{'tag_regex'}/
464 3 117 if defined $p->{'id'} and not $link->attrs->{'id'} && $link->attrs->{'id'} eq $p->{'id'}
465 3 114 if defined $p->{'id_regex'} and not $link->attrs->{'id'} && $link->attrs->{'id'} =~ /$p->{'id_regex'}/
466 1 113 if defined $p->{'class'} and not $link->attrs->{'class'} && $link->attrs->{'class'} eq $p->{'class'}
467 1 112 if defined $p->{'class_regex'} and not $link->attrs->{'class'} && $link->attrs->{'class'} =~ /$p->{'class_regex'}/
469 3 109 if defined $p->{'rel'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} eq $p->{'rel'}
470 2 107 if defined $p->{'rel_regex'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} =~ /$p->{'rel_regex'}/
485 5 232 unless ($key =~ qr/$rx_keyname/)
494 49 183 if ($key_regex) { }
495 6 43 unless ($val_regex)
502 5 178 if ($val_regex)
507 5 173 if ($val =~ /^\s|\s$/)
530 0 8 unless my $form = $self->current_form
544 11 11 unless $matched
546 23 11 if $matched
563 4 51 unless $self->{'images'}
565 54 1 if wantarray
578 0 50 unless my(@images) = $self->images
583 87 342 if (_match_any_image_params($image, \%params))
584 66 21 if ($wantall) { }
589 20 1 if $nmatches >= $params{'n'}
594 18 12 if ($wantall)
595 17 1 if wantarray
609 0 429 unless keys %$p
611 42 387 if defined $p->{'url'} and not defined $image->url && $image->url eq $p->{'url'}
612 33 354 if defined $p->{'url_regex'} and not defined $image->url && $image->url =~ /$p->{'url_regex'}/
613 30 324 if defined $p->{'url_abs'} and not defined $image->url_abs && $image->url_abs eq $p->{'url_abs'}
614 25 299 if defined $p->{'url_abs_regex'} and not defined $image->url_abs && $image->url_abs =~ /$p->{'url_abs_regex'}/
615 24 275 if defined $p->{'alt'} and not defined $image->alt && $image->alt eq $p->{'alt'}
616 24 251 if defined $p->{'alt_regex'} and not defined $image->alt && $image->alt =~ /$p->{'alt_regex'}/
617 39 212 if defined $p->{'tag'} and not $image->tag && $image->tag eq $p->{'tag'}
618 16 196 if defined $p->{'tag_regex'} and not $image->tag && $image->tag =~ /$p->{'tag_regex'}/
619 27 169 if defined $p->{'id'} and not $image->attrs && $image->attrs->{'id'} && $image->attrs->{'id'} eq $p->{'id'}
620 26 143 if defined $p->{'id_regex'} and not $image->attrs && $image->attrs->{'id'} && $image->attrs->{'id'} =~ /$p->{'id_regex'}/
621 27 116 if defined $p->{'class'} and not $image->attrs && $image->attrs->{'class'} && $image->attrs->{'class'} eq $p->{'class'}
622 29 87 if defined $p->{'class_regex'} and not $image->attrs && $image->attrs->{'class'} && $image->attrs->{'class'} =~ /$p->{'class_regex'}/
639 75 82 unless $self->{'forms'}
641 65 90 if wantarray
648 30 132 unless ($self->{'current_form'})
661 48 2 if ($$forms[$form - 1])
665 1 47 wantarray ? :
668 0 2 wantarray ? :
676 15 0 if defined($temp = $_->action)
679 2 1 if ($nmatches > 0)
680 1 1 if ($nmatches > 1)
698 2 4 unless defined(my $form = $self->form_with("id", $formid, $args || ()))
707 1 20 unless scalar @fields
713 124 47 unless grep {$_ eq $field;} @fields_in_form
724 2 10 unless scalar @fields
727 3 7 if (@fields > 1 and ref $fields[-1] eq "HASH")
732 3 7 if ($nth)
733 2 1 @matches >= $nth ? :
736 9 1 if ($nmatches > 0) { }
737 4 5 if ($nmatches > 1)
743 1 0 $nth ? :
755 23 247 unless not $action
757 5 40 unless @forms = grep(_equal($spec{$attr}, $_->attr($attr)), @forms)
766 0 20 unless $self->forms
770 7 13 if (@args % 2 and ref $args[-1] eq "HASH")
777 7 13 if ($nth)
778 5 2 @forms >= $nth ? :
780 3 17 if (@forms > 1)
791 1 3 do { $spec{$_} eq '' } ? :
4 1 defined $spec{$_} ? :
3 0 keys %spec ? :
817 251 9 defined $x ? :
827 0 49 if ($number > 1) { }
831 11 38 if (ref $value eq 'ARRAY') { }
834 10 1 if ($input->type eq 'file') { }
856 1 8 unless ($input)
861 0 8 if ($input->type ne "option")
868 4 4 if (ref $value eq "HASH")
870 0 4 unless $_ eq "n"
874 4 0 if (defined $value->{'n'}) { }
879 2 2 if (@inputs == 1) { }
890 2 2 if (ref $n eq 'ARRAY') { }
2 0 elsif (not ref $n and $n =~ /^\d+$/) { }
893 0 4 unless (/^\d+$/)
914 4 4 if (ref $value eq "ARRAY")
928 0 27 unless my $form = $self->current_form
935 9 23 if (ref $value eq 'ARRAY') { }
936 1 8 unless my $input = $form->find_input($field)
941 4 4 if ($input->type ne "file" or $input->type eq "file" and ref $value->[0] eq "ARRAY")
949 2 21 if (ref $value eq "SCALAR")
952 0 2 unless (defined int $$value)
958 0 2 if ($#possible_values < $$value)
979 1 3 if (ref $value eq 'ARRAY') { }
982 0 3 if $input->type eq "hidden"
983 1 2 if ($input->type eq $type)
993 0 3 if $input->type eq "hidden"
1009 1 4 @_ ? :
1017 1 4 if ($value eq "")
1018 1 0 $set ? :
1024 4 4 unless defined $val
1025 3 1 if ($val eq $value)
1026 2 1 $set ? :
1051 1 15 if ($number > 1) { }
1062 4 0 unless defined $_
1073 0 15 unless (/^(number|name|value|id|input|x|y)$/)
1088 1 13 if (scalar @present_exclusive_options > 1)
1093 26 0 unless defined $_
1096 0 12 unless my $form = $self->current_form
1099 3 9 if ($args{'name'}) { }
2 7 elsif (defined $args{'id'}) { }
2 5 elsif ($args{'number'}) { }
1 4 elsif ($args{'input'}) { }
4 0 elsif ($args{'value'}) { }
1119 3 6 if ($input->value and $args{'value'} eq $input->value)
1142 1 60 unless (/^(form_(number|name|fields|id)|(with_)?fields|button|x|y|strict_forms)$/)
1149 26 34 if ($args{$_})
1150 24 2 if (ref $args{$_} eq 'HASH') { }
1161 11 23 if ($args{'with_fields'})
1163 2 8 unless @got
1166 9 22 if (my $form_number = $args{'form_number'})
1168 1 7 unless $got
1171 17 12 if (my $form_name = $args{'form_name'})
1173 1 16 unless @got
1176 2 26 if (my $form_id = $args{'form_id'})
1178 1 1 unless @got
1182 1 26 if (not @filtered_sets) { }
1191 0 26 unless tie my %c, "Tie::RefHash"
1199 4 22 unless (@matched)
1202 2 20 if (@matched > 1)
1208 6 15 if (defined $args{'strict_forms'})
1214 18 3 if $fields
1217 0 17 if ($args{'button'}) { }
1261 8 37 if @_
1270 2 4 if @_
1278 3 238 if @_
1287 1 1 if (delete $opts{'binary'})
1292 0 2 unless open my $fh, ">", $filename
1293 1 1 if (my $binmode = delete $opts{'binmode'} || '' or not $self->content_type =~ m[^text/])
1294 1 0 if (length $binmode and substr($binmode, 0, 1) eq ':') { }
1301 0 2 unless print {$fh;} $self->content(%opts)
1302 0 2 unless close $fh
1312 1 2 if (not $p) { }
1 1 elsif (not ref $p) { }
1315 0 1 unless open my $fh, ">", $p
1339 0 52 $absolute ? :
1340 0 52 unless defined $url
1353 0 24 $absolute ? :
1354 2 22 unless defined $url
1402 1 0 if ($ok)
1415 2 174 unless $request
1420 172 2 if ($request->method eq "GET" or $request->method eq "POST")
1445 4 4 if (@_ == 4 or @_ == 2 and $_[0] =~ /:\d+$/)
1449 1 3 unless @_ == 2
1459 5 4 if @cred == 2
1482 184 17 if ($res->is_success)
1487 17 184 if ($res->is_error)
1488 2 15 if ($self->{'autocheck'})
1498 0 199 unless defined $content
1502 175 24 if ($self->is_html) { }
1516 156 43 if defined $_taintbrush
1524 19 24 if &tainted($_taintbrush)
1528 0 24 if &tainted($_taintbrush)
1534 4606 0 if (open my $fh, "<", $filename)
1536 4534 72 if (defined sysread($fh, $data, 1))
1538 0 4534 if &tainted($_taintbrush)
1544 0 24 if length $_taintbrush
1558 174 2 unless ($req->header("Accept-Encoding"))
1560 174 0 $HAS_ZLIB ? :
1564 117 59 if ($last)
1565 0 117 if ref $last
1569 4 1 if (defined $value) { }
1627 24 2 if (defined $self->{'content'})
1631 186 14 if $link
1649 4 0 if (defined $self->{'content'})
1650 1 3 if ($self->content_type eq 'text/css') { }
1657 36 66 if $tag_name =~ m[^/]
1659 30 36 if ($image_tags{$tag_name}) { }
3 33 elsif ($tag_name eq 'style') { }
1661 27 3 if $image
1667 6 60 if ($attrs->{'style'})
1685 6 24 if ($tag eq "input")
1686 0 6 unless my $type = $attrs->{'type'}
1687 3 3 unless $type eq "image"
1759 147 53 if ($tag eq "a")
1761 0 147 unless defined $text
1764 3 144 if ($onClick and $onClick =~ /^window\.open\(\s*'([^']+)'/) { }
3 144 elsif ($url and $url =~ /^javascript\:\s*(?:void\(\s*)?window\.open\(\s*'([^']+)'/s) { }
1778 17 183 if ($tag eq "meta")
1781 7 7 unless $equiv and lc $equiv eq "refresh" and defined $content
1783 7 0 if ($content =~ /^\d+\s*;\s*url\s*=\s*(\S+)/i) { }
1785 7 0 unless $url =~ s/^"(.+)"$/$1/
1792 4 186 unless defined $url
1819 28 1121 if ($input->type eq "file")
1835 3 117 unless $req and $res and $self->stack_depth
1839 2 115 if (@{$stack;} >= $self->stack_depth)
1851 0 37 unless my $handler = $self->{'onwarn'}
1853 6 31 if $self->quiet
1862 1 29 unless my $handler = $self->{'onerror'}