use Modern::Perl;
+use NCIP::Configuration::Service;
use base qw(Config::Merge);
+sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new(@_);
+ my @services;
+
+ # we might have a few services set them up safely
+ if ( ref( $self->('NCIP.listeners.service') ) eq 'ARRAY' ) {
+ @services = $self->('NCIP.listeners.service');
+ }
+ else {
+ @services = ( $self->('NCIP.listeners')->{'service'} );
+ }
+ my %listeners;
+ foreach my $service (@services) {
+ my $serv_object = NCIP::Configuration::Service->new($service);
+ $listeners{ lc $service->{'port'} } = $serv_object;
+ }
+ $self->{'listeners'} = \%listeners;
+ return $self;
+}
+
+sub find_service {
+ my ( $self, $sockaddr, $port, $proto ) = @_;
+ my $portstr;
+ foreach my $addr ( '', '*:', "$sockaddr:" ) {
+ $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
+
+ # Sys::Syslog::syslog( "LOG_DEBUG",
+ # "Configuration::find_service: Trying $portstr" );
+ # print "Configuration::find_service: Trying $portstr";
+ last if ( exists( ( $self->{listeners} )->{$portstr} ) );
+ }
+ return $self->{listeners}->{$portstr};
+}
1;
--- /dev/null
+package NCIP::Configuration::Service;
+
+use Modern::Perl;
+
+sub new {
+ my ($class, $obj) = @_;
+ my $type = ref($class) || $class;
+
+ if (ref($obj) eq "HASH") {
+ # Just bless the object
+ return bless $obj, $type;
+ }
+
+ return bless {}, $type;
+}
+
+1;
use strict;
use warnings;
-use Test::More tests => 4; # last test to print
+use Test::More tests => 5; # last test to print
use_ok('NCIP::Configuration');
is( $server_params->{'min_servers'}, 1, 'Do we have a minimum of one server' );
+ok ($config->find_service('127.0.0.1','6001','tcp'),'Testing find_service');
+