| 1 | package POE::XUL::Logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: Logging.pm 1566 2010-11-03 03:13:32Z fil $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright Philip Gwyn 2007-2010. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Handle logging features for the application | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | ▶ | use Scalar::Util qw( reftype blessed openhandle ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | ▶ | use constant DEBUG => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 20 | our $VERSION = '0.0600'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | our @EXPORT_OK = qw( xwarn xlog xdebug xcarp xcarp2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 20 | our @EXPORT = @EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 20 | our $SINGLETON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # To interface with log4perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | my %type2level = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | DEBUG => 10000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | LOG => 20000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | REQ => 20000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | WARN => 30000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | SETUP => 42000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | my( $package, $args, $log_root ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | my $rt = reftype $args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | if( $args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | if( !$rt or $rt eq 'CODE' or $rt eq 'HASH' or blessed $args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
not $rt or $rt eq "CODE" or $rt eq "HASH" or builtin::blessed($args)
not $rt or $rt eq "CODE" or $rt eq "HASH"
not $rt or $rt eq "CODE"
MC/DC75%3/4
not $rt or $rt eq "CODE" or $rt eq "HASH" or builtin::blessed($args)
not $rt
$rt eq "CODE"
$rt eq "HASH"
builtin::blessed($args)
Truth table80%4/5
not(A) or B or C or D
A= not $rtB= $rt eq "CODE"C= $rt eq "HASH"D= builtin::blessed($args)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | elsif( $rt eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if( 2 > @$args ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | croak "logging parameter must have at least 2 elements"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | croak "logging parameter must be a CODE ref, ARRAY ref, scalar or a log4perl object"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | my $self = $SINGLETON = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | bless { logger=>$args, log_root=>$log_root }, $package; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | if( $rt and $rt eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$rt and $rt eq "HASH"
MC/DC100%2/2
$rt and $rt eq "HASH"
$rt
$rt eq "HASH"
Truth table100%3/3
A and B
A= $rtB= $rt eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | $self->{logger} = $args->{logger}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $self->{access_log} = $args->{access_log}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | $self->{error_log} = $args->{error_log}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | $self->__init_apps( $args->{apps} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | return $SINGLETON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | sub __init_apps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | my( $self, $apps ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__init_apps: called CC=8 SCAR=21.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | unless( $apps ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $self->{apps} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | unless( ref $apps ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $apps = { $apps=>$apps }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | elsif( 'ARRAY' eq ref $apps ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my %A; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | @A{@$apps} = @$apps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $apps = \%A; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | $self->{apps} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | while( my( $app, $def ) = each %$apps ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | push @{ $self->{apps} }, $app; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | foreach my $t ( qw( access error ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | my $log = "${t}_log"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | unless( ref $def ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | $file = File::Spec->catfile( $def, $log ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | elsif( $def->{$log} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $file = $def->{$log}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $file = File::Spec->catfile( $app, $log ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | $self->{"$app-$t-log"} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | ▶ | $self->{logger} ||= \&default_sub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"logger"} ||= \&POE::XUL::Logging::default_sub
MC/DC100%1/1
$self->{"logger"} ||= \&POE::XUL::Logging::default_sub
$self->{"logger"}
Truth table100%2/2
A
A= $self->{"logger"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | $self->dispatch( { type => 'SETUP', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | directory => $self->{log_root} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Dispatch the exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | sub dispatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 31 | ▶ | my( $self, $exception ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 31 | ▶ | $self = $SINGLETON unless blessed $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 31 | ▶ | $exception = { message => $exception, type => 'LOG' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | unless ref $exception; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 31 | my $rt = reftype $self->{logger}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 31 | ▶ | if( blessed $self->{logger} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | ▶ | return if $exception->{type} eq 'SETUP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | my $lvl = $type2level{ $exception->{type} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | $lvl ||= $type2level{ 'LOG' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$lvl ||= $type2level{"LOG"}
MC/DC0%0/2
$lvl ||= $type2level{"LOG"}
$lvl
$type2level{"LOG"}
Truth table66%2/3
A ||= B
A= $lvlB= $type2level{"LOG"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | $self->{logger}->log( $lvl, $exception->{message} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | elsif( not $rt ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | $POE::Kernel::poe_kernel->call( $self->{logger}, 'log', $exception ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | elsif( $rt eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # warn "POE logger @{ $self->{logger} }"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | $POE::Kernel::poe_kernel->call( @{ $self->{logger} }, $exception ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif( $rt eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 15 | $self->{logger}->( $exception ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sub default_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | my( $ex ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_sub: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | ▶ | $ex->{type} ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ex->{"type"} ||= ""
MC/DC0%0/1
$ex->{"type"} ||= ""
$ex->{"type"}
Truth table50%1/2
A
A= $ex->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 9 | ▶ | if( $ex->{type} eq 'SETUP' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $SINGLETON->default_setup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | if( $ex->{type} and $ex->{type} ne 'REQ' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ex->{"type"} and $ex->{"type"} ne "REQ"
MC/DC50%1/2
$ex->{"type"} and $ex->{"type"} ne "REQ"
$ex->{"type"}
$ex->{"type"} ne "REQ"
Truth table66%2/3
A and B
A= $ex->{"type"}B= $ex->{"type"} ne "REQ"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | $ex->{message} = "$ex->{type} $ex->{message}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | $SINGLETON->default( @_ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | sub default_setup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_setup: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | $self = $SINGLETON unless blessed $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $self->{stderr_fh} = $self->open_file( qw( error_log error_log ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $self->{error_fh} = $self->{stderr_fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | $self->{log_fh} = $self->open_file( qw( access_log access_log ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $self->{access_fh} = $self->{log_fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | foreach my $app ( @{ $self->{apps} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | foreach my $t ( qw( error access ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | if( $self->{"$app-$t-log"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | $self->{"$app-$t-fh"} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | $self->open_file( "$app-$t-log", "$app/${t}_log" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->{"$app-$t-fh"} = $self->{"${t}_fh"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | sub open_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | ▶ | my( $self, $key, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_file: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 6 | my $file = $self->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | $file ||= File::Spec->catfile( $self->{log_root}, $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$file ||= "File::Spec"->catfile($self->{"log_root"}, $name)
MC/DC0%0/2
$file ||= "File::Spec"->catfile($self->{"log_root"}, $name)
$file
"File::Spec"->catfile($self->{"log_root"}, $name)
Truth table33%1/3
A ||= B
A= $fileB= "File::Spec"->catfile($self->{"log_root"}, $name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | ▶ | unless( File::Spec->file_name_is_absolute( $file ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | $file = File::Spec->catfile( $self->{log_root}, $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | $self->{$key} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | my( $vol, $dir, $f ) = File::Spec->splitpath( $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | ▶ | if( $dir and not -d $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dir and not -d $dir
MC/DC50%1/2
$dir and not -d $dir
$dir
not -d $dir
Truth table66%2/3
A and not(B)
A= $dirB= not -d $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | File::Path::mkpath( [ $dir ], 0, 0750 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | my $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | unless( $fh->open(">> $file") ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | warn "AUGH $file: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | die "Unable to create log file $file: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | $fh->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | return $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | sub default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | my( $self, $exception ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=12 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | $self = $SINGLETON unless blessed $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | ▶ | my $type = $exception->{type}||''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$exception->{'type'} || ''
MC/DC0%0/1
$exception->{'type'} || ''
$exception->{'type'}
Truth table50%1/2
A
A= $exception->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 8 | my $msg = $exception->{message}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | ▶ | $msg = '' unless defined $msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | $msg =~ s/\n+$// if $exception->{location}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | ▶ | if( $msg !~ /\n$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $msg .= " at $exception->{caller}[1] line $exception->{caller}[2]" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | ▶ | if $exception->{caller}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | $msg .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | ▶ | my $app = $self->{app}||'THERE-IS-NO-APP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'app'} || 'THERE-IS-NO-APP'
MC/DC100%1/1
$self->{'app'} || 'THERE-IS-NO-APP'
$self->{'app'}
Truth table100%2/2
A
A= $self->{'app'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | ▶ | my $t = $type eq 'REQ' ? 'access' : 'error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | ▶ | my $fh = $self->{"$app-$t-fh"} || $self->{"${t}_fh"} || $self->{stderr_fh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$$self{"$app-$t-fh"} || $$self{"${t}_fh"} || $self->{'stderr_fh'}
$$self{"$app-$t-fh"} or $$self{"${t}_fh"}
MC/DC0%0/3
$$self{"$app-$t-fh"} || $$self{"${t}_fh"} || $self->{'stderr_fh'}
$$self{"$app-$t-fh"}
$$self{"${t}_fh"}
$self->{'stderr_fh'}
Truth table50%2/4
A or B || C
A= $$self{"$app-$t-fh"}B= $$self{"${t}_fh"}C= $self->{'stderr_fh'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | if( $fh ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | $fh->print( $msg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | print STDERR $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | sub __mk_exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 22 | ▶ | my( $package, $type, $level, @msg ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__mk_exception: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 22 | local $, = $,; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 22 | ▶ | $, = '' unless defined $,; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 22 | message => join( $,, grep {defined} @msg), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | caller => [ caller( $level ) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sub xdebug | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | ▶ | return carp join( '' , @_ ) unless $SINGLETON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdebug: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | $SINGLETON->dispatch( $SINGLETON->__mk_exception( 'DEBUG', 1, @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub xwarn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 7 | ▶ | return carp join( '' , @_ ) unless $SINGLETON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xwarn: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 7 | $SINGLETON->dispatch( $SINGLETON->__mk_exception( 'WARN', 1, @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | sub xcarp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | ▶ | my $ex = $SINGLETON->__mk_exception( 'WARN', 2, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xcarp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 5 | $ex->{location} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | $SINGLETON->dispatch( $ex ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | sub xcarp2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my $ex = $SINGLETON->__mk_exception( 'WARN', 3, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xcarp2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $ex->{location} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $SINGLETON->dispatch( $ex ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | sub xlog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 9 | ▶ | my $ex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlog: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 9 | ▶ | if( 1==@_ and 'HASH' eq ref $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
1 == @_ and "HASH" eq ref $_[0]
MC/DC50%1/2
1 == @_ and "HASH" eq ref $_[0]
1 == @_
"HASH" eq ref $_[0]
Truth table66%2/3
A and B
A= 1 == @_B= "HASH" eq ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | $ex = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | ▶ | $ex->{type} ||= 'LOG'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ex->{"type"} ||= "LOG"
MC/DC0%0/1
$ex->{"type"} ||= "LOG"
$ex->{"type"}
Truth table50%1/2
A
A= $ex->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | ▶ | $ex->{caller} ||= [ caller( 0 ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ex->{"caller"} ||= [caller 0]
MC/DC0%0/1
$ex->{"caller"} ||= [caller 0]
$ex->{"caller"}
Truth table50%1/2
A
A= $ex->{"caller"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 5 | $ex = $SINGLETON->__mk_exception( 'LOG', 1, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | $SINGLETON->dispatch( $ex ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||