| 1 | package CGI::Application::Plugin::DebugMessage; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use CGI::Application 3.21; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||
| 17 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 18 | debug_ocode | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $prefix = "CAP_DeubgMessage"; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my $caller = scalar(caller); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | $caller->add_callback('postrun', 'CGI::Application::Plugin::DebugMessage::log2footer'); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | goto &Exporter::import; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | my @added = @_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (@added) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | my $footer = $self->param("${prefix}_footer") || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->param("${prefix}_footer") || []
MC/DC100%1/1
$self->param("${prefix}_footer") || []
$self->param("${prefix}_footer")
Truth table100%2/2
A
A= $self->param("${prefix}_footer")
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | my $caller = bless([caller(0)], "${prefix}::Caller"); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | @added = map { [$caller, $_] } @added; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | push(@{$footer}, @added); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | $self->param("${prefix}_footer" => $footer) | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub debug_ocode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug_ocode: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $self->param("${prefix}_code" => $code) if (UNIVERSAL::can($self, 'param')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub log2footer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log2footer: called CC=12 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $footer = $self->param("${prefix}_footer") ? $self->param("${prefix}_footer") : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | return unless ($footer and ref($footer) eq 'ARRAY' and @{$footer}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$footer and ref $footer eq "ARRAY" and @{$footer;}
$footer and ref $footer eq "ARRAY"
MC/DC0%0/3
$footer and ref $footer eq "ARRAY" and @{$footer;}
$footer
ref $footer eq "ARRAY"
@{$footer;}
Truth table25%1/4
A and B and C
A= $footerB= ref $footer eq "ARRAY"C= @{$footer;}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my $html = "<hr />\n" . $self->dump_html() . "<p>Debug Messages:</p>\n<ol>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | foreach my $message (@{$footer}) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my $caller = undef; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | ($caller, $message) = @{$message} if (ref($message) eq 'ARRAY' and @{$message} and ref($message->[0]) eq "${prefix}::Caller"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $message eq "ARRAY" and @{$message;} and ref $message->[0] eq "${prefix}::Caller"
ref $message eq "ARRAY" and @{$message;}
MC/DC0%0/3
ref $message eq "ARRAY" and @{$message;} and ref $message->[0] eq "${prefix}::Caller"
ref $message eq "ARRAY"
@{$message;}
ref $message->[0] eq "${prefix}::Caller"
Truth table25%1/4
A and B and C
A= ref $message eq "ARRAY"B= @{$message;}C= ref $message->[0] eq "${prefix}::Caller"
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | $caller = sprintf("[%s(%s)] ", $caller->[0], $caller->[2]) if ($caller); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | # HTML escape and dump (if necessary) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if (ref($message)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | $string = CGI::Application::Plugin::DebugMessage::dump_pretty($self, $message); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $string = CGI->pre($string); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $string = CGI->escapeHTML($message); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | $string = CGI::Application::Plugin::DebugMessage::convert_code($self, $string) if ($self->param("${prefix}_code")); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | $html .= CGI->li($caller . $string) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | $html .= "</ol>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | $$ref =~ s/(<\/html>|$)/$html$1/i; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | sub dump_pretty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_pretty: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | eval ' | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | local $Data::Dumper::Indent = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | local $Data::Dumper::Sortkeys = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | local $Data::Dumper::Terse = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | '; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | return join(", ", @_) if ($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | return unless (@_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my $dump = Dumper(@_); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return $dump; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub convert_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_code: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $ref = ref($str) ? $str : \$str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $class = ref($self) ? ref($self) : $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $ocode = $self->param("${prefix}_code"); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return $str unless (length($str)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return $str unless ($ocode); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | # Use Jcode | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | eval "use Jcode"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return $str if ($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | # Guess input code | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my ($icode, $match) = Jcode::getcode($$ref); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $icode = 'euc' if ($icode eq undef and $match > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$icode eq undef and $match > 0
MC/DC0%0/2
$icode eq undef and $match > 0
$icode eq undef
$match > 0
Truth table0%0/3
A and B
A= $icode eq undefB= $match > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($icode eq 'euc') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $re_sjis = '[\201-\237\340-\374][\100-\176\200-\374]|[\241-\337]|[\x00-\x7F]'; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $re_euc = '[\241-\376][\241-\376]|\216[\241-\337]|\217[\241-\376][\241-\376]|[\x00-\x7F]'; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $icode = 'sjis' if ($$ref !~ /^(?:$re_euc)*$/o and $str =~ /^(?:$re_sjis)*$/o); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $$ref =~ /^(?:$re_euc)*$/o and $str =~ /^(?:$re_sjis)*$/o
MC/DC0%0/2
not $$ref =~ /^(?:$re_euc)*$/o and $str =~ /^(?:$re_sjis)*$/o
not $$ref =~ /^(?:$re_euc)*$/o
$str =~ /^(?:$re_sjis)*$/o
Truth table0%0/3
not(A) and B
A= not $$ref =~ /^(?:$re_euc)*$/oB= $str =~ /^(?:$re_sjis)*$/o
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # Convert | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $$ref = Jcode::jcode($ref, $icode)->$ocode if ($icode ne $ocode); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||||||||||||||||