From f7038c7b9f991c95dd2f4e2398da763d69a7dd97 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 30 Dec 2013 14:40:26 +1300 Subject: [PATCH] Responding better now --- lib/NCIP.pm | 14 +++++++------- lib/NCIP/Handler.pm | 19 ++++++++++++++++--- lib/NCIP/Handler/LookupUser.pm | 9 ++++++--- templates/response.tt | 2 +- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/NCIP.pm b/lib/NCIP.pm index 8cb6a9e..e8eaf66 100644 --- a/lib/NCIP.pm +++ b/lib/NCIP.pm @@ -63,9 +63,10 @@ sub process_request { } my $handler = NCIP::Handler->new( { - namespace => $self->namespace(), - type => $request_type, - ils => $self->ils + namespace => $self->namespace(), + type => $request_type, + ils => $self->ils, + template_dir => $self->config->('NCIP.templates.value'), } ); return $handler->handle( $self->xmldoc ); @@ -137,9 +138,8 @@ sub parse_request { if ($nodes) { warn "got nodes"; my @childnodes = $nodes->[0]->childNodes(); - warn $nodes; - if ( $childnodes[1] ) { - return $childnodes[1]->localname(); + if ( $childnodes[0] ) { + return $childnodes[0]->localname(); } else { warn "Got a node, but no child node"; @@ -154,7 +154,7 @@ sub parse_request { } sub _error { - my $self = shift; + my $self = shift; my $error_detail = shift; my $vars; $vars->{'error_detail'} = $error_detail; diff --git a/lib/NCIP/Handler.pm b/lib/NCIP/Handler.pm index 30c2ccf..bf1d7c7 100644 --- a/lib/NCIP/Handler.pm +++ b/lib/NCIP/Handler.pm @@ -17,20 +17,33 @@ package NCIP::Handler; #=============================================================================== use Modern::Perl; -use Object::Tiny qw{ type namespace ils }; +use Object::Tiny qw{ type namespace ils templates }; use Module::Load; +use Template; sub new { my $class = shift; my $params = shift; my $subclass = __PACKAGE__ . "::" . $params->{type}; load $subclass || die "Can't load module $subclass"; - my $self = bless { + my $self = bless { type => $params->{type}, namespace => $params->{namespace}, - ils => $params->{ils} + ils => $params->{ils}, + templates => $params->{template_dir} }, $subclass; return $self; } +sub render_output { + my $self = shift; + my $templatename = shift; + + my $vars = shift; + my $template = Template->new( + { INCLUDE_PATH => $self->templates, } ); + my $output; + $template->process( $templatename, $vars, \$output ); + return $output; +} 1; diff --git a/lib/NCIP/Handler/LookupUser.pm b/lib/NCIP/Handler/LookupUser.pm index dc78795..2cc984f 100644 --- a/lib/NCIP/Handler/LookupUser.pm +++ b/lib/NCIP/Handler/LookupUser.pm @@ -33,9 +33,12 @@ sub handle { my $user = NCIP::User->new( { userid => $user_id->textContent(), ils => $self->ils } ); $user->initialise(); - use Data::Dumper; - warn Dumper $user->userdata(); - return $user->userid(); + my $vars; + $vars->{'messagetype'} = 'LookupUserResponse'; + $vars->{'user'} = $user; + my $output = $self->render_output('response.tt',$vars); + return $output; + } } diff --git a/templates/response.tt b/templates/response.tt index 63dc1c0..f9ea3be 100644 --- a/templates/response.tt +++ b/templates/response.tt @@ -15,7 +15,7 @@ [% toagency %] - + -- 2.43.2