blib/lib/Catmandu/Fix/log.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 85.7% 36 / 42 CC 4 SCAR 8.8
CC
4
Cov
91%
fix
4.2
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« blib/lib/Catmandu/Store/Hash.pm ↑ Summary blib/lib/Catmandu/Fix/include.pm »
1 package Catmandu::Fix::log;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.0201_02';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'Catmandu::Fix::Inlineable', 'Catmandu::Logger';
13  
14 1 has message => (fix_arg => 1);
15 1 has level => (fix_opt => 1);
16  
17 sub fix {
18 1 ▶ my ($self, $data) = @_;
Subroutine fix: called CC=4 SCAR=14.3
Pod undocumented
19 1 ▶ my $id = $data->{_id} // '<undef>';
Condition50%1/2
$data->{"_id"} // "<undef>"
l!l
01
MC/DC0%0/1
$data->{"_id"} // "<undef>"
$data->{"_id"}
Truth table50%1/2
A
A= $data->{"_id"}
Aresult
11
00
20 1 ▶ my $level = $self->level // 'INFO';
Condition50%1/2
$self->level // "INFO"
l!l
01
MC/DC0%0/1
$self->level // "INFO"
$self->level
Truth table50%1/2
A
A= $self->level
Aresult
11
00
21  
22 1 ▶ if ($level
Branch: 1 branch
BranchTrueFalseTotal
if ($level =~ /^(trace|debug|info|notice|warn|error|critical|alert|emergency)$/i) 1 0 1
23 =~ /^(trace|debug|info|notice|warn|error|critical|alert|emergency)$/i)
24 {
25 1 my $lvl = lc $level;
26 1 $self->log->$lvl(sprintf "%s : %s\n", $id, $self->message);
27 }
28  
29 1 $data;
30 }
31  
32 1 1;
33  
34 __END__
35  
36 =pod
37  
38 =head1 NAME
39  
40 Catmandu::Fix::log - Log::Any logger as fix
41  
42 =head1 SYNOPSIS
43  
44 log('test123')
45  
46 log('hello world' , level:DEBUG);
47  
48 =head1 DESCRIPTION
49  
50 This fix add debugging capabilities to fixes. To use it via the command line you need to add the
51 '-D' option to your script. E.g.
52  
53 echo '{}' | catmandu convert -D to YAML --fix 'log("help!", level:WARN)'
54  
55 =head1 SEE ALSO
56  
57 L<Catmandu::Fix>
58  
59 =cut
« blib/lib/Catmandu/Store/Hash.pm ↑ Summary blib/lib/Catmandu/Fix/include.pm »