line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###########################################################################
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# File_Pool.pm
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
# Copyright (C) 1999 Raphael Manfredi.
|
6
|
|
|
|
|
|
|
# Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
|
7
|
|
|
|
|
|
|
# all rights reserved.
|
8
|
|
|
|
|
|
|
#
|
9
|
|
|
|
|
|
|
# See the README file included with the
|
10
|
|
|
|
|
|
|
# distribution for license information.
|
11
|
|
|
|
|
|
|
#
|
12
|
|
|
|
|
|
|
##########################################################################
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
55
|
use strict;
|
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
2873
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
########################################################################
|
17
|
|
|
|
|
|
|
package Log::Agent::File_Pool;
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
# A pool of all created file objects, along with their rotation policies
|
21
|
|
|
|
|
|
|
#
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $POOL = undef; # only one instance
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#
|
26
|
|
|
|
|
|
|
# ->make
|
27
|
|
|
|
|
|
|
#
|
28
|
|
|
|
|
|
|
# Creation routine.
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
# Attributes:
|
31
|
|
|
|
|
|
|
# info records path ->
|
32
|
|
|
|
|
|
|
# [Log::Agent::File objects, rotation policies, refcnt]
|
33
|
|
|
|
|
|
|
#
|
34
|
|
|
|
|
|
|
sub make {
|
35
|
8
|
|
|
8
|
0
|
27
|
my $self = bless {}, shift;
|
36
|
8
|
|
|
|
|
60
|
$self->{info} = {};
|
37
|
8
|
|
|
|
|
46
|
return $self;
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#
|
41
|
|
|
|
|
|
|
# Attribute access
|
42
|
|
|
|
|
|
|
#
|
43
|
|
|
|
|
|
|
|
44
|
98
|
|
|
98
|
0
|
179
|
sub info { $_[0]->{'info'} }
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#
|
47
|
|
|
|
|
|
|
# file_pool -- "once" routine
|
48
|
|
|
|
|
|
|
#
|
49
|
|
|
|
|
|
|
# Return the main pool
|
50
|
|
|
|
|
|
|
#
|
51
|
|
|
|
|
|
|
sub file_pool {
|
52
|
50
|
|
66
|
50
|
0
|
161
|
return $POOL || ($POOL = Log::Agent::File_Pool->make());
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#
|
56
|
|
|
|
|
|
|
# ->put
|
57
|
|
|
|
|
|
|
#
|
58
|
|
|
|
|
|
|
# Put new entry in pool.
|
59
|
|
|
|
|
|
|
#
|
60
|
|
|
|
|
|
|
sub put {
|
61
|
31
|
|
|
31
|
0
|
58
|
my $self = shift;
|
62
|
31
|
|
|
|
|
65
|
my ($path, $file, $rotate) = @_;
|
63
|
|
|
|
|
|
|
|
64
|
31
|
|
|
|
|
127
|
my $info = $self->info;
|
65
|
31
|
100
|
|
|
|
93
|
if (exists $info->{$path}) {
|
66
|
1
|
|
|
|
|
4
|
$info->{$path}->[2]++; # refcnt
|
67
|
|
|
|
|
|
|
} else {
|
68
|
30
|
|
|
|
|
137
|
$info->{$path} = [$file, $rotate, 1];
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#
|
73
|
|
|
|
|
|
|
# ->get
|
74
|
|
|
|
|
|
|
#
|
75
|
|
|
|
|
|
|
# Get record for existing entry, undef if none.
|
76
|
|
|
|
|
|
|
#
|
77
|
|
|
|
|
|
|
sub get {
|
78
|
31
|
|
|
31
|
0
|
54
|
my $self = shift;
|
79
|
31
|
|
|
|
|
60
|
my ($path) = @_;
|
80
|
31
|
|
|
|
|
65
|
my $aref = $self->info->{$path};
|
81
|
31
|
100
|
|
|
|
109
|
return defined $aref ? @$aref : ();
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#
|
85
|
|
|
|
|
|
|
# ->remove
|
86
|
|
|
|
|
|
|
#
|
87
|
|
|
|
|
|
|
# Remove record.
|
88
|
|
|
|
|
|
|
# Returns true when file is definitively removed (no more reference on it).
|
89
|
|
|
|
|
|
|
#
|
90
|
|
|
|
|
|
|
sub remove {
|
91
|
19
|
|
|
19
|
0
|
28
|
my $self = shift;
|
92
|
19
|
|
|
|
|
35
|
my ($path) = @_;
|
93
|
19
|
|
|
|
|
37
|
my $item = $self->info->{$path};
|
94
|
19
|
100
|
|
|
|
44
|
return 1 unless defined $item;
|
95
|
17
|
50
|
|
|
|
35
|
return 0 if --$item->[2];
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#
|
98
|
|
|
|
|
|
|
# Reference count reached 0
|
99
|
|
|
|
|
|
|
#
|
100
|
|
|
|
|
|
|
|
101
|
17
|
|
|
|
|
31
|
delete $self->info->{$path};
|
102
|
17
|
|
|
|
|
78
|
return 1;
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; # for require
|