| 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>"
MC/DC0%0/1
$data->{"_id"} // "<undef>"
$data->{"_id"}
Truth table50%1/2
A
A= $data->{"_id"}
| |||||||||||||
| 20 | 1 | ▶ | my $level = $self->level // 'INFO'; | ||||||||||
|
Condition50%1/2
$self->level // "INFO"
MC/DC0%0/1
$self->level // "INFO"
$self->level
Truth table50%1/2
A
A= $self->level
| |||||||||||||
| 21 | |||||||||||||
| 22 | 1 | ▶ | if ($level | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ||||||||||||