Search/Base.pm

filter: Statementstmt 22.4% 22 / 98 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 43 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 36.8% 7 / 19 Podpod 0.0% 0 / 12 totaltotal 11.4% 29 / 253 CC 44 SCAR 36.1
CC
44
Cov
11%
warn
90.0
log_error
56.0
extra_vars_for_uri
42.0
CRAP 36.8
« Search/Display/Grid.pm ↑ Summary TEST/TestCase.pm »
1 package CGI::Widget::DBI::Search::Base;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Encode qw/decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # use Encode::Detect; # no longer used- decode('utf8') is more reliable
7 3 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use URI::Escape qw/uri_escape uri_escape_utf8/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # --------------------- USER CUSTOMIZABLE VARIABLES ------------------------
11  
12 3 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # --------------------- END USER CUSTOMIZABLE VARIABLES --------------------
15  
16 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
17 0 my $this = shift;
18 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
19 my $self = ref($_[0]) =~ m/^CGI::Widget::DBI::/ && scalar(@_) == 1
20 0 ▶ ? bless { %{ $_[0] } }, $class
Branch: 1 branch
BranchTrueFalseTotal
ref($_[0]) =~ /^CGI::Widget::DBI::/ && scalar @_ == 1 ? : 0 0 0
Condition0%0/3
ref($_[0]) =~ /^CGI::Widget::DBI::/ and scalar @_ == 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref($_[0]) =~ /^CGI::Widget::DBI::/ and scalar @_ == 1
ref($_[0]) =~ /^CGI::Widget::DBI::/ scalar @_ == 1
Truth table0%0/3
A and B
A= ref($_[0]) =~ /^CGI::Widget::DBI::/B= scalar @_ == 1
ABresult
0X0
100
111
21 : bless { @_ }, $class;
22 0 ▶ $self->initialize if $self->can('initialize');
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("initialize") 0 0 0
23 0 return $self;
24 }
25  
26 0 ▶sub caller_function {
Subroutine caller_function: not called CC=3 SCAR=24.8
Pod undocumented
27 0 my ($self, $stacklvl) = @_;
28 0 ▶ my ($func) = ( (caller($stacklvl || 1))[3] =~ m/::([^:]+)\z/ );
Condition0%0/2
$stacklvl || 1
l!l
00
MC/DC0%0/1
$stacklvl || 1
$stacklvl
Truth table0%0/2
A
A= $stacklvl
Aresult
11
00
29 0 ▶ return $func || '';
Condition0%0/2
$func || ''
l!l
00
MC/DC0%0/1
$func || ''
$func
Truth table0%0/2
A
A= $func
Aresult
11
00
30 }
31  
32 0 ▶sub log_error {
Subroutine log_error: not called CC=7 SCAR=40.3
Pod undocumented
33 0 my ($self, $msg) = @_;
34 0 ▶ my $method = $self->caller_function(2) || $self->caller_function(3); # check one level higher in case called from eval
Condition0%0/3
$self->caller_function(2) || $self->caller_function(3)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->caller_function(2) || $self->caller_function(3)
$self->caller_function(2) $self->caller_function(3)
Truth table0%0/3
A || B
A= $self->caller_function(2)B= $self->caller_function(3)
ABresult
1X1
011
000
35 0 ▶ my $logmsg = (ref($self)||$self).'->'.$method.': '.$msg;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
36 0 ▶ if (blessed($self->{r}) && $self->{r}->can('log_error')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($self->{'r'}) and $self->{'r'}->can('log_error')) { } 0 0 0
elsif (ref $self->{'parent'} and ref $self->{'parent'}{'r'} eq 'Apache') { } 0 0 0
Condition0%0/3
builtin::blessed($self->{"r"}) and $self->{"r"}->can("log_error")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($self->{"r"}) and $self->{"r"}->can("log_error")
builtin::blessed($self->{"r"}) $self->{"r"}->can("log_error")
Truth table0%0/3
A and B
A= builtin::blessed($self->{"r"})B= $self->{"r"}->can("log_error")
ABresult
0X0
100
111
37 0 $self->{r}->log_error($logmsg);
38 ▶ } elsif (ref $self->{parent} and ref $self->{parent}->{r} eq 'Apache') {
Condition0%0/3
ref $self->{"parent"} and ref $self->{"parent"}{"r"} eq "Apache"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"parent"} and ref $self->{"parent"}{"r"} eq "Apache"
ref $self->{"parent"} ref $self->{"parent"}{"r"} eq "Apache"
Truth table0%0/3
A and B
A= ref $self->{"parent"}B= ref $self->{"parent"}{"r"} eq "Apache"
ABresult
0X0
100
111
39 0 $self->{parent}->{r}->log_error($logmsg);
40 } else {
41 0 print STDERR '['.localtime().'] [error] [client '.$ENV{REMOTE_ADDR}.'] (STDERR) '.$logmsg."\n";
42 }
43 }
44  
45 0 ▶sub warn {
Subroutine warn: not called CC=9 SCAR=45.0
Pod undocumented
46 0 my ($self, $msg) = @_;
47 0 ▶ return unless $self->{_DEBUG} || DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_DEBUG"} or 0 0 0 0
Condition0%0/2
$self->{"_DEBUG"} or 0
l!l
00
MC/DC0%0/1
$self->{"_DEBUG"} or 0
$self->{"_DEBUG"}
Truth table0%0/2
A
A= $self->{"_DEBUG"}
Aresult
11
00
48 0 ▶ my $method = $self->caller_function(2) || $self->caller_function(3);
Condition0%0/3
$self->caller_function(2) || $self->caller_function(3)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->caller_function(2) || $self->caller_function(3)
$self->caller_function(2) $self->caller_function(3)
Truth table0%0/3
A || B
A= $self->caller_function(2)B= $self->caller_function(3)
ABresult
1X1
011
000
49 0 ▶ my $logmsg = (ref($self)||$self).'->'.$method.': '.$msg;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
50 0 ▶ if (blessed($self->{r}) && $self->{r}->can('warn')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($self->{'r'}) and $self->{'r'}->can('warn')) { } 0 0 0
elsif (ref $self->{'parent'} and ref $self->{'parent'}{'r'} eq 'Apache') { } 0 0 0
Condition0%0/3
builtin::blessed($self->{"r"}) and $self->{"r"}->can("warn")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($self->{"r"}) and $self->{"r"}->can("warn")
builtin::blessed($self->{"r"}) $self->{"r"}->can("warn")
Truth table0%0/3
A and B
A= builtin::blessed($self->{"r"})B= $self->{"r"}->can("warn")
ABresult
0X0
100
111
51 0 $self->{r}->warn($logmsg);
52 ▶ } elsif (ref $self->{parent} and ref $self->{parent}->{r} eq 'Apache') {
Condition0%0/3
ref $self->{"parent"} and ref $self->{"parent"}{"r"} eq "Apache"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"parent"} and ref $self->{"parent"}{"r"} eq "Apache"
ref $self->{"parent"} ref $self->{"parent"}{"r"} eq "Apache"
Truth table0%0/3
A and B
A= ref $self->{"parent"}B= ref $self->{"parent"}{"r"} eq "Apache"
ABresult
0X0
100
111
53 0 $self->{parent}->{r}->warn($logmsg);
54 } else {
55 0 print STDERR '['.localtime().'] [warn] [client '.$ENV{REMOTE_ADDR}.'] (STDERR) '.$logmsg."\n";
56 }
57 }
58  
59 0 ▶sub extra_vars_for_uri {
Subroutine extra_vars_for_uri: not called CC=6 SCAR=37.4
Pod undocumented
60 0 my ($self, $exclude_param_list) = @_;
61 0 ▶ return '' unless ref $self->{-href_extra_vars} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"-href_extra_vars"} eq "HASH" 0 0 0
62 0 ▶ my %exclude = map {$_=>1} @{$exclude_param_list||[]};
Condition0%0/2
$exclude_param_list || []
l!l
00
MC/DC0%0/1
$exclude_param_list || []
$exclude_param_list
Truth table0%0/2
A
A= $exclude_param_list
Aresult
11
00
63 return join('&', map {
64 0 my $param_val = $self->{q}->param($_);
65 $exclude{$_} ? () : uri_escape($_).'='.uri_escape_utf8(defined $self->{-href_extra_vars}->{$_} ? $self->{-href_extra_vars}->{$_}
66 0 ▶ : defined $self->{q}->param($_) ? decode_utf8($param_val) : '');
Branch: 3 branches
BranchTrueFalseTotal
$exclude{$_} ? : 0 0 0
defined $self->{'-href_extra_vars'}{$_} ? : 0 0 0
defined $self->{'q'}->param($_) ? : 0 0 0
67 0 } keys %{$self->{-href_extra_vars}});
68 }
69  
70 0 ▶sub extra_vars_for_json {
Subroutine extra_vars_for_json: not called CC=6 SCAR=37.4
Pod undocumented
71 0 my ($self, $exclude_param_list) = @_;
72 0 ▶ return '' unless ref $self->{-href_extra_vars} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"-href_extra_vars"} eq "HASH" 0 0 0
73 0 ▶ my %exclude = map {$_=>1} @{$exclude_param_list||[]};
Condition0%0/2
$exclude_param_list || []
l!l
00
MC/DC0%0/1
$exclude_param_list || []
$exclude_param_list
Truth table0%0/2
A
A= $exclude_param_list
Aresult
11
00
74 return join(', ', map { #TODO: js escape below key?
75 0 my $param_val = $self->{q}->param($_);
76 $exclude{$_} ? () : qq|'$_': '|.(defined $self->{-href_extra_vars}->{$_} ? $self->{-href_extra_vars}->{$_}
77 0 ▶ : defined $self->{q}->param($_) ? js_escape(decode_utf8($param_val)) : '').q|'|;
Branch: 3 branches
BranchTrueFalseTotal
$exclude{$_} ? : 0 0 0
defined $self->{'-href_extra_vars'}{$_} ? : 0 0 0
defined $self->{'q'}->param($_) ? : 0 0 0
78 0 } keys %{$self->{-href_extra_vars}});
79 }
80  
81 0 ▶sub extra_vars_for_form {
Subroutine extra_vars_for_form: not called CC=3 SCAR=24.8
Pod undocumented
82 0 my ($self) = @_;
83 0 ▶ return '' unless ref $self->{-form_extra_vars} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"-form_extra_vars"} eq "HASH" 0 0 0
84 return join('', map {
85 0 my $val = $self->{q}->param($_);
86 0 ▶ defined $val ? $self->{q}->hidden(-name => $_, -default => decode_utf8($val), -override => 1) : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
87 0 } sort keys %{$self->{-form_extra_vars}});
88 }
89  
90 # matches a "double" encoded UTF-8 sequence within the range U+0000 - U+10FFFF
91 3 ▶use constant UTF8_DOUBLE_ENCODED_REGEX => qr/
Subroutine BEGIN: called CC=1 SCAR=0.0
92 \xC3 (?: [\x82-\x9F] \xC2 [\x80-\xBF] # U+0080 - U+07FF
93 | \xA0 \xC2 [\xA0-\xBF] \xC2 [\x80-\xBF] # U+0800 - U+0FFF
94 | [\xA1-\xAC] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+1000 - U+CFFF
95 | \xAD \xC2 [\x80-\x9F] \xC2 [\x80-\xBF] # U+D000 - U+D7FF
96 | [\xAE-\xAF] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+E000 - U+FFFF
97 | \xB0 \xC2 [\x90-\xBF] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+010000 - U+03FFFF
98 | [\xB1-\xB3] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+040000 - U+0FFFFF
99 | \xB4 \xC2 [\x80-\x8F] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+100000 - U+10FFFF
100 )
101 3 /x;
102 # matches a well-formed UTF-8 encoded sequence within the range U+0080 - U+10FFFF
103 3 ▶use constant UTF8_REGEX => qr/
Subroutine BEGIN: called CC=1 SCAR=0.0
104 (?: [\xC2-\xDF] [\x80-\xBF] # U+0080 - U+07FF
105 | \xE0 [\xA0-\xBF] [\x80-\xBF] # U+0800 - U+0FFF
106 | [\xE1-\xEC] [\x80-\xBF] [\x80-\xBF] # U+1000 - U+CFFF
107 | \xED [\x80-\x9F] [\x80-\xBF] # U+D000 - U+D7FF
108 | [\xEE-\xEF] [\x80-\xBF] [\x80-\xBF] # U+E000 - U+FFFF
109 | \xF0 [\x90-\xBF] [\x80-\xBF] [\x80-\xBF] # U+010000 - U+03FFFF
110 | [\xF1-\xF3] [\x80-\xBF] [\x80-\xBF] [\x80-\xBF] # U+040000 - U+0FFFFF
111 | \xF4 [\x80-\x8F] [\x80-\xBF] [\x80-\xBF] # U+100000 - U+10FFFF
112 )
113 3 /x;
114  
115 0 ▶sub has_utf8_chars {
Subroutine has_utf8_chars: not called CC=2 SCAR=17.9
Pod undocumented
116 0 ▶ shift if blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) 0 0 0
117 0 my ($string) = @_;
118 0 return $string =~ m/@{[ UTF8_REGEX ]}/og;
119 }
120  
121 0 ▶sub looks_like_double_encoded_utf8 {
Subroutine looks_like_double_encoded_utf8: not called CC=3 SCAR=24.8
Pod undocumented
122 0 ▶ shift if blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) 0 0 0
123 0 my ($string) = @_;
124 0 ▶ return $string =~ m/@{[ UTF8_REGEX ]}/og if utf8::is_utf8($string);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($string) 0 0 0
125 0 return $string =~ m/@{[ UTF8_DOUBLE_ENCODED_REGEX ]}/og;
126 }
127  
128 0 ▶sub decode_utf8 {
Subroutine decode_utf8: not called CC=6 SCAR=37.4
Pod undocumented
129 0 ▶ shift if blessed $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) 0 0 0
130 0 my ($input) = @_;
131 0 ▶ return $input if ! has_utf8_chars($input);
Branch: 1 branch
BranchTrueFalseTotal
unless has_utf8_chars($input) 0 0 0
132  
133 0 my $output = eval { decode('utf8', $input); };
134 0 ▶ return $input if $@; # if any error encountered, simply return input string
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
135  
136 # note: this second decode() does not seem to be necessary on linux, as no strings get double-encoded utf8; here just for macosx systems
137 0 ▶ $output = eval { decode('utf8', $output); } if has_utf8_chars($output);
Branch: 1 branch
BranchTrueFalseTotal
if has_utf8_chars($output) 0 0 0
138 0 ▶ return $input if $@; # if any error encountered, simply return input string
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
139 0 return $output;
140 }
141  
142 0 ▶sub js_escape {
Subroutine js_escape: not called CC=3 SCAR=24.8
Pod undocumented
143 0 ▶ shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
144 0 my ($str, $no_newline_conv) = @_;
145 0 $str =~ s|'|\\'|g;
146 0 $str =~ s|"|"|g;
147 0 ▶ $str =~ s,(?:\r\n|\r|\n),<br/>,g if ! $no_newline_conv;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_newline_conv 0 0 0
148 0 return $str;
149 }
150  
151 # note: this could be in AbstractDisplay if used only from this module, but it is here so it can be used by other modules like CGI::Widget::DBI::Browse
152 0 ▶sub translate {
Subroutine translate: not called CC=2 SCAR=17.9
Pod undocumented
153 0 my ($self, $string) = @_;
154 0 ▶ return $self->{-i18n_translation_strings}->{$string} || $string;
Condition0%0/3
$self->{'-i18n_translation_strings'}{$string} || $string
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'-i18n_translation_strings'}{$string} || $string
$self->{'-i18n_translation_strings'}{$string} $string
Truth table0%0/3
A || B
A= $self->{'-i18n_translation_strings'}{$string}B= $string
ABresult
1X1
011
000
155 }
156  
157  
158 3 1;
159 __END__
« Search/Display/Grid.pm ↑ Summary TEST/TestCase.pm »