line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::Code; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3302
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
114
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.71'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
16
|
use Log::Dispatch::Types; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
33
|
|
9
|
2
|
|
|
2
|
|
60690
|
use Params::ValidationCompiler qw( validation_for ); |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
156
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
19
|
use base qw( Log::Dispatch::Output ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
950
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
my $validator = validation_for( |
15
|
|
|
|
|
|
|
params => { code => { type => t('CodeRef') } }, |
16
|
|
|
|
|
|
|
slurpy => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
1
|
|
|
1
|
0
|
5
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
21
|
my %p = $validator->(@_); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
20
|
my $self = bless { code => delete $p{code} }, $class; |
25
|
1
|
|
|
|
|
9
|
$self->_basic_init(%p); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
4
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub log_message { |
32
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
33
|
2
|
|
|
|
|
5
|
my %p = @_; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
5
|
delete $p{name}; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
6
|
$self->{code}->(%p); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ABSTRACT: Object for logging to a subroutine reference |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=pod |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=encoding UTF-8 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Log::Dispatch::Code - Object for logging to a subroutine reference |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 VERSION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
version 2.71 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Log::Dispatch; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $log = Log::Dispatch->new( |
63
|
|
|
|
|
|
|
outputs => [ |
64
|
|
|
|
|
|
|
[ |
65
|
|
|
|
|
|
|
'Code', |
66
|
|
|
|
|
|
|
min_level => 'emerg', |
67
|
|
|
|
|
|
|
code => \&_log_it, |
68
|
|
|
|
|
|
|
], |
69
|
|
|
|
|
|
|
] |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _log_it { |
73
|
|
|
|
|
|
|
my %p = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
warn $p{message}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This module supplies a simple object for logging to a subroutine reference. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=for Pod::Coverage new log_message |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The constructor takes the following parameters in addition to the standard |
87
|
|
|
|
|
|
|
parameters documented in L<Log::Dispatch::Output>: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * code ($) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
The subroutine reference. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 HOW IT WORKS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The subroutine you provide will be called with a hash of named arguments. The |
100
|
|
|
|
|
|
|
two arguments are: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * level |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The log level of the message. This will be a string like "info" or "error". |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * message |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The message being logged. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SUPPORT |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Log-Dispatch/issues>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SOURCE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The source code repository for Log-Dispatch can be found at L<https://github.com/houseabsolute/Log-Dispatch>. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Dave Rolsky. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software, licensed under: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The full text of the license can be found in the |
135
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |