Config.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 72 CC 6 SCAR 28.3
CC
6
Cov
0%
clamd_config
42.0
clamd_option
2.0
BEGIN
2.0
CRAP 17.0
1 #
2 # ClamAV::Config class
3 #
4 # (C) 2004-2005 Julian Mehnle <julian@mehnle.net>
5 # $Id: Config.pm,v 1.3 2005/01/21 22:50:14 julian Exp $
6 #
7 ##############################################################################
8  
9 =head1 NAME
10  
11 ClamAV::Config - A Perl class providing configuration information for Perl
12 modules related to ClamAV
13  
14 =cut
15  
16 package ClamAV::Config;
17  
18 =head1 VERSION
19  
20 0.11
21  
22 =cut
23  
24 our $VERSION = 0.11;
25  
26 =head1 SYNOPSIS
27  
28 use ClamAV::Config;
29
30 # ClamAV base configuration:
31 ClamAV::Config->config_dir;
32 ClamAV::Config->clamd_config_file;
33
34 # clamd run-time configuration:
35 ClamAV::Config->clamd_config;
36 ClamAV::Config->clamd_option($option);
37  
38 =cut
39  
40 use warnings;
41 use strict;
42  
43 use Error qw(:try);
44  
45 use IO::File;
46  
47 # Private declarations:
48 ##############################################################################
49  
50 use constant TRUE => (0 == 0);
51 use constant FALSE => not TRUE;
52  
53 my $clamd_config;
54  
55 # Interface:
56 ##############################################################################
57  
58 =head1 DESCRIPTION
59  
60 This class provides configuration information for Perl modules related to the
61 ClamAV virus scanner, e.g. installation specific file system paths and run-time
62 configuration options.
63  
64 =cut
65  
66 sub clamd_option;
67  
68 # Implementation:
69 ##############################################################################
70  
71 =head2 ClamAV base configuration
72  
73 The following ClamAV base configuration information is provided as class
74 methods:
75  
76 =over
77  
78 =item B<config_dir>
79  
80 The base configuration directory of ClamAV.
81  
82 =cut
83  
84 use constant config_dir => '/etc/clamav';
85  
86 =item B<clamd_config_file>
87  
88 The absolute file name of the I<clamd> configuration file.
89  
90 =cut
91  
92 use constant clamd_config_file => config_dir . '/clamd.conf';
93  
94 =back
95  
96 =head2 clamd run-time configuration
97  
98 The following clamd run-time configuration information is provided as class
99 methods:
100  
101 =over
102  
103 =item B<clamd_config>
104  
105 Returns all clamd run-time configuration options as a hash reference.
106  
107 =cut
108  
109 sub clamd_config {
110 my ($self) = @_;
111
112 return $clamd_config
113 if $clamd_config;
114
115 my $file = IO::File->new($self->clamd_config_file);
116 if (not $file) {
117 $clamd_config = {};
118 throw ClamAV::Config::Error(
119 'Could not open clamd config file "' . $self->clamd_config_file . '" for reading'
120 );
121 }
122
123 while (my $line = $file->getline) {
124 chomp($line);
125 next if $line =~ /^\s*#/;
126 if (not $line =~ /^\s*(\w+)(?:\s+(\S+))?\s*$/) {
127 $clamd_config = {};
128 throw ClamAV::Config::Error('Malformed line in clamd configuration file encountered');
129 }
130 $clamd_config->{$1} = (defined($2) ? $2 : TRUE);
131 }
132
133 return $clamd_config;
134 }
135  
136 =item B<clamd_option($option)>
137  
138 Returns the value of the specified clamd run-time configuration option.
139  
140 =cut
141  
142 sub clamd_option {
143 my ($self, $option) = @_;
144 return $self->clamd_config->{$option};
145 }
146  
147 =back
148  
149 =head1 SEE ALSO
150  
151 For AVAILABILITY, SUPPORT, and LICENSE information, see
152 L<ClamAV::Client>.
153  
154 =head1 AUTHOR
155  
156 Julian Mehnle <julian@mehnle.net>
157  
158 =cut
159  
160 package ClamAV::Config::Error;
161 use base qw(Error::Simple);
162  
163 package ClamAV::Config;
164  
165 TRUE;
166  
167 # vim:tw=79