| 1 | package App::Commando::Logger; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 9 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use Scalar::Util qw(openhandle); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 9 | has 'device' => ( is => 'ro' ); | |||||||||
| 11 | 9 | has 'formatter' => ( is => 'rw' ); | |||||||||
| 12 | 9 | has 'level' => ( is => 'rw' ); | |||||||||
| 13 | |||||||||||
| 14 | 13 | ▶ | sub BUILDARGS { | ||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | 13 | my ($class, $device) = @_; | |||||||||
| 16 | |||||||||||
| 17 | return { | ||||||||||
| 18 | 13 | device => $device, | |||||||||
| 19 | }; | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 13 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 23 | 13 | my ($self) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 13 | eval { | |||||||||
| 26 | 13 | $self->{_fh} = openhandle($self->device); | |||||||||
| 27 | 13 | ▶ | open($self->{_fh}, '>>', $self->device) if !defined $self->{_fh}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | }; | ||||||||||
| 29 | 13 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | croak 'Can\'t open log device'; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 13 | return $self; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 9 | my %levels = ( | |||||||||
| 37 | 'debug' => 1, | ||||||||||
| 38 | 'info' => 2, | ||||||||||
| 39 | 'warn' => 3, | ||||||||||
| 40 | 'error' => 4, | ||||||||||
| 41 | 'fatal' => 5, | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | 11 | ▶ | sub _store { | ||||||||
|
Subroutine
_store: called CC=3 SCAR=16.5
| |||||||||||
| 45 | 11 | my ($self, $level, $message) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 11 | ▶ | if ($levels{lc $level} >= $levels{lc $self->{level}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | print { $self->{_fh} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | ref($self->formatter) eq 'CODE' ? | ||||||||||
| 50 | $self->formatter->($level, $message) : $message; | ||||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 11 | ▶ | sub debug { | ||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 55 | 11 | my ($self, $message) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 11 | $self->_store('debug', $message); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub info { | ||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | 0 | my ($self, $message) = @_; | |||||||||
| 62 | |||||||||||
| 63 | 0 | $self->_store('info', $message); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub warn { | ||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 67 | 0 | my ($self, $message) = @_; | |||||||||
| 68 | |||||||||||
| 69 | 0 | $self->_store('warn', $message); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | sub error { | ||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 73 | 0 | my ($self, $message) = @_; | |||||||||
| 74 | |||||||||||
| 75 | 0 | $self->_store('error', $message); | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub fatal { | ||||||||
|
Subroutine
fatal: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 79 | 0 | my ($self, $message) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 0 | $self->_store('fatal', $message); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 9 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||