lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm

filter: Statementstmt 78.0% 39 / 50 Branchbran 50.0% 9 / 18 Conditioncond 23.0% 3 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 61.2% 60 / 98 CC 17 SCAR 35.5
CC
17
Cov
63%
check_response
46.8
BEGIN
1.0
BEGIN
1.0
CRAP 34.8
« lib/WWW/Mechanize/Script/Util.pm ↑ Summary lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm »
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
BranchTrueFalseTotal
$mech->is_html ? : 0 1 1
31  
32 1 ▶ defined($text_require) and ref($text_require) ne "ARRAY" and $text_require = [$text_require];
Branch: 1 branch
BranchTrueFalseTotal
defined $text_require and ref $text_require ne "ARRAY" and $text_require = [$text_require] 0 1 1
Condition33%1/3
defined $text_require and ref $text_require ne "ARRAY"
!ll&&!rl&&r
010
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"
ABresult
0X0
100
111
33 1 ▶ defined($text_forbid) and ref($text_forbid) ne "ARRAY" and $text_forbid = [$text_forbid];
Branch: 1 branch
BranchTrueFalseTotal
defined $text_forbid and ref $text_forbid ne "ARRAY" and $text_forbid = [$text_forbid] 0 1 1
Condition33%1/3
defined $text_forbid and ref $text_forbid ne "ARRAY"
!ll&&!rl&&r
010
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"
ABresult
0X0
100
111
34  
35 1 my @match_fails;
36 1 my $code = 0;
37 1 ▶ my $case_ign = $ignore_case ? "(?i)" : "";
Branch: 1 branch
BranchTrueFalseTotal
$ignore_case ? : 0 1 1
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
BranchTrueFalseTotal
unless ($content =~ /$case_ign\Q$text_line\E/u) 0 3 3
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
l!l
00
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")
Aresult
11
00
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
BranchTrueFalseTotal
@match_fails and push @msg, 'required text ' . join(", ", map({q['] . $_ . q['];} @match_fails)) . ' not found in received content' 0 1 1
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
BranchTrueFalseTotal
if ($content =~ /$case_ign\Q$text_line\E/u) 0 1 1
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
l!l
00
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")
Aresult
11
00
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
BranchTrueFalseTotal
@match_fails and push @msg, 'forbidden text ' . join(", ", map({q['] . $_ . q['];} @match_fails)) . ' found in received content' 0 1 1
68 . " found in received content" );
69  
70 1 ▶ if ( $code or @msg )
Branch: 1 branch
BranchTrueFalseTotal
if ($code or @msg) 0 1 1
Condition33%1/3
$code or @msg
l!l&&r!l&&!r
001
MC/DC0%0/2
$code or @msg
$code @msg
Truth table33%1/3
A or B
A= $codeB= @msg
ABresult
1X1
011
000
71 {
72 0 return ( $code, @msg );
73 }
74  
75 1 return (0);
76 }
77  
78 2 1;
79  
80 __END__
« lib/WWW/Mechanize/Script/Util.pm ↑ Summary lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm »