]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/Configuration.pm
4db0e5fce321153c2beba7110e1ab588350feb9c
[working/NCIPServer.git] / lib / NCIP / Configuration.pm
1 package NCIP::Configuration;
2 #
3 #===============================================================================
4 #
5 #         FILE: Configuration.pm
6 #
7 #  DESCRIPTION:
8 #
9 #        FILES: ---
10 #         BUGS: ---
11 #        NOTES: ---
12 #       AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
13 # ORGANIZATION: Koha Development Team
14 #      VERSION: 1.0
15 #      CREATED: 28/08/13 10:16:55
16 #     REVISION: ---
17 #===============================================================================
18
19 =head1 NAME
20   
21   NCIP::Configuration
22
23 =head1 SYNOPSIS
24
25   use NCIP::Configuration;
26   my $config = NCIP::Configuration->new($config_dir);
27
28 =cut
29
30 use Modern::Perl;
31
32 use NCIP::Configuration::Service;
33 use base qw(Config::Merge);
34
35 sub new {
36     my $class = shift;
37     my $self  = $class->SUPER::new(@_);
38     my @services;
39
40     # we might have a few services set them up safely
41     if ( ref( $self->('NCIP.listeners.service') ) eq 'ARRAY' ) {
42         @services = $self->('NCIP.listeners.service');
43     }
44     else {
45         @services = ( $self->('NCIP.listeners')->{'service'} );
46     }
47     my %listeners;
48     foreach my $service (@services) {
49         my $serv_object = NCIP::Configuration::Service->new($service);
50         $listeners{ lc $service->{'port'} } = $serv_object;
51     }
52     $self->{'listeners'} = \%listeners;
53     return $self;
54 }
55
56 sub find_service {
57     my ( $self, $sockaddr, $port, $proto ) = @_;
58     my $portstr;
59     foreach my $addr ( '', '*:', "$sockaddr:" ) {
60         $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
61         Sys::Syslog::syslog( "LOG_DEBUG",
62             "Configuration::find_service: Trying $portstr" );
63         last if ( exists( ( $self->{listeners} )->{$portstr} ) );
64     }
65     return $self->{listeners}->{$portstr};
66 }
67 1;
68