| 1 | package Log::ger::Plugin::OptAway; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||
| 4 | 2 | our $DATE = '2020-03-11'; # DATE | |||||||||||||||||||
| 5 | 2 | our $DIST = 'Log-ger-Plugin-OptAway'; # DIST | |||||||||||||||||||
| 6 | 2 | our $VERSION = '0.009'; # VERSION | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | sub meta { +{ | ||||||||||||||||||
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 12 | 1 | v => 2, | |||||||||||||||||||
| 13 | } } | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | ▶ | sub get_hooks { | ||||||||||||||||||
|
Subroutine
get_hooks: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 16 | 1 | my %plugin_conf = @_; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | return { | ||||||||||||||||||||
| 19 | after_install_routines => [ | ||||||||||||||||||||
| 20 | __PACKAGE__, # key | ||||||||||||||||||||
| 21 | 99, # priority (after all the other plugins) | ||||||||||||||||||||
| 22 | 3 | ▶ | sub { # hook | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.1
| |||||||||||||||||||||
| 23 | 3 | require B::CallChecker; | |||||||||||||||||||
| 24 | 3 | require B::Generate; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 3 | my %hook_args = @_; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | # we are only relevant when targetting package | ||||||||||||||||||||
| 29 | 3 | ▶ | return [undef] unless ($hook_args{target_type}||'') eq 'package'; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$hook_args{'target_type'} || ''
MC/DC0%0/1
$hook_args{'target_type'} || ''
$hook_args{'target_type'}
Truth table50%1/2
A
A= $hook_args{'target_type'}
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | #use DD; dd \%hook_args; | ||||||||||||||||||||
| 32 | 3 | for my $r (@{ $hook_args{routines} }) { | |||||||||||||||||||
| 33 | 36 | my ($code, $name, $lnum, $type) = @$r; | |||||||||||||||||||
| 34 | #print "D:got routine name=$name, lnum=",(defined $lnum ? $lnum : '-'), ", type=$type\n"; | ||||||||||||||||||||
| 35 | 36 | ▶ | next unless $type =~ /\A(logger_|log_|level_checker_|is_)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 36 | my $fullname = "$hook_args{target_name}\::$name"; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | ▶ | no warnings 'once'; # $Log::ger::Current_Level | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 36 | my $should_opt_away; | |||||||||||||||||||
| 40 | 36 | ▶ | if ($plugin_conf{all}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 41 | 0 | $should_opt_away = 1; | |||||||||||||||||||
| 42 | } elsif ($Log::ger::Current_Level < $r->[2]) { | ||||||||||||||||||||
| 43 | 14 | $should_opt_away = 1; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 36 | ▶ | if ($should_opt_away) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | #print "D:no-oping $fullname\n"; | ||||||||||||||||||||
| 48 | B::CallChecker::cv_set_call_checker( | ||||||||||||||||||||
| 49 | 14 | \&{$fullname}, | |||||||||||||||||||
| 50 | 6 | ▶ | sub { B::SVOP->new("const",0,!1) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 14 | \!1, | |||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 3 | [1]; | |||||||||||||||||||
| 56 | 1 | }], | |||||||||||||||||||
| 57 | }; | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 2 | 1; | |||||||||||||||||||
| 61 | # ABSTRACT: Optimize away log statements | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||