File Coverage

blib/lib/Log/ger/Format/Hashref.pm
Criterion Covered Total %
statement 17 17 100.0
branch 6 6 100.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 27 28 96.4


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-02-18'; # DATE
5             our $DIST = 'Log-ger-Format-Hashref'; # DIST
6             our $VERSION = '0.001'; # VERSION
7              
8 1     1   83992 use strict;
  1         11  
  1         30  
9 1     1   5 use warnings;
  1         2  
  1         176  
10              
11             sub get_hooks {
12 1     1 0 13 my %conf = @_;
13              
14             return {
15             create_formatter => [
16             __PACKAGE__, # key
17             50, # priority
18             sub { # hook
19 2     2   2498 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
20              
21             my $formatter = sub {
22 5 100       665 if (@_ == 1) {
    100          
23 2 100       6 if (ref $_[0] eq 'HASH') {
24 1         4 return $_[0];
25             } else {
26 1         8 return {message=>$_[0]};
27             }
28             } elsif (@_ % 2) {
29 1         12 die "Please log an even number of arguments";
30             } else {
31 2         9 return {@_};
32             }
33 2         8 };
34 2         7 [$formatter];
35              
36 1         8 }],
37             };
38             }
39              
40             1;
41             # ABSTRACT: Format arguments as hashref
42              
43             __END__