Branch Coverage

blib/lib/WWW/Mechanize.pm
Criterion Covered Total %
branch 423 480 88.1


line true false branch
34 75 0 $class eq 'WWW::Mechanize' ? :
51 19 41 if (exists $mech_params{$key}) { }
67 75 0 unless $mech_params{'noproxy'}
71 0 75 unless defined $self->{'proxy'}
100 1 1 if (defined $known_agents{$alias}) { }
187 0 144 if ref $uri eq "WWW::Mechanize::Link"
189 89 55 $self->base ? :
201 1 3 unless my $req = $self->{'req'}
227 3 25 unless $stack and @{$stack;}
253 1 14 unless $self->{'req'} and $self->{'res'}
257 1 13 unless $stack
267 1 9 unless $self->{'req'} and $self->{'res'}
269 8 1 if ($n == 0)
274 1 0 unless $stack and @$stack >= $n
289 50 1 $self->response ? :
310 2 21 unless $self->is_html
312 20 1 unless (defined $self->{'title'})
334 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) { }
344 2 104 if (exists $params{'base_href'})
349 2 104 if (my $format = delete $params{'format'})
350 1 1 if ($format eq 'text') { }
368 2 1 unless (defined $self->{'text'})
369 2 0 unless (exists $INC{'HTML::TreeBuilder'})
397 27 54 unless $self->{'links'}
399 81 0 if wantarray
406 1 16 if @_ % 2
409 1 15 if ($params{'n'} eq "all")
415 11 5 if ($link)
419 1 4 if ($self->{'autocheck'})
438 3 71 unless my(@links) = $self->links
443 108 463 if (_match_any_link_params($link, \%params))
444 23 85 if ($wantall) { }
449 56 29 if $nmatches >= $params{'n'}
454 6 9 if ($wantall)
455 4 2 if wantarray
469 0 571 unless keys %$p
471 93 478 if defined $p->{'url'} and not $link->url eq $p->{'url'}
472 63 415 if defined $p->{'url_regex'} and not $link->url =~ /$p->{'url_regex'}/
473 26 389 if defined $p->{'url_abs'} and not $link->url_abs eq $p->{'url_abs'}
476 24 365 if defined $p->{'url_abs_regex'} and not $link->url_abs =~ /$p->{'url_abs_regex'}/
479 67 298 if defined $p->{'text'} and not defined $link->text && $link->text eq $p->{'text'}
482 145 153 if defined $p->{'text_regex'} and not defined $link->text && $link->text =~ /$p->{'text_regex'}/
485 9 144 if defined $p->{'name'} and not defined $link->name && $link->name eq $p->{'name'}
488 15 129 if defined $p->{'name_regex'} and not defined $link->name && $link->name =~ /$p->{'name_regex'}/
489 4 125 if defined $p->{'tag'} and not $link->tag && $link->tag eq $p->{'tag'}
492 4 121 if defined $p->{'tag_regex'} and not $link->tag && $link->tag =~ /$p->{'tag_regex'}/
496 3 118 if defined $p->{'id'} and not $link->attrs->{'id'} && $link->attrs->{'id'} eq $p->{'id'}
499 3 115 if defined $p->{'id_regex'} and not $link->attrs->{'id'} && $link->attrs->{'id'} =~ /$p->{'id_regex'}/
502 1 114 if defined $p->{'class'} and not $link->attrs->{'class'} && $link->attrs->{'class'} eq $p->{'class'}
506 1 113 if defined $p->{'class_regex'} and not $link->attrs->{'class'} && $link->attrs->{'class'} =~ /$p->{'class_regex'}/
510 3 110 if defined $p->{'rel'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} eq $p->{'rel'}
513 2 108 if defined $p->{'rel_regex'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} =~ /$p->{'rel_regex'}/
528 5 233 unless ($key =~ qr/$rx_keyname/)
537 49 184 if ($key_regex) { }
538 6 43 unless ($val_regex)
545 5 179 if ($val_regex)
550 5 174 if ($val =~ /^\s|\s$/)
572 0 8 unless my $form = $self->current_form
589 11 11 unless $matched
591 23 11 if $matched
607 4 51 unless $self->{'images'}
609 54 1 if wantarray
625 0 50 unless my(@images) = $self->images
630 87 342 if (_match_any_image_params($image, \%params))
631 66 21 if ($wantall) { }
636 20 1 if $nmatches >= $params{'n'}
641 18 12 if ($wantall)
642 17 1 if wantarray
656 0 429 unless keys %$p
660 42 387 if defined $p->{'url'} and not defined $image->url && $image->url eq $p->{'url'}
663 33 354 if defined $p->{'url_regex'} and not defined $image->url && $image->url =~ /$p->{'url_regex'}/
667 30 324 if defined $p->{'url_abs'} and not defined $image->url_abs && $image->url_abs eq $p->{'url_abs'}
671 25 299 if defined $p->{'url_abs_regex'} and not defined $image->url_abs && $image->url_abs =~ /$p->{'url_abs_regex'}/
674 24 275 if defined $p->{'alt'} and not defined $image->alt && $image->alt eq $p->{'alt'}
677 24 251 if defined $p->{'alt_regex'} and not defined $image->alt && $image->alt =~ /$p->{'alt_regex'}/
679 39 212 if defined $p->{'tag'} and not $image->tag && $image->tag eq $p->{'tag'}
682 16 196 if defined $p->{'tag_regex'} and not $image->tag && $image->tag =~ /$p->{'tag_regex'}/
687 27 169 if defined $p->{'id'} and not $image->attrs && $image->attrs->{'id'} && $image->attrs->{'id'} eq $p->{'id'}
692 26 143 if defined $p->{'id_regex'} and not $image->attrs && $image->attrs->{'id'} && $image->attrs->{'id'} =~ /$p->{'id_regex'}/
697 27 116 if defined $p->{'class'} and not $image->attrs && $image->attrs->{'class'} && $image->attrs->{'class'} eq $p->{'class'}
702 29 87 if defined $p->{'class_regex'} and not $image->attrs && $image->attrs->{'class'} && $image->attrs->{'class'} =~ /$p->{'class_regex'}/
718 75 82 unless $self->{'forms'}
720 65 90 if wantarray
727 30 132 unless ($self->{'current_form'})
741 48 2 if ($$forms[$form - 1])
745 1 47 wantarray ? :
748 0 2 wantarray ? :
757 15 0 if defined($temp = $_->action)
761 2 1 if ($nmatches > 0)
762 1 1 if ($nmatches > 1)
782 2 4 unless defined(my $form = $self->form_with("id", $formid, $args || ()))
790 1 20 unless scalar @fields
796 124 46 unless grep {$_ eq $field;} @fields_in_form
806 2 10 unless scalar @fields
809 3 7 if (@fields > 1 and ref $fields[-1] eq "HASH")
814 3 7 if ($nth)
815 2 1 @matches >= $nth ? :
818 9 1 if ($nmatches > 0) { }
819 4 5 if ($nmatches > 1)
827 1 0 $nth ? :
841 23 247 unless not $action
843 5 40 unless @forms = grep(_equal($spec{$attr}, $_->attr($attr)), @forms)
853 0 20 unless $self->forms
857 7 13 if (@args % 2 and ref $args[-1] eq "HASH")
864 7 13 if ($nth)
865 5 2 @forms >= $nth ? :
867 3 17 if (@forms > 1)
878 1 3 do { $spec{$_} eq '' } ? :
4 1 defined $spec{$_} ? :
3 0 keys %spec ? :
905 257 8 defined $x ? :
914 0 49 if ($number > 1) { }
918 11 38 if (ref $value eq 'ARRAY') { }
921 10 1 if ($input->type eq 'file') { }
943 1 8 unless ($input)
948 0 8 if ($input->type ne "option")
955 4 4 if (ref $value eq "HASH")
957 0 4 unless $_ eq "n"
961 4 0 if (defined $value->{'n'}) { }
967 2 2 if (@inputs == 1) { }
978 2 2 if (ref $n eq 'ARRAY') { }
2 0 elsif (not ref $n and $n =~ /^\d+$/) { }
981 0 4 unless (/^\d+$/)
1004 4 4 if (ref $value eq "ARRAY")
1018 0 27 unless my $form = $self->current_form
1025 9 23 if (ref $value eq 'ARRAY') { }
1026 1 8 unless my $input = $form->find_input($field)
1031 4 4 if ($input->type ne "file" or $input->type eq "file" and ref $value->[0] eq "ARRAY")
1039 2 21 if (ref $value eq "SCALAR")
1042 0 2 unless (defined int $$value)
1049 0 2 if ($#possible_values < $$value)
1072 1 3 if (ref $value eq 'ARRAY') { }
1075 0 3 if $input->type eq "hidden"
1076 1 2 if ($input->type eq $type)
1087 0 3 if $input->type eq "hidden"
1103 1 4 @_ ? :
1113 1 4 if ($value eq "")
1114 1 0 $set ? :
1121 4 4 unless defined $val
1122 3 1 if ($val eq $value)
1123 2 1 $set ? :
1148 1 15 if ($number > 1) { }
1159 4 0 unless defined $_
1170 0 15 unless (/^(number|name|value|id|input|x|y)$/)
1185 1 13 if (scalar @present_exclusive_options > 1)
1191 26 0 unless defined $_
1194 0 12 unless my $form = $self->current_form
1198 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'}) { }
1222 3 6 if ($input->value and $args{'value'} eq $input->value)
1245 1 60 unless (/^(form_(number|name|fields|id)|(with_)?fields|button|x|y|strict_forms)$/)
1254 26 34 if ($args{$_})
1255 24 2 if (ref $args{$_} eq 'HASH') { }
1266 11 23 if ($args{'with_fields'})
1268 2 8 unless @got
1271 9 22 if (my $form_number = $args{'form_number'})
1273 1 7 unless $got
1276 17 12 if (my $form_name = $args{'form_name'})
1278 1 16 unless @got
1281 2 26 if (my $form_id = $args{'form_id'})
1283 1 1 unless @got
1287 1 26 if (not @filtered_sets) { }
1297 0 26 unless tie my %c, "Tie::RefHash"
1306 4 22 unless (@matched)
1309 2 20 if (@matched > 1)
1315 6 15 if (defined $args{'strict_forms'})
1322 18 3 if $fields
1325 0 17 if ($args{'button'}) { }
1369 9 38 if @_
1378 2 4 if @_
1386 3 240 if @_
1395 1 1 if (delete $opts{'binary'})
1400 0 2 unless open my $fh, ">", $filename
1402 1 1 if (my $binmode = delete $opts{'binmode'} || '' or not $self->content_type =~ m[^text/])
1404 1 0 if (length $binmode and substr($binmode, 0, 1) eq ':') { }
1411 0 2 unless print {$fh;} $self->content(%opts)
1413 0 2 unless close $fh
1422 1 2 if (not $p) { }
1 1 elsif (not ref $p) { }
1426 0 1 unless open my $fh, ">", $p
1450 0 52 $absolute ? :
1451 0 52 unless defined $url
1464 0 24 $absolute ? :
1465 2 22 unless defined $url
1511 1 0 if ($ok)
1523 2 175 unless $request
1528 173 2 if ($request->method eq "GET" or $request->method eq "POST")
1556 4 4 if (@_ == 4 or @_ == 2 and $_[0] =~ /:\d+$/)
1560 1 3 unless @_ == 2
1570 5 4 if @cred == 2
1593 186 17 if ($res->is_success)
1598 17 186 if ($res->is_error)
1599 2 15 if ($self->{'autocheck'})
1612 0 201 unless defined $content
1616 177 24 if ($self->is_html) { }
1630 158 43 if defined $_taintbrush
1638 19 24 if &tainted($_taintbrush)
1642 0 24 if &tainted($_taintbrush)
1648 4835 0 if (open my $fh, "<", $filename)
1650 4763 72 if (defined sysread($fh, $data, 1))
1652 0 4763 if &tainted($_taintbrush)
1658 0 24 if length $_taintbrush
1671 175 2 unless ($req->header("Accept-Encoding"))
1674 175 0 $HAS_ZLIB ? :
1678 118 59 if ($last)
1679 0 118 if ref $last
1683 4 1 if (defined $value) { }
1740 25 2 if (defined $self->{'content'})
1744 196 14 if $link
1761 4 0 if (defined $self->{'content'})
1762 1 3 if ($self->content_type eq 'text/css') { }
1772 36 66 if $tag_name =~ m[^/]
1774 30 36 if ($image_tags{$tag_name}) { }
3 33 elsif ($tag_name eq 'style') { }
1776 27 3 if $image
1785 6 60 if ($attrs->{'style'})
1806 6 24 if ($tag eq "input")
1807 0 6 unless my $type = $attrs->{'type'}
1808 3 3 unless $type eq "image"
1883 157 53 if ($tag eq "a")
1885 0 157 unless defined $text
1888 3 154 if ($onClick and $onClick =~ /^window\.open\(\s*'([^']+)'/) { }
3 154 elsif ($url and $url =~ /^javascript\:\s*(?:void\(\s*)?window\.open\(\s*'([^']+)'/s) { }
1904 17 193 if ($tag eq "meta")
1908 7 7 unless $equiv and lc $equiv eq "refresh" and defined $content
1910 7 0 if ($content =~ /^\d+\s*;\s*url\s*=\s*(\S+)/i) { }
1912 7 0 unless $url =~ s/^"(.+)"$/$1/
1920 4 196 unless defined $url
1947 28 1121 if ($input->type eq "file")
1963 3 118 unless $req and $res and $self->stack_depth
1967 2 116 if (@{$stack;} >= $self->stack_depth)
1979 0 38 unless my $handler = $self->{'onwarn'}
1981 6 32 if $self->quiet
1990 1 29 unless my $handler = $self->{'onerror'}