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-2015 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
|
|
40
|
use strict; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
2624
|
|
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
|
21
|
my $self = bless {}, shift; |
36
|
8
|
|
|
|
|
54
|
$self->{info} = {}; |
37
|
8
|
|
|
|
|
48
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# Attribute access |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
|
44
|
98
|
|
|
98
|
0
|
188
|
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
|
198
|
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
|
43
|
my $self = shift; |
62
|
31
|
|
|
|
|
52
|
my ($path, $file, $rotate) = @_; |
63
|
|
|
|
|
|
|
|
64
|
31
|
|
|
|
|
66
|
my $info = $self->info; |
65
|
31
|
100
|
|
|
|
150
|
if (exists $info->{$path}) { |
66
|
1
|
|
|
|
|
4
|
$info->{$path}->[2]++; # refcnt |
67
|
|
|
|
|
|
|
} else { |
68
|
30
|
|
|
|
|
143
|
$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
|
41
|
my $self = shift; |
79
|
31
|
|
|
|
|
47
|
my ($path) = @_; |
80
|
31
|
|
|
|
|
68
|
my $aref = $self->info->{$path}; |
81
|
31
|
100
|
|
|
|
116
|
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
|
26
|
my $self = shift; |
92
|
19
|
|
|
|
|
24
|
my ($path) = @_; |
93
|
19
|
|
|
|
|
36
|
my $item = $self->info->{$path}; |
94
|
19
|
100
|
|
|
|
50
|
return 1 unless defined $item; |
95
|
17
|
50
|
|
|
|
44
|
return 0 if --$item->[2]; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
# Reference count reached 0 |
99
|
|
|
|
|
|
|
# |
100
|
|
|
|
|
|
|
|
101
|
17
|
|
|
|
|
32
|
delete $self->info->{$path}; |
102
|
17
|
|
|
|
|
94
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; # for require |