File Coverage

blib/lib/Log/ger/Format/Hashref.pm
Criterion Covered Total %
statement 18 18 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 29 31 93.5


line stmt bran cond sub pod time code
1             package Log::ger::Format::Hashref;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-03-09'; # DATE
5             our $DIST = 'Log-ger-Format-Hashref'; # DIST
6             our $VERSION = '0.002'; # VERSION
7              
8 1     1   70826 use strict;
  1         10  
  1         24  
9 1     1   5 use warnings;
  1         1  
  1         165  
10              
11             sub meta { +{
12 1     1 0 13 v => 1,
13             } }
14              
15             sub get_hooks {
16 1     1 0 10 my %plugin_conf = @_;
17              
18             return {
19             create_formatter => [
20             __PACKAGE__, # key
21             50, # priority
22             sub { # hook
23 2     2   2083 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
24              
25             my $formatter = sub {
26 5 100       587 if (@_ == 1) {
    100          
27 2 100       6 if (ref $_[0] eq 'HASH') {
28 1         3 return $_[0];
29             } else {
30 1         6 return {message=>$_[0]};
31             }
32             } elsif (@_ % 2) {
33 1         9 die "Please log an even number of arguments";
34             } else {
35 2         7 return {@_};
36             }
37 2         7 };
38 2         5 [$formatter];
39              
40 1         8 }],
41             };
42             }
43              
44             1;
45             # ABSTRACT: Format arguments as hashref
46              
47             __END__