lib/Log/Any/Adapter/Mojo.pm

filter: Statementstmt 76.9% 40 / 52 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 1 totaltotal 72.4% 50 / 69 CC 2 SCAR 2.9
CC
2
Cov
75%
init
2.3
__ANON__
2.0
__ANON__
1.5
CRAP 1.3
↑ Summary
1 package Log::Any::Adapter::Mojo;
2  
3 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $Log::Any::Adapter::Mojo::VERSION = '0.06';
5 }
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::Any::Adapter::Util qw(make_method);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base qw(Log::Any::Adapter::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Mojo::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶sub init {
Subroutine init: called CC=2 SCAR=8.1
Pod undocumented
15 2 my ($self) = @_;
16 2 ▶ $self->{logger} ||= Mojo::Log->new;
Condition33%1/3
$self->{"logger"} ||= "Mojo::Log"->new
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{"logger"} ||= "Mojo::Log"->new
$self->{"logger"} "Mojo::Log"->new
Truth table33%1/3
A ||= B
A= $self->{"logger"}B= "Mojo::Log"->new
ABresult
1X1
011
000
17 }
18  
19 # Create logging methods
20 #
21 1 foreach my $method ( Log::Any->logging_methods ) {
22 9 my $mojo_method = $method;
23  
24 # Map log levels down to Mojo::Log levels where necessary
25 #
26 9 for ($mojo_method) {
27 9 s/trace/debug/;
28 9 s/notice/info/;
29 9 s/warning/warn/;
30 9 s/critical|alert|emergency/fatal/;
31 }
32  
33 make_method(
34 $method,
35 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=4.1
36 0 my $self = shift;
37 0 my ( $pkg, $line ) = ( caller() )[ 0, 2 ];
38  
39 # Quick and dirty hack to get correct package and line number
40 # into log line.
41 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 my $old_syswrite = *{*IO::Handle::syswrite}{CODE};
44 0 ▶ local *IO::Handle::syswrite = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 my $self = shift;
46 0 my $l = shift;
47  
48 0 $l =~ s/Log::Any::Adapter::Mojo:\d+/\Q$pkg\E:\Q$line\E/;
49 0 $l =~ s/Mojo::EventEmitter:\d+/\Q$pkg\E:\Q$line\E/;
50 0 $l =~ s/Mojo::Log:\d+/\Q$pkg\E:\Q$line\E/;
51  
52 0 return $self->$old_syswrite( $l, @_ );
53 0 };
54  
55 0 return $self->{logger}->$mojo_method(@_);
56 }
57 9 );
58 }
59  
60 # Create detection methods: is_debug, is_info, etc.
61 #
62 1 foreach my $method ( Log::Any->detection_methods ) {
63 9 my $mojo_method = $method;
64  
65 # Map log levels down to Mojo::Log levels where necessary
66 #
67 9 for ($mojo_method) {
68 9 s/trace/debug/;
69 9 s/notice/info/;
70 9 s/warning/warn/;
71 9 s/critical|alert|emergency/fatal/;
72 }
73  
74 make_method(
75 $method,
76 1 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 1 my $self = shift;
78 1 return $self->{logger}->$mojo_method(@_);
79 }
80 9 );
81 }
82  
83 1 1;
84  
85 __END__
↑ Summary