File Coverage

blib/lib/App/Rsnapshot/Config.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package App::Rsnapshot::Config;
2              
3 3     3   23805 use strict;
  3         7  
  3         127  
4 3     3   32 use warnings;
  3         4  
  3         94  
5              
6 3     3   1859 use App::Rsnapshot::XML::Tiny;
  3         6  
  3         161  
7 3     3   1732 use App::Rsnapshot::Config::Node;
  3         8  
  3         91  
8              
9 3     3   20 use vars qw($VERSION);
  3         4  
  3         462  
10              
11             $VERSION = '1.0';
12              
13             =head1 NAME
14              
15             App::Rsnapshot::Config - parse the config file; OO interface to read it
16              
17             =head1 SYNOPSIS
18              
19             my $config = App::Rsnapshot::Config->new('/etc/rsnapshot.conf');
20              
21             ...
22              
23             my $rsync = $config->externalprograms()->rsync();
24             my $rsyncbinary = $rsync->binary();
25             my $rsyncargs = [
26             $rsync->shortargs()->values(),
27             $srync->longargs()->values()
28             ];
29              
30             =head1 DESCRIPTION
31              
32             Parses an XML config file, and provides a nice objecty interface to get
33             at information in it. Note that it does only minimal verification of
34             the XML schema or anything like that.
35              
36             =head1 METHODS
37              
38             =head2 new
39              
40             Constructor, takes a filename (with path) and returns an
41             App::Rsnapshot::Config::Node object representing the root of the
42             XML document tree.
43              
44             =cut
45              
46             sub new {
47 3     3 1 67 my $class = shift;
48 3         8 my $file = shift;
49 3         19 my $document = App::Rsnapshot::XML::Tiny::parsefile($file)->[0];
50 3 50       19 die("$file isn't a valid config file - wrong top-level element\n")
51             unless($document->{name} eq 'rsnapshot');
52 3         52 return App::Rsnapshot::Config::Node->new($document);
53             }
54              
55             =head1 BUGS/WARNINGS/LIMITATIONS
56              
57             This uses App::Rsnapshot::XML::Tiny, so is subject to all of its bugs
58             and foibles. Bug reports are most welcome.
59              
60             =head1 SOURCE CODE REPOSITORY
61              
62             L
63              
64             =head1 AUTHOR, COPYRIGHT and LICENCE
65              
66             Copyright 2009 David Cantrell
67              
68             This software is free-as-in-speech software, and may be used,
69             distributed, and modified under the terms of either the GNU
70             General Public Licence version 2 or the Artistic Licence. It's
71             up to you which one you use. The full text of the licences can
72             be found in the files GPL2.txt and ARTISTIC.txt, respectively.
73              
74             =head1 CONSPIRACY
75              
76             This module is also free-as-in-mason software.
77              
78             =cut
79              
80             1;