]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - NCIP/Configuration.pm
This is my start to the NCIPServer, the only real code is the Apache NCIPResponder...
[working/NCIPServer.git] / NCIP / Configuration.pm
1 #
2 # Copyright (C) 2013  MnSCU/PALS
3
4 # Author: Alan Rykhus
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of version 2 of the GNU General Public
8 # License as published by the Free Software Foundation.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public
16 # License along with this program; if not, write to the Free
17 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 # MA 02111-1307 USA
19
20 # parse-config: Parse an XML-format
21 # ACS configuration file and build the configuration
22 # structure.
23 #
24
25 package NCIPServer::NCIP::Configuration;
26
27 our $VERSION = 0.02;
28
29 use strict;
30 use warnings;
31 use XML::Simple qw(:strict);
32
33 use NCIPServer::NCIP::Configuration::Account;
34 use NCIPServer::NCIP::Configuration::Institution;
35
36 my $parser = new XML::Simple(
37     KeyAttr => {
38         login       => '+id',
39         institution => '+id',
40     },
41     GroupTags => {
42         accounts     => 'login',
43         institutions => 'institution',
44     },
45     ForceArray => [ 'login', 'institution' ],
46 );
47
48 sub new {
49     my ($class, $config_file) = @_;
50     my $cfg = $parser->XMLin($config_file);
51
52     foreach my $acct (values %{$cfg->{accounts}}) {
53         new NCIPServer::NCIP::Configuration::Account $acct;
54     }
55
56     foreach my $inst (values %{$cfg->{institutions}}) {
57         new NCIPServer::NCIP::Configuration::Institution $inst;
58     }
59
60     return bless $cfg, $class;
61 }
62
63 sub accounts {
64     my $self = shift;
65     return values %{$self->{accounts}};
66 }
67
68 sub institutions {
69     my $self = shift;
70     return values %{$self->{institutions}};
71 }
72
73 1;
74 __END__
75
76 =head1 NAME
77
78 NCIPServer::NCIP::Configuration - abstraction/accessor for NCIP configs
79
80 =head1 SYNOPSIS
81
82 use NCIPServer::NCIP::Configuration;
83 my $config = NCIPServer::NCIP::Configuration->new($ARGV[0]);
84
85 foreach my $acct ($config->accounts) {
86     print "Found account: '", $acct->id, "', part of '";
87     print $acct->institution, "'\n";
88 }
89
90 =cut
91