Branch Coverage

blib/lib/WWW/Mechanize.pm
Criterion Covered Total %
branch 418 470 88.9


line true false branch
33 76 0 $class eq 'WWW::Mechanize' ? :
50 20 42 if (exists $mech_params{$key}) { }
66 76 0 unless $mech_params{'noproxy'}
70 0 76 unless defined $self->{'proxy'}
99 1 1 if (defined $known_agents{$alias}) { }
186 0 146 if ref $uri eq "WWW::Mechanize::Link"
188 91 55 $self->base ? :
200 1 3 unless my $req = $self->{'req'}
226 3 26 unless $stack and @{$stack;}
252 1 14 unless $self->{'req'} and $self->{'res'}
256 1 13 unless $stack
266 1 9 unless $self->{'req'} and $self->{'res'}
268 8 1 if ($n == 0)
273 1 0 unless $stack and @$stack >= $n
288 53 1 $self->response ? :
309 2 19 unless $self->is_html
311 19 0 unless (defined $self->{'title'})
333 2 120 if (delete $params{'raw'}) { }
2 118 elsif (delete $params{'decoded_by_headers'}) { }
1 117 elsif (my $charset = delete $params{'charset'}) { }
107 10 elsif ($self->is_html) { }
335 1 1 if $res
344 2 105 if (exists $params{'base_href'})
349 2 105 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 33 54 unless $self->{'links'}
399 87 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 74 unless my(@links) = $self->links
443 117 463 if (_match_any_link_params($link, \%params))
444 32 85 if ($wantall) { }
449 56 29 if $nmatches >= $params{'n'}
454 9 9 if ($wantall)
455 7 2 if wantarray
469 0 580 unless keys %$p
471 93 487 if defined $p->{'url'} and not $link->url eq $p->{'url'}
472 63 424 if defined $p->{'url_regex'} and not $link->url =~ /$p->{'url_regex'}/
473 26 398 if defined $p->{'url_abs'} and not $link->url_abs eq $p->{'url_abs'}
476 24 374 if defined $p->{'url_abs_regex'} and not $link->url_abs =~ /$p->{'url_abs_regex'}/
479 67 307 if defined $p->{'text'} and not defined $link->text && $link->text eq $p->{'text'}
482 145 162 if defined $p->{'text_regex'} and not defined $link->text && $link->text =~ /$p->{'text_regex'}/
485 9 153 if defined $p->{'name'} and not defined $link->name && $link->name eq $p->{'name'}
488 15 138 if defined $p->{'name_regex'} and not defined $link->name && $link->name =~ /$p->{'name_regex'}/
489 4 134 if defined $p->{'tag'} and not $link->tag && $link->tag eq $p->{'tag'}
492 4 130 if defined $p->{'tag_regex'} and not $link->tag && $link->tag =~ /$p->{'tag_regex'}/
496 3 127 if defined $p->{'id'} and not $link->attrs->{'id'} && $link->attrs->{'id'} eq $p->{'id'}
499 3 124 if defined $p->{'id_regex'} and not $link->attrs->{'id'} && $link->attrs->{'id'} =~ /$p->{'id_regex'}/
502 1 123 if defined $p->{'class'} and not $link->attrs->{'class'} && $link->attrs->{'class'} eq $p->{'class'}
506 1 122 if defined $p->{'class_regex'} and not $link->attrs->{'class'} && $link->attrs->{'class'} =~ /$p->{'class_regex'}/
510 3 119 if defined $p->{'rel'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} eq $p->{'rel'}
513 2 117 if defined $p->{'rel_regex'} and not $link->attrs->{'rel'} && $link->attrs->{'rel'} =~ /$p->{'rel_regex'}/
528 5 236 unless ($key =~ qr/$rx_keyname/)
537 49 187 if ($key_regex) { }
538 6 43 unless ($val_regex)
545 5 182 if ($val_regex)
550 5 177 if ($val =~ /^\s|\s$/)
572 0 8 unless my $form = $self->current_form
589 11 11 unless $matched
591 23 11 if $matched
607 7 51 unless $self->{'images'}
609 57 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 79 82 unless $self->{'forms'}
720 68 91 if wantarray
727 31 136 unless ($self->{'current_form'})
741 49 2 if ($$forms[$form - 1])
745 1 48 wantarray ? :
748 0 2 wantarray ? :
757 15 0 if defined($temp = $_->action)
762 2 1 if ($nmatches > 0)
763 1 1 if ($nmatches > 1)
783 2 4 unless defined(my $form = $self->form_with("id", $formid, $args || ()))
791 1 20 unless scalar @fields
797 124 46 unless grep {$_ eq $field;} @fields_in_form
807 2 10 unless scalar @fields
810 3 7 if (@fields > 1 and ref $fields[-1] eq "HASH")
815 3 7 if ($nth)
816 2 1 @matches >= $nth ? :
819 9 1 if ($nmatches > 0) { }
820 4 5 if ($nmatches > 1)
828 1 0 $nth ? :
842 23 247 unless not $action
844 5 40 unless @forms = grep(_equal($spec{$attr}, $_->attr($attr)), @forms)
854 0 20 unless $self->forms
858 7 13 if (@args % 2 and ref $args[-1] eq "HASH")
865 7 13 if ($nth)
866 5 2 @forms >= $nth ? :
868 3 17 if (@forms > 1)
879 1 3 do { $spec{$_} eq '' } ? :
4 1 defined $spec{$_} ? :
3 0 keys %spec ? :
906 257 9 defined $x ? :
915 0 49 if ($number > 1) { }
919 11 38 if (ref $value eq 'ARRAY') { }
922 10 1 if ($input->type eq 'file') { }
945 1 12 unless ($input)
950 0 12 if ($input->type ne "option")
957 4 8 if (ref $value eq "HASH")
959 0 4 unless $_ eq "n"
963 4 0 if (defined $value->{'n'}) { }
969 2 2 if (@inputs == 1) { }
980 2 2 if (ref $n eq 'ARRAY') { }
2 0 elsif (not ref $n and $n =~ /^\d+$/) { }
983 0 4 unless (/^\d+$/)
1006 4 8 if (ref $value eq "ARRAY")
1020 0 27 unless my $form = $self->current_form
1027 9 23 if (ref $value eq 'ARRAY') { }
1028 1 8 unless my $input = $form->find_input($field)
1033 4 4 if ($input->type ne "file" or $input->type eq "file" and ref $value->[0] eq "ARRAY")
1041 2 21 if (ref $value eq "SCALAR")
1044 0 2 unless (defined int $$value)
1051 0 2 if ($#possible_values < $$value)
1074 1 3 if (ref $value eq 'ARRAY') { }
1077 0 3 if $input->type eq "hidden"
1078 1 2 if ($input->type eq $type)
1089 0 3 if $input->type eq "hidden"
1105 1 4 @_ ? :
1115 1 4 if ($value eq "")
1116 1 0 $set ? :
1123 4 4 unless defined $val
1124 3 1 if ($val eq $value)
1125 2 1 $set ? :
1150 1 15 if ($number > 1) { }
1161 4 0 unless defined $_
1172 0 18 unless (/^(number|name|value|id|input|x|y)$/)
1186 2 16 unless $_
1188 1 14 if (scalar @present_exclusive_options > 1)
1194 26 2 unless defined $_
1197 0 13 unless my $form = $self->current_form
1201 4 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'}) { }
1225 3 6 if ($input->value and $args{'value'} eq $input->value)
1248 1 60 unless (/^(form_(number|name|fields|id)|(with_)?fields|button|x|y|strict_forms)$/)
1257 26 34 if ($args{$_})
1258 24 2 if (ref $args{$_} eq 'HASH') { }
1269 11 23 if ($args{'with_fields'})
1271 2 8 unless @got
1274 9 22 if (my $form_number = $args{'form_number'})
1276 1 7 unless $got
1279 17 12 if (my $form_name = $args{'form_name'})
1281 1 16 unless @got
1284 2 26 if (my $form_id = $args{'form_id'})
1286 1 1 unless @got
1290 1 26 if (not @filtered_sets) { }
1300 0 26 unless tie my %c, "Tie::RefHash"
1309 4 22 unless (@matched)
1312 2 20 if (@matched > 1)
1318 6 15 if (defined $args{'strict_forms'})
1325 18 3 if $fields
1328 0 17 if ($args{'button'}) { }
1372 9 38 if @_
1381 2 4 if @_
1389 3 246 if @_
1398 1 1 if (delete $opts{'binary'})
1403 0 2 unless open my $fh, ">", $filename
1405 1 1 if (my $binmode = delete $opts{'binmode'} || '' or not $self->content_type =~ m[^text/])
1407 1 0 if (length $binmode and substr($binmode, 0, 1) eq ':') { }
1414 0 2 unless print {$fh;} $self->content(%opts)
1416 0 2 unless close $fh
1425 1 2 if (not $p) { }
1 1 elsif (not ref $p) { }
1429 0 1 unless open my $fh, ">", $p
1453 0 64 $absolute ? :
1454 0 64 unless defined $url
1467 0 26 $absolute ? :
1468 3 23 unless defined $url
1513 1 0 if ($ok)
1525 2 178 unless $request
1530 176 2 if ($request->method eq "GET" or $request->method eq "POST")
1558 4 4 if (@_ == 4 or @_ == 2 and $_[0] =~ /:\d+$/)
1562 1 3 unless @_ == 2
1572 5 4 if @cred == 2
1595 189 18 if ($res->is_success)
1600 18 189 if ($res->is_error)
1601 2 16 if ($self->{'autocheck'})
1614 0 205 unless defined $content
1616 179 26 if ($self->is_html) { }
1634 178 2 unless ($req->header("Accept-Encoding"))
1637 178 0 $HAS_ZLIB ? :
1641 121 59 if ($last)
1642 0 121 if ref $last
1646 4 1 if (defined $value) { }
1703 31 2 if (defined $self->{'content'})
1707 217 15 if $link
1724 7 0 if (defined $self->{'content'})
1725 1 6 if ($self->content_type eq 'text/css') { }
1735 99 160 if $tag_name =~ m[^/]
1737 50 110 if ($image_tags{$tag_name}) { }
4 106 elsif ($tag_name eq 'style') { }
1739 29 21 if $image
1748 10 150 if ($attrs->{'style'})
1768 24 26 if ($tag eq "input")
1769 1 23 unless my $type = $attrs->{'type'}
1770 20 3 unless $type eq "image"
1845 178 54 if ($tag eq "a")
1853 0 178 unless defined $text
1856 3 175 if ($onClick and $onClick =~ /^window\.open\(\s*'([^']+)'/) { }
3 175 elsif ($url and $url =~ /^javascript\:\s*(?:void\(\s*)?window\.open\(\s*'([^']+)'/s) { }
1872 18 214 if ($tag eq "meta")
1876 8 7 unless $equiv and lc $equiv eq "refresh" and defined $content
1878 7 0 if ($content =~ /^\d+\s*;\s*url\s*=\s*(\S+)/i) { }
1880 7 0 unless $url =~ s/^"(.+)"$/$1/
1888 4 217 unless defined $url
1915 29 1154 if ($input->type eq "file")
1931 3 121 unless $req and $res and $self->stack_depth
1935 2 119 if (@{$stack;} >= $self->stack_depth)
1947 0 38 unless my $handler = $self->{'onwarn'}
1949 6 32 if $self->quiet
1958 1 29 unless my $handler = $self->{'onerror'}