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/GameMaster.pm »
1 package BalanceOfPower::Role::Logger;
2 11 $BalanceOfPower::Role::Logger::VERSION = '0.200000';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 has log_active => (
10 is => 'rw',
11 default => 1
12 );
13  
14 11 has log_name => (
15 is => 'rw',
16 default => "bop.log"
17 );
18  
19 has log_dir => (
20 is => 'rw',
21 172 ▶ default => sub { getcwd }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 11 );
23  
24 11 has log_on_stdout => (
25 is => 'rw',
26 default => 0
27 );
28  
29 sub log_path
30 {
31 4468 ▶ my $self = shift;
Subroutine log_path: called CC=1 SCAR=0.0
Pod undocumented
32 4468 return $self->log_dir . "/" .$self->log_name;
33 }
34  
35 sub log
36 {
37 4414 ▶ my $self = shift;
Subroutine log: called CC=3 SCAR=11.1
Pod undocumented
38 4414 ▶ return if(! $self->log_active);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->log_active 41 4373 4414
39 4373 my $message = shift;
40 4373 open(my $log, ">>", $self->log_path);
41 4373 print $log $message . "\n";
42 4373 close($log);
43 4373 ▶ if($self->log_on_stdout)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log_on_stdout) 0 4373 4373
44 {
45 0 print $message . "\n";
46 }
47 }
48  
49 sub delete_log
50 {
51 95 ▶ my $self = shift;
Subroutine delete_log: called CC=1 SCAR=0.0
Pod undocumented
52 95 unlink $self->log_path;
53 }
54  
55 11 1;
« lib/BalanceOfPower/Commands/AidInsurgents.pm ↑ Summary lib/BalanceOfPower/Role/GameMaster.pm »