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

filter: Statementstmt 76.4% 39 / 51 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 60.6% 60 / 99 CC 17 SCAR 35.8
CC
17
Cov
62%
check_response
48.4
BEGIN
1.0
BEGIN
1.0
CRAP 36.0
« lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm ↑ Summary lib/WWW/Mechanize/Script/Util.pm »
1 package WWW::Mechanize::Script::Plugin::RegexMatchTest;
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 via regular expression 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(regex_forbid regex_require);
20 }
21  
22  
23 sub check_response
24 1 ▶{
Subroutine check_response: called CC=17 SCAR=38.8
Pod documented
25 1 my ( $self, $check, $mech ) = @_;
26  
27 1 my $regex_require = $self->get_check_value( $check, "regex_require" );
28 1 my $regex_forbid = $self->get_check_value( $check, "regex_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($regex_require)
Branch: 1 branch
BranchTrueFalseTotal
defined $regex_require and ref $regex_require ne "ARRAY" and $regex_require = [$regex_require] 0 1 1
Condition33%1/3
defined $regex_require and ref $regex_require ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $regex_require and ref $regex_require ne "ARRAY"
defined $regex_require ref $regex_require ne "ARRAY"
Truth table33%1/3
A and B
A= defined $regex_requireB= ref $regex_require ne "ARRAY"
ABresult
0X0
100
111
33 and ref($regex_require) ne "ARRAY"
34 and $regex_require = [$regex_require];
35 1 ▶ defined($regex_forbid) and ref($regex_forbid) ne "ARRAY" and $regex_forbid = [$regex_forbid];
Branch: 1 branch
BranchTrueFalseTotal
defined $regex_forbid and ref $regex_forbid ne "ARRAY" and $regex_forbid = [$regex_forbid] 0 1 1
Condition33%1/3
defined $regex_forbid and ref $regex_forbid ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $regex_forbid and ref $regex_forbid ne "ARRAY"
defined $regex_forbid ref $regex_forbid ne "ARRAY"
Truth table33%1/3
A and B
A= defined $regex_forbidB= ref $regex_forbid ne "ARRAY"
ABresult
0X0
100
111
36  
37 1 my @match_fails;
38 1 my $code = 0;
39 1 ▶ my $case_ign = $ignore_case ? "(?i)" : "";
Branch: 1 branch
BranchTrueFalseTotal
$ignore_case ? : 0 1 1
40 1 my @msg;
41 1 foreach my $regex_line ( @{$regex_require} )
42 {
43 2 ▶ if ( $content !~ m/$case_ign$regex_line/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($content =~ /$case_ign$regex_line/u) 0 2 2
44 {
45 0 ▶ my $err_code = $self->get_check_value( $check, "regex_require_code" ) // 1;
Condition0%0/2
$self->get_check_value($check, "regex_require_code") // 1
l!l
00
MC/DC0%0/1
$self->get_check_value($check, "regex_require_code") // 1
$self->get_check_value($check, "regex_require_code")
Truth table0%0/2
A
A= $self->get_check_value($check, "regex_require_code")
Aresult
11
00
46 0 $code = &{ $check->{compute_code} }( $code, $err_code );
47 0 push( @match_fails, $regex_line );
48 }
49 }
50 @match_fails
51 and push( @msg,
52 "required regex "
53 0 ▶ . join( ", ", map { "'" . $_ . "'" } @match_fails )
Branch: 1 branch
BranchTrueFalseTotal
@match_fails and push @msg, 'required regex ' . join(", ", map({q['] . $_ . q['];} @match_fails)) . ' not found in received content' 0 1 1
54 . " not found in received content" );
55  
56 1 @match_fails = ();
57 1 foreach my $regex_line ( @{$regex_forbid} )
58 {
59 1 ▶ if ( $content =~ m/$case_ign$regex_line/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /$case_ign$regex_line/u) 0 1 1
60 {
61 0 ▶ my $err_code = $self->get_check_value( $check, "regex_forbid_code" ) // 1;
Condition0%0/2
$self->get_check_value($check, "regex_forbid_code") // 1
l!l
00
MC/DC0%0/1
$self->get_check_value($check, "regex_forbid_code") // 1
$self->get_check_value($check, "regex_forbid_code")
Truth table0%0/2
A
A= $self->get_check_value($check, "regex_forbid_code")
Aresult
11
00
62 0 $code = &{ $check->{compute_code} }( $code, $err_code );
63 0 push( @match_fails, $regex_line );
64 }
65 }
66 @match_fails
67 and push( @msg,
68 "forbidden regex "
69 0 ▶ . join( ", ", map { "'" . $_ . "'" } @match_fails )
Branch: 1 branch
BranchTrueFalseTotal
@match_fails and push @msg, 'forbidden regex ' . join(", ", map({q['] . $_ . q['];} @match_fails)) . ' found in received content' 0 1 1
70 . " found in received content" );
71  
72 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
73 {
74 0 return ( $code, @msg );
75 }
76  
77 1 return (0);
78 0 return (0);
79 }
80  
81 2 1;
82  
83 __END__
« lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm ↑ Summary lib/WWW/Mechanize/Script/Util.pm »