From 62e1920ad015355beed5cdc71eccb8998cae07bd Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Fri, 20 Sep 2013 09:58:51 +1200 Subject: [PATCH] Tidying up and starting to extend the handler --- lib/NCIP.pm | 9 ++++++--- lib/NCIP/Handler.pm | 12 ++++++------ lib/NCIP/Handler/LookupItem.pm | 9 +++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/NCIP.pm b/lib/NCIP.pm index 5031f6f..b84dca6 100644 --- a/lib/NCIP.pm +++ b/lib/NCIP.pm @@ -5,7 +5,7 @@ use Modern::Perl; use XML::LibXML; use Try::Tiny; -use Object::Tiny; +use Object::Tiny qw{xmldoc config}; our $VERSION = '0.01'; our $nsURI = 'http://www.niso.org/2008/ncip'; @@ -44,7 +44,7 @@ sub process_request { my $self = shift; my $xml = shift; - my $request_type = $self->handle_initiation($xml); + my ($request_type) = $self->handle_initiation($xml); unless ($request_type) { # We have invalid xml, or we can't figure out what kind of request this is @@ -54,7 +54,7 @@ sub process_request { #bail out for now } my $handler = NCIP::Handler->new($request_type); - return $handler->handle($xml); + return $handler->handle( $self->xmldoc ); } =head2 handle_initiation @@ -76,13 +76,16 @@ sub handle_initiation { # should check validity with validate at this point if ( $self->validate($dom) ) { my $request_type = $self->parse_request($dom); + # do whatever we should do to initiate, then hand back request_type if ($request_type) { + $self->{xmldoc} = $dom; return $request_type; } } else { warn "Not valid xml"; + # not valid throw error return; } diff --git a/lib/NCIP/Handler.pm b/lib/NCIP/Handler.pm index e9577c5..4fda628 100644 --- a/lib/NCIP/Handler.pm +++ b/lib/NCIP/Handler.pm @@ -4,7 +4,7 @@ package NCIP::Handler; # # FILE: Hander.pm # -# DESCRIPTION: +# DESCRIPTION: # # FILES: --- # BUGS: --- @@ -19,14 +19,14 @@ package NCIP::Handler; use Modern::Perl; use Object::Tiny qw{ type }; - use NCIP::Handler::LookupItem; sub new { - my $class = shift; - my $type = shift; - my $subclass = __PACKAGE__."::".$type; - my $self = bless { type => $type }, $subclass; + my $class = shift; + my $type = shift; + my $xmldoc = shift; + my $subclass = __PACKAGE__ . "::" . $type; + my $self = bless { type => $type }, $subclass; return $self; } diff --git a/lib/NCIP/Handler/LookupItem.pm b/lib/NCIP/Handler/LookupItem.pm index 81c192e..77c758f 100644 --- a/lib/NCIP/Handler/LookupItem.pm +++ b/lib/NCIP/Handler/LookupItem.pm @@ -5,7 +5,7 @@ package NCIP::Handler::LookupItem; # # FILE: LookupItem.pm # -# DESCRIPTION: +# DESCRIPTION: # # FILES: --- # BUGS: --- @@ -23,7 +23,12 @@ use NCIP::Handler; our @ISA = qw(NCIP::Handler); sub handle { - my $self = shift; + my $self = shift; + my $xmldoc = shift; + if ($xmldoc) { + # my ($item_id) = $dom->getElementsByTagNameNS( $nsURI, 'ItemId' ); + } + des = $dom->getElementsByTagNameNS( $nsURI, 'NCIPMessage' ); return $self->type; } -- 2.11.0