1 package WWW
::Mechanize
::Script
::Plugin
::TextMatchTest
;
6 use parent
qw(WWW::Mechanize::Script::Plugin);
8 use Params
::Util
qw(_ARRAY0);
10 our $VERSION = '0.001_002';
16 return qw(text_forbid text_require);
21 my ( $self, $check, $mech ) = @_;
23 my $text_require = $self->get_check_value( $check, "text_require" );
24 my $text_forbid = $self->get_check_value( $check, "text_forbid" );
25 my $ignore_case = $self->get_check_value_as_bool( $check, "ignore_case" );
26 my $content = $mech->is_html() ?
$mech->text() : $mech->content();
28 _ARRAY0
($text_require) or $text_require = [$text_require];
29 _ARRAY0
($text_forbid) or $text_forbid = [$text_forbid];
33 my $case_ign = $ignore_case ?
"(?i)" : "";
35 foreach my $text_line ( @
{$text_require} )
37 if ( $content !~ m/$case_ign\Q$text_line\E/ )
39 my $err_code = $self->get_check_value( $check, "text_require_code" ) // 1;
40 $code = &{ $check->{compute_code
} }( $code, $err_code );
41 push( @match_fails, $text_line );
47 . join( ", ", map { "'" . $_ . "'" } @match_fails )
48 . " not found in received content" );
51 foreach my $text_line ( @
{$text_forbid} )
53 if ( $content =~ m/$case_ign\Q$text_line\E/ )
55 my $err_code = $self->get_check_value( $check, "text_forbid_code" ) // 1;
56 $code = &{ $check->{compute_code
} }( $code, $err_code );
57 push( @match_fails, $text_line );
63 . join( ", ", map { "'" . $_ . "'" } @match_fails )
64 . " found in received content" );
68 return ( $code, @msg );