From cdcad06988f85882d18139782ff0fa8592b75668 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 28 Aug 2013 12:07:09 +1200 Subject: [PATCH] Server now starts, and uses the config --- lib/NCIPServer.pm | 23 ++++++++++++++++++++--- t/NCIPServer.t | 8 +++++++- t/config_sample/NCIP.xml | 7 ++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/NCIPServer.pm b/lib/NCIPServer.pm index 6cfab2a..d8928ed 100644 --- a/lib/NCIPServer.pm +++ b/lib/NCIPServer.pm @@ -1,14 +1,31 @@ package NCIPServer; use Modern::Perl; +use NCIP::Configuration; -require Net::Server::PreFork;; - -our @ISA = qw(Net::Server::PreFork); +use base qw(Net::Server::PreFork); our $VERSION = '0.01'; +sub configure_hook { + my ($self) = @_; + my $server = $self->{'server'}; + my $config = NCIP::Configuration->new( $server->{'config_dir'} ); + my $server_params = $config->('NCIP.server-params'); + while ( my ( $key, $val ) = each %$server_params ) { + $server->{$key} = $val; + } + my $listeners = $config->('NCIP.listeners'); + foreach my $svc ( keys %$listeners ) { + $server->{'port'} = $listeners->{$svc}->{'port'}; + } +} +sub post_configure_hook { + my $self = shift; + use Data::Dumper; + print Dumper $self; +} 1; __END__ diff --git a/t/NCIPServer.t b/t/NCIPServer.t index dd270dc..22ca4e0 100644 --- a/t/NCIPServer.t +++ b/t/NCIPServer.t @@ -3,7 +3,13 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 2; BEGIN { use_ok('NCIPServer') }; +ok(my $server = NCIPServer->new({config_dir => '../t/config_sample'})); +use Data::Dumper; +print Dumper $server; +$server->run(); + +print Dumper $server; diff --git a/t/config_sample/NCIP.xml b/t/config_sample/NCIP.xml index 7fc02e2..04d6b05 100644 --- a/t/config_sample/NCIP.xml +++ b/t/config_sample/NCIP.xml @@ -3,13 +3,18 @@ + -- 2.43.2