| 1 | package Sys::Export::LogAny; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 19 | our $VERSION = '0.006'; # VERSION | |||||||||||||
| 4 | # ABSTRACT: Use Log::Any without depending on it | ||||||||||||||
| 5 | |||||||||||||||
| 6 | |||||||||||||||
| 7 | 19 | ▶ | use v5.26; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 19 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 19 | ▶ | if (eval 'use Log::Any 1.051; 1') { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||
| 11 | 19 | our @ISA= ( 'Log::Any' ); | |||||||||||||
| 12 | 19 | ▶ | my $lev= !$ENV{DEBUG}? 'info' : $ENV{DEBUG} > 1? 'trace' : 'debug'; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 13 | 19 | Log::Any->import(default_adapter => [ 'Stderr', log_level => $lev ]); | |||||||||||||
| 14 | } else { | ||||||||||||||
| 15 | 0 | ▶ | *get_logger= sub { bless {}, 'Sys::Export::LogAny::_Logger'; }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 16 | 0 | ▶ | *import= sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=19.6
| |||||||||||||||
| 17 | 0 | my $class= shift; | |||||||||||||
| 18 | 0 | for (@_) { | |||||||||||||
| 19 | 0 | ▶ | if ($_ eq '$log') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 0 | my $caller= caller; | |||||||||||||
| 21 | 0 | my $logger= $class->get_logger($caller); | |||||||||||||
| 22 | 19 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 0 | *{$caller . '::log'}= \$logger; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | 0 | else { die "Can't export '$_'"; } | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | 0 | }; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 19 | package Sys::Export::LogAny::_Logger { | |||||||||||||
| 31 | 19 | ▶ | use v5.26; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | 19 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 33 | 19 | ▶ | use experimental qw( signatures ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 34 | 0 | ▶ | sub _dump { | ||||||||||||
|
Subroutine
_dump: not called CC=1 SCAR=6.9
| |||||||||||||||
| 35 | 0 | state $dumper_loaded= require Data::Dumper; | |||||||||||||
| 36 | 0 | chomp(my $s= Data::Dumper->new([$_[0]])->Terse(1)->Sortkeys(1)->Dump); | |||||||||||||
| 37 | 0 | $s; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | 0 | ▶ | sub is_info { 1 } | ||||||||||||
|
Subroutine
is_info: not called CC=1 SCAR=6.9
| |||||||||||||||
| 40 | 0 | ▶ | sub info($self, @msg) { | ||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
| |||||||||||||||
| 41 | 0 | print STDERR join(' ', @msg)."\n" | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | 0 | ▶ | sub infof($self, $fmt, @args) { | ||||||||||||
|
Subroutine
infof: not called CC=3 SCAR=24.8
| |||||||||||||||
| 44 | 0 | ▶ | printf STDERR $fmt."\n", map +(ref? _dump($_) : defined? $_ : '(undef)'), @args; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 45 | } | ||||||||||||||
| 46 | 19 | *error = *warn = *notice = *info; | |||||||||||||
| 47 | 19 | *errorf= *warnf = *noticef= *infof; | |||||||||||||
| 48 | 19 | *is_error= *is_warn= *is_notice= *is_info; | |||||||||||||
| 49 | 0 | ▶ | sub is_debug { ($ENV{DEBUG} // 0) >= 1 } | ||||||||||||
|
Subroutine
is_debug: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{"DEBUG"} // 0
MC/DC0%0/1
$ENV{"DEBUG"} // 0
$ENV{"DEBUG"}
Truth table0%0/2
A
A= $ENV{"DEBUG"}
| |||||||||||||||
| 50 | 0 | ▶ | sub is_trace { ($ENV{DEBUG} // 0) >= 2 } | ||||||||||||
|
Subroutine
is_trace: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{"DEBUG"} // 0
MC/DC0%0/1
$ENV{"DEBUG"} // 0
$ENV{"DEBUG"}
Truth table0%0/2
A
A= $ENV{"DEBUG"}
| |||||||||||||||
| 51 | 0 | ▶ | sub debug { is_debug? info (@_) : () } | ||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 52 | 0 | ▶ | sub debugf { is_debug? infof(@_) : () } | ||||||||||||
|
Subroutine
debugf: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | ▶ | sub trace { is_trace? info (@_) : () } | ||||||||||||
|
Subroutine
trace: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 54 | 0 | ▶ | sub tracef { is_trace? infof(@_) : () } | ||||||||||||
|
Subroutine
tracef: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 19 | 1; | |||||||||||||
| 58 | |||||||||||||||
| 59 | __END__ | ||||||||||||||