File Coverage

blib/lib/BoxBackup/Config/BBackupd.pm
Criterion Covered Total %
statement 15 46 32.6
branch 0 12 0.0
condition 0 14 0.0
subroutine 5 15 33.3
pod 0 9 0.0
total 20 96 20.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package BoxBackup::Config::BBackupd;
4 1     1   23739 use strict;
  1         2  
  1         34  
5 1     1   6 use Carp;
  1         2  
  1         91  
6 1     1   1018 use Config::Scoped;
  1         147382  
  1         14  
7              
8 1     1   46 use vars '$AUTOLOAD';
  1         2  
  1         75  
9             our $VERSION = v0.03;
10              
11 1         8 use subs qw(getStoreHostName
12             setStoreHostName
13             getAccountNumber
14             setAccountNumber
15             getKeysFile
16             setKeysFile
17             getCertificateFile
18             setCertificateFile
19             getPrivateKeyFile
20             setPrivateKeyFile
21             getTrustedCAsFile
22             setTrustedCAsFile
23             getDataDirectory
24             setDataDirectory
25             getNotifyScript
26             setNotifyScript
27             getAutomaticBackup
28             setAutomaticBackup
29             getUpdateStoreInterval
30             setUpdateStoreInterval
31             getMinimumFileAge
32             setMinimumFileAge
33             getMaxUploadWait
34             setMaxUploadWait
35             getFileTrackingSizeThreshold
36             setFileTrackingSizeThreshold
37             getDiffingUploadSizeThreshold
38             setDiffingUploadSizeThreshold
39             getMaximumDiffingTime
40             setMaximumDiffingTime
41             getExtendedLogging
42             setExtendedLogging
43             getCommandSocket
44             setCommandSocket
45 1     1   5 );
  1         2  
46              
47             sub new
48             {
49 0     0 0   my ($self, @args) = @_;
50 0   0       my $bbackupdFile = $args[0] || "/etc/box/bbackupd.conf";
51              
52 0           my $parser = Config::Scoped->new( file => $bbackupdFile );
53              
54 0           $self = $parser->parse;
55              
56 0           return bless $self;
57              
58             }
59              
60             sub save
61 0     0 0   {
62             }
63              
64             sub getServerPidFile
65             {
66             # This is a bit of an odd man out, since there is a section
67             # wrapped around the PidFile, but there is no real chance of
68             # multiple 'Server' sections, at least not at this time.
69 0     0 0   my $self = shift;
70            
71 0           return($self->{"Server"}{"PidFile"});
72            
73             }
74              
75             sub setServerPidFile
76             {
77             # This is a bit of an odd man out, since there is a section
78             # wrapped around the PidFile, but there is no real chance of
79             # multiple 'Server' sections, at least not at this time.
80 0     0 0   my $self = shift;
81 0           my $pidFile = shift;
82            
83 0           return($self->{"Server"}{"PidFile"} = shift);
84            
85             }
86              
87              
88             # Shamelessly copied from Ben's distribution bbackupd.conf
89             #
90             # BackupLocations specifies which locations on disc should be backed up. Each
91             # directory is in the format
92             #
93             # name
94             # {
95             # Path = /path/of/directory
96             # (optional exclude directives)
97             # }
98             #
99             # 'name' is derived from the Path by the config script, but should merely be
100             # unique.
101             #
102             # The exclude directives are of the form
103             #
104             # [Exclude|AlwaysInclude][File|Dir][|sRegex] = regex or full pathname
105             #
106             # (The regex suffix is shown as 'sRegex' to make File or Dir plural)
107             #
108             # For example:
109             #
110             # ExcludeDir = /home/guest-user
111             # ExcludeFilesRegex = *.(mp3|MP3)$
112             # AlwaysIncludeFile = /home/username/veryimportant.mp3
113             #
114             # This excludes the directory /home/guest-user from the backup along with all mp3
115             # files, except one MP3 file in particular.
116             #
117             # In general, Exclude excludes a file or directory, unless the directory is
118             # explicitly mentioned in a AlwaysInclude directive.
119              
120              
121              
122              
123             sub getListOfBackupLocations
124 0     0 0   {
125             }
126              
127             sub getBackupLocationPath
128 0     0 0   {
129             }
130              
131             sub setBackupLocationPath
132 0     0 0   {
133             }
134              
135             sub addBackupLocation
136 0     0 0   {
137             }
138              
139             sub removeBackupLocation
140 0     0 0   {
141             }
142              
143             # The AUTOLOAD method handles all getters and setters.
144             #
145             # It's a little hairy, because it also handles getters/setters
146             # for the 'BackupLocations' sections.
147             sub AUTOLOAD
148             {
149 0     0     my $self = shift;
150            
151 0 0         croak "$self not an object" unless ref($self);
152            
153 0 0         return if $AUTOLOAD =~ /::DESTROY$/;
154            
155 0 0         if($AUTOLOAD =~ /.*::get(\w+)/) # this is a getter
156             {
157 0           my $name = $1;
158             # For the 'BackupLocations' section we have to get the location
159             # in question, before we know which parameter value to get.
160 0 0 0       if($name =~ /AlwaysInclude/ || $name =~ /Exclude/ || $name =~ /Path/)
      0        
161             {
162 0           my $backupLocation = shift;
163 0           return($self->{"BackupLocations"}{$backupLocation}{$name});
164             }
165             else
166             {
167 0           return($self->{$name});
168             }
169             }
170            
171 0 0         if($AUTOLOAD =~ /.*::set(\w+)/) # this is a setter
172             {
173            
174 0           my $name = $1;
175 0 0 0       if($name =~ /AlwaysInclude/ || $name =~ /Exclude/ || $name =~ /Path/)
      0        
176             {
177 0           my $backupLocation = shift;
178 0           return($self->{"BackupLocations"}{$backupLocation}{$name} = shift);
179             }
180             else
181             {
182 0           return($self->{$name} = shift);
183             }
184             }
185            
186             }
187              
188             1;