blib/lib/BalanceOfPower/Role/Logger.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 CC 3 SCAR 16.7
CC
3
Cov
0%
log
12.0
log_path
2.0
delete_log
2.0
CRAP 5.3
1 package BalanceOfPower::Role::Logger;
2 $BalanceOfPower::Role::Logger::VERSION = '0.200000';
3 use strict;
4 use v5.10;
5 use Moo::Role;
6  
7 use Cwd;
8  
9 has log_active => (
10 is => 'rw',
11 default => 1
12 );
13  
14 has log_name => (
15 is => 'rw',
16 default => "bop.log"
17 );
18  
19 has log_dir => (
20 is => 'rw',
21 default => sub { getcwd }
22 );
23  
24 has log_on_stdout => (
25 is => 'rw',
26 default => 0
27 );
28  
29 sub log_path
30 {
31 my $self = shift;
32 return $self->log_dir . "/" .$self->log_name;
33 }
34  
35 sub log
36 {
37 my $self = shift;
38 return if(! $self->log_active);
39 my $message = shift;
40 open(my $log, ">>", $self->log_path);
41 print $log $message . "\n";
42 close($log);
43 if($self->log_on_stdout)
44 {
45 print $message . "\n";
46 }
47 }
48  
49 sub delete_log
50 {
51 my $self = shift;
52 unlink $self->log_path;
53 }
54  
55 1;