| 1 | package WWW::Mechanize::Script::Plugin::TextMatchTest; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent qw(WWW::Mechanize::Script::Plugin); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # ABSTRACT: check for required/forbidden text in response | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Params::Util qw(_ARRAY0); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.100'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub check_value_names | ||||||||||||||||||||||||||||
| 18 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_value_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 5 | return qw(text_forbid text_require); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub check_response | ||||||||||||||||||||||||||||
| 24 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_response: called CC=17 SCAR=38.5
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 1 | my ( $self, $check, $mech ) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | my $text_require = $self->get_check_value( $check, "text_require" ); | |||||||||||||||||||||||||||
| 28 | 1 | my $text_forbid = $self->get_check_value( $check, "text_forbid" ); | |||||||||||||||||||||||||||
| 29 | 1 | my $ignore_case = $self->get_check_value_as_bool( $check, "ignore_case" ); | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | my $content = $mech->is_html() ? $mech->text() : $mech->content(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | defined($text_require) and ref($text_require) ne "ARRAY" and $text_require = [$text_require]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $text_require and ref $text_require ne "ARRAY"
MC/DC0%0/2
defined $text_require and ref $text_require ne "ARRAY"
defined $text_require
ref $text_require ne "ARRAY"
Truth table33%1/3
A and B
A= defined $text_requireB= ref $text_require ne "ARRAY"
| |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | defined($text_forbid) and ref($text_forbid) ne "ARRAY" and $text_forbid = [$text_forbid]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $text_forbid and ref $text_forbid ne "ARRAY"
MC/DC0%0/2
defined $text_forbid and ref $text_forbid ne "ARRAY"
defined $text_forbid
ref $text_forbid ne "ARRAY"
Truth table33%1/3
A and B
A= defined $text_forbidB= ref $text_forbid ne "ARRAY"
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | my @match_fails; | |||||||||||||||||||||||||||
| 36 | 1 | my $code = 0; | |||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $case_ign = $ignore_case ? "(?i)" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | my @msg; | |||||||||||||||||||||||||||
| 39 | 1 | foreach my $text_line ( @{$text_require} ) | |||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 3 | ▶ | if ( $content !~ m/$case_ign\Q$text_line\E/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $err_code = $self->get_check_value( $check, "text_require_code" ) // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_check_value($check, "text_require_code") // 1
MC/DC0%0/1
$self->get_check_value($check, "text_require_code") // 1
$self->get_check_value($check, "text_require_code")
Truth table0%0/2
A
A= $self->get_check_value($check, "text_require_code")
| |||||||||||||||||||||||||||||
| 44 | 0 | $code = &{ $check->{compute_code} }( $code, $err_code ); | |||||||||||||||||||||||||||
| 45 | 0 | push( @match_fails, $text_line ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | @match_fails | ||||||||||||||||||||||||||||
| 49 | and push( @msg, | ||||||||||||||||||||||||||||
| 50 | "required text " | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | . join( ", ", map { "'" . $_ . "'" } @match_fails ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | . " not found in received content" ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | @match_fails = (); | |||||||||||||||||||||||||||
| 55 | 1 | foreach my $text_line ( @{$text_forbid} ) | |||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ( $content =~ m/$case_ign\Q$text_line\E/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $err_code = $self->get_check_value( $check, "text_forbid_code" ) // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_check_value($check, "text_forbid_code") // 1
MC/DC0%0/1
$self->get_check_value($check, "text_forbid_code") // 1
$self->get_check_value($check, "text_forbid_code")
Truth table0%0/2
A
A= $self->get_check_value($check, "text_forbid_code")
| |||||||||||||||||||||||||||||
| 60 | 0 | $code = &{ $check->{compute_code} }( $code, $err_code ); | |||||||||||||||||||||||||||
| 61 | 0 | push( @match_fails, $text_line ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | @match_fails | ||||||||||||||||||||||||||||
| 65 | and push( @msg, | ||||||||||||||||||||||||||||
| 66 | "forbidden text " | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | . join( ", ", map { "'" . $_ . "'" } @match_fails ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | . " found in received content" ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | if ( $code or @msg ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$code or @msg
MC/DC0%0/2
$code or @msg
$code
@msg
Truth table33%1/3
A or B
A= $codeB= @msg
| |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 0 | return ( $code, @msg ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | return (0); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||