Agent/File_Pool.pm

filter: Statementstmt 100% 27 / 27 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 6 totaltotal 81.1% 43 / 53 CC 6 SCAR 7.0
CC
6
Cov
95%
remove
3.0
file_pool
2.1
put
2.0
CRAP 2.0
« Agent/Tag_List.pm ↑ Summary Agent/Tag/String.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 8 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 8 ▶sub make {
Subroutine make: called CC=1 SCAR=0.0
Pod undocumented
35 8 my $self = bless {}, shift;
36 8 $self->{info} = {};
37 8 return $self;
38 }
39  
40 #
41 # Attribute access
42 #
43  
44 98 ▶sub info { $_[0]->{'info'} }
Subroutine info: called CC=1 SCAR=0.0
Pod undocumented
45  
46 #
47 # file_pool -- "once" routine
48 #
49 # Return the main pool
50 #
51 50 ▶sub file_pool {
Subroutine file_pool: called CC=2 SCAR=7.2
Pod undocumented
52 50 ▶ return $POOL || ($POOL = Log::Agent::File_Pool->make());
Condition66%2/3
$POOL || ($POOL = 'Log::Agent::File_Pool'->make)
l!l&&r!l&&!r
4280
MC/DC0%0/2
$POOL || ($POOL = 'Log::Agent::File_Pool'->make)
$POOL ($POOL = 'Log::Agent::File_Pool'->make)
Truth table66%2/3
A || B
A= $POOLB= ($POOL = 'Log::Agent::File_Pool'->make)
ABresult
1X1
011
000
53 }
54  
55 #
56 # ->put
57 #
58 # Put new entry in pool.
59 #
60 31 ▶sub put {
Subroutine put: called CC=2 SCAR=6.9
Pod undocumented
61 31 my $self = shift;
62 31 my ($path, $file, $rotate) = @_;
63  
64 31 my $info = $self->info;
65 31 ▶ if (exists $info->{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{$path}) { } 1 30 31
66 1 $info->{$path}->[2]++; # refcnt
67 } else {
68 30 $info->{$path} = [$file, $rotate, 1];
69 }
70 }
71  
72 #
73 # ->get
74 #
75 # Get record for existing entry, undef if none.
76 #
77 31 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
78 31 my $self = shift;
79 31 my ($path) = @_;
80 31 my $aref = $self->info->{$path};
81 31 ▶ return defined $aref ? @$aref : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $aref ? : 1 30 31
82 }
83  
84 #
85 # ->remove
86 #
87 # Remove record.
88 # Returns true when file is definitively removed (no more reference on it).
89 #
90 19 ▶sub remove {
Subroutine remove: called CC=3 SCAR=11.0
Pod undocumented
91 19 my $self = shift;
92 19 my ($path) = @_;
93 19 my $item = $self->info->{$path};
94 19 ▶ return 1 unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 2 17 19
95 17 ▶ return 0 if --$item->[2];
Branch: 1 branch
BranchTrueFalseTotal
if --$item->[2] 0 17 17
96  
97 #
98 # Reference count reached 0
99 #
100  
101 17 delete $self->info->{$path};
102 17 return 1;
103 }
104  
105 8 1; # for require
« Agent/Tag_List.pm ↑ Summary Agent/Tag/String.pm »