1 package WWW
::Mechanize
::Script
::Plugin
::TextMatchTest
;
6 use parent
qw(WWW::Mechanize::Script::Plugin);
8 # ABSTRACT: check for required/forbidden text in response
10 use Params
::Util
qw(_ARRAY0);
12 our $VERSION = '0.001_003';
18 return qw(text_forbid text_require);
23 my ( $self, $check, $mech ) = @_;
25 my $text_require = $self->get_check_value( $check, "text_require" );
26 my $text_forbid = $self->get_check_value( $check, "text_forbid" );
27 my $ignore_case = $self->get_check_value_as_bool( $check, "ignore_case" );
28 my $content = $mech->is_html() ?
$mech->text() : $mech->content();
30 defined($text_require) and ref($text_require) ne "ARRAY" and $text_require = [$text_require];
31 defined($text_forbid) and ref($text_forbid) ne "ARRAY" and $text_forbid = [$text_forbid];
35 my $case_ign = $ignore_case ?
"(?i)" : "";
37 foreach my $text_line ( @
{$text_require} )
39 if ( $content !~ m/$case_ign\Q$text_line\E/ )
41 my $err_code = $self->get_check_value( $check, "text_require_code" ) // 1;
42 $code = &{ $check->{compute_code
} }( $code, $err_code );
43 push( @match_fails, $text_line );
49 . join( ", ", map { "'" . $_ . "'" } @match_fails )
50 . " not found in received content" );
53 foreach my $text_line ( @
{$text_forbid} )
55 if ( $content =~ m/$case_ign\Q$text_line\E/ )
57 my $err_code = $self->get_check_value( $check, "text_forbid_code" ) // 1;
58 $code = &{ $check->{compute_code
} }( $code, $err_code );
59 push( @match_fails, $text_line );
65 . join( ", ", map { "'" . $_ . "'" } @match_fails )
66 . " found in received content" );
70 return ( $code, @msg );