File Coverage

blib/lib/Log/ger/Format/Block.pm
Criterion Covered Total %
statement 31 31 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 1 0.0
total 44 48 91.6


line stmt bran cond sub pod time code
1             package Log::ger::Format::Block;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-03-07'; # DATE
5             our $DIST = 'Log-ger-Format-Block'; # DIST
6             our $VERSION = '0.006'; # VERSION
7              
8 1     1   110289 use strict;
  1         10  
  1         24  
9 1     1   5 use warnings;
  1         1  
  1         24  
10              
11 1     1   384 use Sub::Metadata qw(mutate_sub_prototype);
  1         439  
  1         144  
12              
13             sub get_hooks {
14 2     2 0 1382 my %plugin_conf = @_;
15              
16             return {
17             create_formatter => [
18             __PACKAGE__, # key
19             50, # priority
20             sub { # hook
21 3     3   504 my %hook_args = @_;
22              
23 3         10 my $formatter = sub { my $code = shift; $code->(@_) };
  2         1229  
  2         5  
24 3         8 [$formatter];
25             }],
26              
27             before_install_routines => [
28             __PACKAGE__, # key
29             50, # priority
30             sub { # hook
31 1     1   7 no strict 'refs';
  1         2  
  1         200  
32              
33 3     3   2517 my %hook_args = @_;
34              
35 3         6 for my $r (@{ $hook_args{routines} }) {
  3         6  
36 36         55 my ($coderef, $name, $lnum, $type) = @$r;
37 36 100       84 next unless $type =~ /\Alog(ger)?_/;
38             # avoid prototype mismatch warning when redefining
39 18 50 33     40 if ($hook_args{target_type} eq 'package' ||
40             $hook_args{target_type} eq 'object') {
41 18 100       19 if (defined ${"$hook_args{target_name}\::"}{$name}) {
  18         39  
42 12         15 delete ${"$hook_args{target_name}\::"}{$name};
  12         57  
43             }
44             }
45 18         35 mutate_sub_prototype($coderef, '&');
46             }
47 3         10 [1];
48 2         20 }],
49             };
50             }
51              
52             1;
53             # ABSTRACT: Use formatting using block instead of sprintf-style
54              
55             __END__