| 1 | package Log::Any::Adapter::Dispatch; | ||||||||||||||||||||
| 2 | # ABSTRACT: Adapter to use Log::Dispatch with Log::Any | ||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | use Log::Any::Adapter::Util qw(make_method); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Log::Dispatch; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use base qw(Log::Any::Adapter::Base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||
| 12 | 2 | my $self = shift; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | # If a dispatcher was not explicitly passed in, create a new one with the passed arguments. | ||||||||||||||||||||
| 15 | # | ||||||||||||||||||||
| 16 | 2 | ▶ | $_[-2] eq "category" and splice @_, -2, 2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 2 | ▶ | $self->{dispatcher} ||= Log::Dispatch->new(@_); | ||||||||||||||||||
|
Condition66%2/3
$self->{"dispatcher"} ||= "Log::Dispatch"->new(@_)
MC/DC0%0/2
$self->{"dispatcher"} ||= "Log::Dispatch"->new(@_)
$self->{"dispatcher"}
"Log::Dispatch"->new(@_)
Truth table66%2/3
A ||= B
A= $self->{"dispatcher"}B= "Log::Dispatch"->new(@_)
| |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # Delegate logging methods to same methods in dispatcher | ||||||||||||||||||||
| 21 | # | ||||||||||||||||||||
| 22 | 2 | foreach my $method ( Log::Any->logging_methods() ) { | |||||||||||||||||||
| 23 | 18 | my $log_dispatch_method = $method; | |||||||||||||||||||
| 24 | 18 | $log_dispatch_method =~ s/trace/debug/; | |||||||||||||||||||
| 25 | 18 | __PACKAGE__->delegate_method_to_slot( 'dispatcher', $method, | |||||||||||||||||||
| 26 | $log_dispatch_method ); | ||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # Delegate detection methods to would_log | ||||||||||||||||||||
| 30 | # | ||||||||||||||||||||
| 31 | 2 | foreach my $method ( Log::Any->detection_methods() ) { | |||||||||||||||||||
| 32 | 18 | my $level = substr( $method, 3 ); | |||||||||||||||||||
| 33 | 18 | $level =~ s/trace/debug/; | |||||||||||||||||||
| 34 | make_method( $method, | ||||||||||||||||||||
| 35 | 56 | ▶ | sub { my ($self) = @_; return $self->{dispatcher}->would_log($level) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 18 | ); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 2 | 1; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | __END__ | ||||||||||||||||||||