line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::ger::Output::ArrayRotate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-03-11'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Log-ger-Output-ArrayRotate'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3329
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
157
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub meta { +{ |
12
|
1
|
|
|
1
|
0
|
15
|
v => 2, |
13
|
|
|
|
|
|
|
} } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_hooks { |
16
|
1
|
|
|
1
|
0
|
14
|
my %plugin_conf = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
4
|
my $ary = $plugin_conf{array} or die "Please specify array"; |
19
|
1
|
50
|
|
|
|
3
|
ref $ary eq 'ARRAY' or die "Please specify arrayref in array"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return { |
22
|
|
|
|
|
|
|
create_outputter => [ |
23
|
|
|
|
|
|
|
__PACKAGE__, # key |
24
|
|
|
|
|
|
|
50, # priority |
25
|
|
|
|
|
|
|
sub { # hook |
26
|
6
|
|
|
6
|
|
1657
|
my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook" |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $outputter = sub { |
29
|
4
|
|
|
|
|
1071
|
my ($ctx, $msg) = @_; |
30
|
4
|
|
|
|
|
7
|
push @$ary, $msg; |
31
|
4
|
100
|
66
|
|
|
17
|
if (defined $plugin_conf{max_elems} && @$ary > $plugin_conf{max_elems}) { |
32
|
1
|
|
|
|
|
3
|
shift @$ary; |
33
|
|
|
|
|
|
|
} |
34
|
6
|
|
|
|
|
18
|
}; |
35
|
6
|
|
|
|
|
14
|
[$outputter]; |
36
|
1
|
|
|
|
|
7
|
}], |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
# ABSTRACT: Log to array, rotating old elements |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |