blib/lib/JavaScript/DebugConsole.pm

filter: Statementstmt 92.0% 58 / 63 Branchbran 68.1% 15 / 22 Conditioncond 50.0% 10 / 20 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 88.8% 8 / 9 Podpod 60.0% 3 / 5 totaltotal 72.5% 95 / 131 CC 23 SCAR 23.0
CC
23
Cov
79%
debugConsole
16.1
new
6.6
_HashVariables
5.5
CRAP 10.0
↑ Summary
1 package JavaScript::DebugConsole;
2  
3 3 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 $VERSION = '0.01';
8  
9 1 ▶sub new {
Subroutine new: called CC=5 SCAR=18.9
Pod documented
10 1 my $proto = shift;
11 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
12 1 ▶ my $self = ($#_ == 0) ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 0 1 1
13 1 ▶ $self->{debug} = 1 if ( ! defined $self->{debug} || $self->{debug} !~ /^(0|1)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"debug"} and $self->{"debug"} =~ /^(0|1)$/ 1 0 1
Condition33%1/3
defined $self->{"debug"} and $self->{"debug"} =~ /^(0|1)$/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->{"debug"} and $self->{"debug"} =~ /^(0|1)$/
defined $self->{"debug"} $self->{"debug"} =~ /^(0|1)$/
Truth table33%1/3
A and B
A= defined $self->{"debug"}B= $self->{"debug"} =~ /^(0|1)$/
ABresult
0X0
100
111
14 1 return bless $self,$class;
15 }
16  
17 2 ▶sub debugConsole {
Subroutine debugConsole: called CC=15 SCAR=27.8
Pod documented
18 2 my $self = shift;
19 0 ▶ my %args = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 2 2
20  
21 2 ▶ $args{'title'} ||= 'POPUPConsole';
Condition50%1/2
$args{"title"} ||= "POPUPConsole"
l!l
20
MC/DC0%0/1
$args{"title"} ||= "POPUPConsole"
$args{"title"}
Truth table50%1/2
A
A= $args{"title"}
Aresult
11
00
22 2 ▶ $args{'auto_open'} = 1 if ! defined $args{'auto_open'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"auto_open"} 1 1 2
23 2 ▶ $args{'id'} = defined $args{'id'} || ( $$ . '_' . ++$self->{'popup_count'} );
Condition50%1/2
defined $args{'id'} || $$ . '_' . ++$self->{'popup_count'}
l!l
02
MC/DC0%0/1
defined $args{'id'} || $$ . '_' . ++$self->{'popup_count'}
defined $args{'id'}
Truth table50%1/2
A
A= defined $args{'id'}
Aresult
11
00
24 2 ▶ $args{'content'} ||= $self->{'content'};
Condition66%2/3
$args{"content"} ||= $self->{"content"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"content"} ||= $self->{"content"}
$args{"content"} $self->{"content"}
Truth table66%2/3
A ||= B
A= $args{"content"}B= $self->{"content"}
ABresult
1X1
011
000
25 2 ▶ $args{'env'} ||= \%ENV;
Condition50%1/2
$args{"env"} ||= \%ENV
l!l
02
MC/DC0%0/1
$args{"env"} ||= \%ENV
$args{"env"}
Truth table50%1/2
A
A= $args{"env"}
Aresult
11
00
26 2 ▶ $args{debug} = $self->{debug} if ( ! defined $args{debug} || $args{debug} !~ /^(0|1)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"debug"} and $args{"debug"} =~ /^(0|1)$/ 1 1 2
Condition66%2/3
defined $args{"debug"} and $args{"debug"} =~ /^(0|1)$/
!ll&&!rl&&r
101
MC/DC50%1/2
defined $args{"debug"} and $args{"debug"} =~ /^(0|1)$/
defined $args{"debug"} $args{"debug"} =~ /^(0|1)$/
Truth table66%2/3
A and B
A= defined $args{"debug"}B= $args{"debug"} =~ /^(0|1)$/
ABresult
0X0
100
111
27 2 ▶ $args{'popup_options'} ||= 'height=250,width=500,scrollbars=1,resizable=1,dependent,screenX=250,screenY=200,top=200,left=250';
Condition50%1/2
$args{"popup_options"} ||= "height=250,width=500,scrollbars=1,resizable=1,dependent,screenX=250,screenY=200,top=200,left=250"
l!l
02
MC/DC0%0/1
$args{"popup_options"} ||= "height=250,width=500,scrollbars=1,resizable=1,dependent,screenX=250,screenY=200,top=200,left=250"
$args{"popup_options"}
Truth table50%1/2
A
A= $args{"popup_options"}
Aresult
11
00
28  
29 # create javascript code
30 2 my $str = <<EOM;
31 <SCRIPT LANGUAGE="JavaScript1.2">
32 <!--
33 function OpenDebugConsole_$args{'id'}(title, caption, options) {
34 def_options = '$args{'popup_options'}';
35  
36 if ( !options )
37 options = def_options;
38  
39 // if our debug window is already open, just switch to it and navigate
40 var win = top.debugWin ;
41 if ( win && win.body && (! win.closed) ) {
42 win.focus();
43 }
44 // open debug win and write
45 else {
46 var win = window.open("",caption,options);
47 win.focus();
48 }
49 EOM
50 2 ▶ $str .= "win.document.writeln(\"<PRE>\")\n" if $args{'pre'};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"pre"} 0 2 2
51  
52 # print debug info
53 2 ▶ if ( $args{'debug'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"debug"}) 1 1 2
54 1 $args{'content'} .= <<EOM;
55 <TABLE BGCOLOR="#8888FF" BORDER="0" CELLPADDING="1" CELLSPACING="1">
56 <TR ALIGN="LEFT">
57 <TH COLSPAN="2"><FONT FACE="VERDANA,ARIAL" SIZE="4" COLOR="#FFFFFF">CGI/form environment</FONT></TH>
58 </TR>
59 <TR BGCOLOR="#CCCCCC">
60 <TH COLSPAN="2" ALIGN="LEFT"><FONT FACE="VERDANA,ARIAL" SIZE="3">FORM PARAMS</FONT></TH>
61 </TR>
62 <TR BGCOLOR="#EEEEEE">
63 <TD><FONT FACE="VERDANA,ARIAL" SIZE="-1">
64 EOM
65 1 $args{'content'} .= _HashVariables($args{'form'},"</FONT></TD>\n </TR>\n <TR BGCOLOR=\"#EEEEEE\">\n <TD><FONT FACE=\"VERDANA,ARIAL\" SIZE=\"-1\">","</FONT></TD>\n <TD><FONT FACE=\"VERDANA,ARIAL\" SIZE=\"-1\">");
66 1 $args{'content'} .= <<EOM;
67 </FONT></TD>
68 <TD></TD>
69 </TR>
70 <TR BGCOLOR="#CCCCCC">
71 <TH COLSPAN="2" ALIGN="LEFT"><FONT FACE="VERDANA,ARIAL" SIZE="3">ENVIRONMENT VARIABLES</FONT></TH>
72 </TR>
73 <TR BGCOLOR="#EEEEEE">
74 <TD><FONT FACE="VERDANA,ARIAL" SIZE="-1">
75 EOM
76 1 $args{'content'} .= _HashVariables($args{'env'},"</FONT></TD>\n\t</TR>\n <TR BGCOLOR=\"#EEEEEE\">\n <TD><FONT FACE=\"VERDANA,ARIAL\" SIZE=\"-1\">","</FONT></TD>\n <TD><FONT FACE=\"VERDANA,ARIAL\" SIZE=\"-1\">");
77 1 $args{'content'} .= <<EOM;
78 </FONT></TD>
79 <TD></TD>
80 </TR>
81 </TABLE>
82 <BR>
83 EOM
84 }
85
86 2 foreach my $debug_line( split(/\n/,$args{'content'}) ) {
87 166 $debug_line =~ s/cM//g;
88 166 $debug_line =~ s/\r//g;
89 166 $debug_line =~ s/'/\\'/g;
90 166 $debug_line =~ s/"/\\"/g;
91 166 $str .= "\twin.document.writeln(\"$debug_line\");\n";
92 }
93 2 ▶ $str .= "win.document.writeln(\"</PRE>\")\n" if $args{'pre'};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"pre"} 0 2 2
94 2 $str .= <<EOM;
95 win.document.close();
96 }
97 EOM
98 # Store JS function call into object property
99 2 $self->{'link'} = "OpenDebugConsole_$args{'id'}('$args{'title'}', '$args{'title'}','$args{'popup_options'}')";
100  
101 2 ▶ if ( $args{'auto_open'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"auto_open"}) 1 1 2
102 1 $str .= <<EOM;
103 // open js console
104 $self->{'link'}
105 EOM
106 }
107 2 $str .= <<EOM;
108 //-->
109 </SCRIPT>
110 EOM
111 2 $self->{'console'} = $str;
112 }
113  
114 1 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
115 1 my ($self) = shift;
116 1 $self->{content} .= join "\n", @_;
117 }
118  
119 2 ▶sub link {
Subroutine link: called CC=1 SCAR=0.0
Pod undocumented
120 2 my $self = shift;
121 2 return 'javascript:' . $self->{'link'};
122 }
123  
124 0 ▶sub console {
Subroutine console: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $self = shift;
126 0 $self->{'console'};
127 }
128  
129 2 ▶sub _HashVariables {
Subroutine _HashVariables: called CC=5 SCAR=17.0
130 2 my($hash,$separator,$equal) = @_;
131 2 my $str = '';
132 2 ▶ $equal = ' = ' unless $equal;
Branch: 1 branch
BranchTrueFalseTotal
unless $equal 0 2 2
133 2 eval { $hash->can('param') };
134 2 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 2 0 2
135 2 foreach(sort keys %$hash) {
136 35 $str .= $_ . $equal . $hash->{$_} . $separator;
137 }
138 }
139 else {
140 0 foreach(sort $hash->param) {
141 0 $str .= $_ . $equal . $hash->param($_) . $separator;
142 }
143 }
144 2 return $str;
145 }
146  
147 3 1;
148  
149 __END__
↑ Summary