blib/lib/Sentry/Logger.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 52 CC 3 SCAR 15.0
CC
3
Cov
0%
_print
12.0
_should_print
2.0
log
2.0
CRAP 4.5
1 package Sentry::Logger;
2 use Mojo::Base -base, -signatures;
3  
4 use Exporter qw(import);
5 use List::Util 'any';
6  
7 our @EXPORT_OK = qw(logger);
8  
9 has context => 'Sentry';
10 has active_contexts => sub { [split(/,/, $ENV{DEBUG} // '')] };
11  
12 sub _should_print ($self, $context) {
13 return any { $context =~ $_ } $self->active_contexts->@*;
14 }
15  
16 sub _print ($self, $message, $context, $error = 0) {
17 return unless $self->_should_print($context);
18 print { $error ? *STDOUT : *STDERR } qq{[$context] $message\n};
19 }
20  
21 sub log ($self, $message, $context = $self->context) {
22 $self->_print($message, $context);
23 }
24  
25 sub warn ($self, $message, $context = $self->context) {
26 $self->_print($message, $context, 1);
27 }
28  
29 sub error ($self, $message, $context = $self->context) {
30 $self->_print($message, $context, 1);
31 }
32  
33 sub enable ($self) {
34 $self->enabled(1);
35 }
36  
37 my $Instance;
38  
39 sub logger() {
40 $Instance //= Sentry::Logger->new;
41 return $Instance;
42 }
43  
44 1;