File Coverage

File:blib/lib/Log/Abstraction/Backend/Code.pm
Coverage:100.0%

linestmtbrancondsubtimecode
1package Log::Abstraction::Backend::Code;
2
3# The code-reference backend: call it with a hash of the message
4
37
37
37
116
23
151
use strict;
5
37
37
37
28
37
323
use warnings;
6
7
37
37
37
48
26
52
use parent 'Log::Abstraction::Backend';
8
9our $VERSION = '0.40';
10
11 - 34
=head1 NAME

Log::Abstraction::Backend::Code - call a code reference with each message

=head1 VERSION

0.40

=head1 DESCRIPTION

Built for C<logger =E<gt> \&code>.  The code is called with
C<{ class, file, line, level, message, ctx, fields }>, where C<message> is an
array reference of the message's parts, and C<ctx> and C<fields> are only
present when set.

For use by L<Log::Abstraction> only; see L<Log::Abstraction::Backend>.

=head1 METHODS

=head2 emit

  $backend->emit($logger, $event);

=cut
35
36sub emit {
37
35
35
        my ($self, $logger, $event) = @_;
38
39        my $args = {
40                class   => $event->{'class'},
41                file    => $event->{'file'},
42                line    => $event->{'line'},
43                level   => $event->{'level'},
44
35
76
                message => $event->{'parts'},
45        };
46
35
36
        $args->{'ctx'} = $event->{'ctx'} if($event->{'ctx'});
47
35
39
        $args->{'fields'} = $event->{'fields'} if($event->{'fields'});
48
35
46
        $self->{'code'}->($args);
49}
50
51 - 67
=head1 AUTHOR

Nigel Horne C<njh@nigelhorne.com>

=head1 SEE ALSO

L<Log::Abstraction>, L<Log::Abstraction::Backend>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2025-2026 Nigel Horne

Usage is subject to the GPL2 licence terms.
If you use it,
please let me know.

=cut
68
691;