| 1 | package CGI::Application::Plugin::DevPopup; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 4 | $CGI::Application::Plugin::DevPopup::VERSION = '1.08'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use HTML::Template; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use CGI::Application 4.01; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | our @EXPORT = qw/ devpopup /; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | my ( $head, $script, $template ); # html stuff for our screen | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub import | ||||||||||||||||||||||||||||
| 18 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 19 | 3 | my $caller = scalar(caller); | |||||||||||||||||||||||||||
| 20 | 3 | ▶ | $caller->add_callback( 'postrun', \&_devpopup_output ) if $ENV{'CAP_DEVPOPUP_EXEC'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 3 | $caller->new_hook('devpopup_report'); | |||||||||||||||||||||||||||
| 22 | 3 | goto &Exporter::import; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub devpopup | ||||||||||||||||||||||||||||
| 26 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
devpopup: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 5 | my $app = shift; # a cgiapp object | |||||||||||||||||||||||||||
| 28 | 5 | my $dp = $app->param('__CAP_DEVPOPUP'); | |||||||||||||||||||||||||||
| 29 | 5 | ▶ | unless ($dp) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | 2 | $dp = bless [], __PACKAGE__; | |||||||||||||||||||||||||||
| 32 | 2 | $app->param( '__CAP_DEVPOPUP' => $dp ); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 5 | return $dp; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub add_report | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_report: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 3 | my $self = shift; # a devpopup object | |||||||||||||||||||||||||||
| 40 | 3 | my %params = @_; | |||||||||||||||||||||||||||
| 41 | 3 | ▶ | $params{severity} ||= 'info'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params{"severity"} ||= "info"
MC/DC0%0/1
$params{"severity"} ||= "info"
$params{"severity"}
Truth table50%1/2
A
A= $params{"severity"}
| |||||||||||||||||||||||||||||
| 42 | 3 | push @$self, \%params; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub _devpopup_output | ||||||||||||||||||||||||||||
| 46 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_devpopup_output: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 47 | 2 | my ( $self, $outputref ) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | return unless $self->header_type eq 'header'; # don't operate on redirects or 'none' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 2 | my %props = $self->header_props; | |||||||||||||||||||||||||||
| 51 | 2 | my ($type) = grep /type/i, keys %props; | |||||||||||||||||||||||||||
| 52 | return if defined $type and # no type defaults to html, so we have work to do. | ||||||||||||||||||||||||||||
| 53 | 2 | ▶ | $props{$type} !~ /html/i; # else skip any other types. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $type and not $props{$type} =~ /html/i
MC/DC0%0/2
defined $type and not $props{$type} =~ /html/i
defined $type
not $props{$type} =~ /html/i
Truth table33%1/3
A and not(B)
A= defined $typeB= not $props{$type} =~ /html/i
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | my $devpopup = $self->devpopup; | |||||||||||||||||||||||||||
| 56 | 2 | $self->call_hook( 'devpopup_report', $outputref ); # process our callback hook | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | my $tmpl = HTML::Template->new( | |||||||||||||||||||||||||||
| 59 | scalarref => \$template, | ||||||||||||||||||||||||||||
| 60 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||
| 61 | loop_context_vars => 1, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 2 | $tmpl->param( | |||||||||||||||||||||||||||
| 64 | reports => $devpopup, | ||||||||||||||||||||||||||||
| 65 | app_class => ref($self), | ||||||||||||||||||||||||||||
| 66 | runmode => $self->get_current_runmode, | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | my $o = _escape_js($tmpl->output); | |||||||||||||||||||||||||||
| 70 | 2 | my $h = _escape_js($head); | |||||||||||||||||||||||||||
| 71 | 0 | my $j = _escape_js($script . join($/, map { $_->{script} } grep exists $_->{script}, @$devpopup) ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | my $js = qq{ | |||||||||||||||||||||||||||
| 74 | <script language="javascript"> | ||||||||||||||||||||||||||||
| 75 | var devpopup_window = window.open("", "devpopup_window", "height=400,width=600,scrollbars,resizable"); | ||||||||||||||||||||||||||||
| 76 | devpopup_window.document.write("$h"); | ||||||||||||||||||||||||||||
| 77 | devpopup_window.document.write("\t<s"); | ||||||||||||||||||||||||||||
| 78 | devpopup_window.document.write("cript type=\\"text/javascript\\">\\n"); | ||||||||||||||||||||||||||||
| 79 | devpopup_window.document.write("//"+"<"+"![CDATA[\\n"); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | devpopup_window.document.write("$j"); | ||||||||||||||||||||||||||||
| 82 | devpopup_window.document.write("//]"+"]>\\n"); | ||||||||||||||||||||||||||||
| 83 | devpopup_window.document.write("\t<"); | ||||||||||||||||||||||||||||
| 84 | devpopup_window.document.write("/script>"); | ||||||||||||||||||||||||||||
| 85 | devpopup_window.document.write("$o"); | ||||||||||||||||||||||||||||
| 86 | devpopup_window.document.close(); | ||||||||||||||||||||||||||||
| 87 | devpopup_window.focus(); | ||||||||||||||||||||||||||||
| 88 | </script> | ||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # insert the js code before the body close, | ||||||||||||||||||||||||||||
| 92 | # if one exists | ||||||||||||||||||||||||||||
| 93 | 2 | ▶ | if ( $$outputref =~ m!</body>!i ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 2 | $$outputref =~ s!</body>!$js\n</body>!i; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 0 | $$outputref .= $js; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub _escape_js | ||||||||||||||||||||||||||||
| 104 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_escape_js: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 6 | my $j = shift; | |||||||||||||||||||||||||||
| 106 | 6 | $j =~ s/\r//g; | |||||||||||||||||||||||||||
| 107 | 6 | $j =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||
| 108 | 6 | $j =~ s/"/\\"/g; | |||||||||||||||||||||||||||
| 109 | 6 | $j =~ s/\n/\\n" + \n\t"/g; | |||||||||||||||||||||||||||
| 110 | 6 | $j =~ s/script>/s" + "cript>/g; | |||||||||||||||||||||||||||
| 111 | 6 | $j; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 4 | $head = <<HEAD; | |||||||||||||||||||||||||||
| 115 | <?xml version="1.0"?> | ||||||||||||||||||||||||||||
| 116 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||||||||||||||||||||||||||||
| 117 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | <html xmlns="http://www.w3.org/1999/xhtml"> | ||||||||||||||||||||||||||||
| 120 | <head> | ||||||||||||||||||||||||||||
| 121 | <title>Devpopup results</title> | ||||||||||||||||||||||||||||
| 122 | <style type="text/css"> | ||||||||||||||||||||||||||||
| 123 | div.report { border: dotted 1px black; margin: 1em;} | ||||||||||||||||||||||||||||
| 124 | div.report h2 { color: #000; background-color: #ddd; padding:.2em; margin-top:0;} | ||||||||||||||||||||||||||||
| 125 | div.report_full, div.report_summary { padding: 0em 1em; } | ||||||||||||||||||||||||||||
| 126 | a:hover, div.report h2:hover, a.print_button:hover { cursor: pointer; background-color: #eee; } | ||||||||||||||||||||||||||||
| 127 | a { text-decoration: underline } | ||||||||||||||||||||||||||||
| 128 | a.print_button { text-align: right; float: right; clear: right; padding: .2em; margin-right: 1em; color: #000; background-color:#ddd; border:solid 1px #444; } | ||||||||||||||||||||||||||||
| 129 | // severity colors | ||||||||||||||||||||||||||||
| 130 | .sev_debug { background-color: #ccffcc; color: #000; } | ||||||||||||||||||||||||||||
| 131 | .sev_info { } // default | ||||||||||||||||||||||||||||
| 132 | .sev_warning { background-color: #ffff99; color: #000; } | ||||||||||||||||||||||||||||
| 133 | .sev_error { background-color: #ff9999; color: #000; } | ||||||||||||||||||||||||||||
| 134 | .sev_fatal { background-color: #ff6600; color: #fff; font-weight: bold; } | ||||||||||||||||||||||||||||
| 135 | </style> | ||||||||||||||||||||||||||||
| 136 | HEAD | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 4 | $script = <<JS; | |||||||||||||||||||||||||||
| 139 | function swap(id1,id2) | ||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | var d1 = document.getElementById(id1); | ||||||||||||||||||||||||||||
| 142 | var d2 = document.getElementById(id2); | ||||||||||||||||||||||||||||
| 143 | var s = d1.style.display; | ||||||||||||||||||||||||||||
| 144 | d1.style.display = d2.style.display; | ||||||||||||||||||||||||||||
| 145 | d2.style.display = s; | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | JS | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | $template = <<TMPL; | |||||||||||||||||||||||||||
| 150 | </head> | ||||||||||||||||||||||||||||
| 151 | <body> | ||||||||||||||||||||||||||||
| 152 | <h1>Devpopup report for <tmpl_var app_class> -> <tmpl_var runmode></h1> | ||||||||||||||||||||||||||||
| 153 | <a href="javascript:window.print()" class="print_button">Print</a> | ||||||||||||||||||||||||||||
| 154 | <div id="titles"> | ||||||||||||||||||||||||||||
| 155 | <ul> | ||||||||||||||||||||||||||||
| 156 | <tmpl_loop reports> | ||||||||||||||||||||||||||||
| 157 | <li class="sev_<tmpl_var severity>"> | ||||||||||||||||||||||||||||
| 158 | <a onclick="swap('#DPS<tmpl_var __counter__>','#DPR<tmpl_var __counter__>')"><tmpl_var title></a> - <tmpl_var summary> | ||||||||||||||||||||||||||||
| 159 | </li> | ||||||||||||||||||||||||||||
| 160 | </tmpl_loop> | ||||||||||||||||||||||||||||
| 161 | </ul> | ||||||||||||||||||||||||||||
| 162 | </div> | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | <tmpl_loop reports> | ||||||||||||||||||||||||||||
| 165 | <div id="#DP<tmpl_var __counter__>" class="report"> | ||||||||||||||||||||||||||||
| 166 | <h2 id="#DPH<tmpl_var __counter__>" | ||||||||||||||||||||||||||||
| 167 | class="sev_<tmpl_var severity>" | ||||||||||||||||||||||||||||
| 168 | onclick="swap('#DPS<tmpl_var __counter__>','#DPR<tmpl_var __counter__>')"> | ||||||||||||||||||||||||||||
| 169 | <tmpl_var title> | ||||||||||||||||||||||||||||
| 170 | </h2> | ||||||||||||||||||||||||||||
| 171 | <div id="#DPS<tmpl_var __counter__>" class="report_summary"> | ||||||||||||||||||||||||||||
| 172 | <tmpl_var summary> | ||||||||||||||||||||||||||||
| 173 | </div> | ||||||||||||||||||||||||||||
| 174 | <div id="#DPR<tmpl_var __counter__>" class="report_full" style="display:none"><tmpl_var report></div> | ||||||||||||||||||||||||||||
| 175 | </div> | ||||||||||||||||||||||||||||
| 176 | </tmpl_loop> | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | </body> | ||||||||||||||||||||||||||||
| 179 | </html> | ||||||||||||||||||||||||||||
| 180 | TMPL | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 4 | 1; # End of CGI::Application::Plugin::DevPopup | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||