lib/BalanceOfPower/Role/Logger.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 88.8% 40 / 45 CC 3 SCAR 4.8
CC
3
Cov
94%
log
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« lib/BalanceOfPower/Commands/AidInsurgents.pm ↑ Summary lib/BalanceOfPower/Role/Herald.pm »
1 package BalanceOfPower::Role::Logger;
2 13 $BalanceOfPower::Role::Logger::VERSION = '0.400115';
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 has log_active => (
10 is => 'rw',
11 default => 1
12 );
13  
14 13 has log_name => (
15 is => 'rw',
16 default => "bop.log"
17 );
18  
19 has log_dir => (
20 is => 'rw',
21 120 ▶ default => sub { getcwd }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 13 );
23  
24 13 has log_on_stdout => (
25 is => 'rw',
26 default => 0
27 );
28  
29 sub log_path
30 4682 ▶{
Subroutine log_path: called CC=1 SCAR=0.0
Pod undocumented
31 4682 my $self = shift;
32 4682 return $self->log_dir . "/" .$self->log_name;
33 }
34  
35 sub log
36 4614 ▶{
Subroutine log: called CC=3 SCAR=11.1
Pod undocumented
37 4614 my $self = shift;
38 4614 ▶ return if(! $self->log_active);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->log_active 40 4574 4614
39 4574 my $message = shift;
40 4574 open(my $log, ">>", $self->log_path);
41 4574 print $log $message . "\n";
42 4574 close($log);
43 4574 ▶ if($self->log_on_stdout)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log_on_stdout) 0 4574 4574
44 {
45 0 print $message . "\n";
46 }
47 }
48  
49 sub delete_log
50 108 ▶{
Subroutine delete_log: called CC=1 SCAR=0.0
Pod undocumented
51 108 my $self = shift;
52 108 unlink $self->log_path;
53 }
54  
55 13 1;
« lib/BalanceOfPower/Commands/AidInsurgents.pm ↑ Summary lib/BalanceOfPower/Role/Herald.pm »