blib/lib/App/MaMGal/Logger.pm

filter: Statementstmt 100% 43 / 43 Branchbran 88.8% 16 / 18 Conditioncond 87.5% 7 / 8 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 91.5% 76 / 83 CC 15 SCAR 20.4
CC
15
Cov
96%
log_exception
12.1
log_message
3.0
init
2.0
CRAP 7.7
« blib/lib/App/MaMGal/Maker.pm ↑ Summary testlib/App/MaMGal/TestHelper.pm »
1 # mamgal - a program for creating static image galleries
2 # Copyright 2007-2009 Marcin Owsiany <marcin@owsiany.pl>
3 # See the README file for license information
4 # A logging subsystem class
5 package App::MaMGal::Logger;
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base 'App::MaMGal::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub init
12 6 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod undocumented
13 6 my $self = shift;
14 6 ▶ my $fh = shift or croak "filehandle arg required";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = shift() or croak("filehandle arg required") 5 1 6
15 5 $self->{fh} = $fh;
16 }
17  
18 sub log_message
19 21 ▶{
Subroutine log_message: called CC=3 SCAR=11.0
Pod undocumented
20 21 my $self = shift;
21 21 my $msg = shift;
22 21 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
165
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
23 21 ▶ $prefix .= ': ' if $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 16 5 21
24 21 $self->{fh}->printf("%s%s\n", $prefix, $msg);
25 }
26  
27 1 our $not_available_warned_before = 0;
28 1 our $exe_failure_warned_before = 0;
29  
30 sub log_exception
31 11 ▶{
Subroutine log_exception: called CC=12 SCAR=24.9
Pod undocumented
32 11 my $self = shift;
33 11 my $e = shift;
34 11 my $prefix = shift;
35 11 ▶ if ($e->isa('App::MaMGal::MplayerWrapper::NotAvailableException')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($e->isa('App::MaMGal::MplayerWrapper::NotAvailableException')) { } 2 9 11
elsif ($e->isa('App::MaMGal::MplayerWrapper::ExecutionFailureException')) { } 3 6 9
elsif ($e->isa('App::MaMGal::SystemException')) { } 2 4 6
36 # TODO this needs to be made thread-safe
37 2 ▶ return if $not_available_warned_before;
Branch: 1 branch
BranchTrueFalseTotal
if $App::MaMGal::Logger::not_available_warned_before 1 1 2
38 1 $not_available_warned_before = 1;
39 } elsif ($e->isa('App::MaMGal::MplayerWrapper::ExecutionFailureException')) {
40 # TODO this needs to be made thread-safe
41 3 ▶ goto JUST_LOG if $exe_failure_warned_before or (! $e->stdout and ! $e->stderr);
Branch: 1 branch
BranchTrueFalseTotal
if $App::MaMGal::Logger::exe_failure_warned_before or not $e->stdout || $e->stderr 2 1 3
Condition83%5/6
$App::MaMGal::Logger::exe_failure_warned_before or not $e->stdout || $e->stderr
l!l&&r!l&&!r
111
$e->stdout || $e->stderr
l!l&&r!l&&!r
101
MC/DC66%2/3
$App::MaMGal::Logger::exe_failure_warned_before or not $e->stdout || $e->stderr
$App::MaMGal::Logger::exe_failure_warned_before $e->stdout $e->stderr
Truth table75%3/4
A or not(B || C)
A= $App::MaMGal::Logger::exe_failure_warned_beforeB= $e->stdoutC= $e->stderr
ABCresult
1XX1
0001
01X0
0010
42 1 $exe_failure_warned_before = 1;
43 1 $self->log_message($e->message, $prefix);
44 1 $self->log_message('--------------------- standard output messages -------------------', $prefix);
45 1 ▶ $self->log_message($_, $prefix) for $e->stdout ? @{$e->stdout} : ();
Branch: 1 branch
BranchTrueFalseTotal
$e->stdout ? : 1 0 1
46 1 $self->log_message('--------------------- standard error messages --------------------', $prefix);
47 1 ▶ $self->log_message($_, $prefix) for $e->stderr ? @{$e->stderr} : ();
Branch: 1 branch
BranchTrueFalseTotal
$e->stderr ? : 1 0 1
48 1 $self->log_message('------------------------------------------------------------------', $prefix);
49 1 return;
50 } elsif ($e->isa('App::MaMGal::SystemException')) {
51 2 $self->log_message($e->interpolated_message);
52 2 return;
53 }
54 JUST_LOG:
55 7 $self->log_message($e->message, $prefix);
56 }
57  
58 1 1;
« blib/lib/App/MaMGal/Maker.pm ↑ Summary testlib/App/MaMGal/TestHelper.pm »