package NCIP;
use NCIP::Configuration;
+use NCIP::Handler;
use Modern::Perl;
use XML::LibXML;
use Try::Tiny;
-use base qw(Class::Accessor);
+use Object::Tiny;
our $VERSION = '0.01';
-our $nsURI = 'http://www.niso.org/2008/ncip';
+our $nsURI = 'http://www.niso.org/2008/ncip';
=head1 NAME
# We have invalid xml, or we can't figure out what kind of request this is
# Handle error here
+ return;
+
+ #bail out for now
}
#my $response = "<HTML> <HEAD> <TITLE>Hello There</TITLE> </HEAD> <BODY> <H1>Hello You Big JERK!</H1> Who would take this book seriously if the first eaxample didn't say \"hello world\"? </BODY> </HTML>";
#return $response;
- return $request_type;
+ warn $request_type;
+ my $handler = NCIP::Handler->new($request_type);
+ return $handler->handle($xml);
}
=head2 handle_initiation
if ($dom) {
# should check validity with validate at this point
+ # if ( $self->validate($dom) ) {
my $request_type = $self->parse_request($dom);
- return $request_type;
+
+ # do whatever we should do to initiate, then hand back request_type
+ if ($request_type) {
+ return $request_type;
+ }
+
+ # }
+ # else {
+ # warn "Not valid xml";
+ # not valid throw error
+ # return;
+ # }
+
}
else {
return;
sub parse_request {
my $self = shift;
my $dom = shift;
- my $nodes = $dom->getElementsByTagNameNS($nsURI,'NCIPMessage');
- if ($nodes){
+ my $nodes = $dom->getElementsByTagNameNS( $nsURI, 'NCIPMessage' );
+ if ($nodes) {
my @childnodes = $nodes->[0]->childNodes();
- if ($childnodes[1]){
+ if ( $childnodes[1] ) {
return $childnodes[1]->localname();
}
else {
- return "unknown";
+ return;
}
}
else {
--- /dev/null
+package NCIP::Handler;
+#
+#===============================================================================
+#
+# FILE: Hander.pm
+#
+# DESCRIPTION:
+#
+# FILES: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
+# ORGANIZATION: Koha Development Team
+# VERSION: 1.0
+# CREATED: 19/09/13 10:43:14
+# REVISION: ---
+#===============================================================================
+
+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;
+ return $self;
+}
+
+1;
--- /dev/null
+package NCIP::Handler::LookupItem;
+
+#
+#===============================================================================
+#
+# FILE: LookupItem.pm
+#
+# DESCRIPTION:
+#
+# FILES: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
+# ORGANIZATION: Koha Development Team
+# VERSION: 1.0
+# CREATED: 19/09/13 10:52:44
+# REVISION: ---
+#===============================================================================
+
+use Modern::Perl;
+
+use NCIP::Handler;
+our @ISA = qw(NCIP::Handler);
+
+sub handle {
+ my $self = shift;
+ return $self->type;
+}
+
+1;
use warnings;
use File::Slurp;
-use Test::More tests => 9; # last test to print
+use Test::More tests => 7; # last test to print
use lib 'lib';
use_ok('NCIP');
ok( my $ncip = NCIP->new('t/config_sample'), 'Create new object' );
-my $xml = <<'EOT';
-<?xml version="1.0" encoding="UTF-8"?>
-<ns1:NCIPMessage
- ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd" xmlns:ns1="http://www.niso.org/2008/ncip">
-</ns1:NCIPMessage>
-EOT
-
-ok( my $response = $ncip->process_request($xml), 'Process a request' );
-
my $xmlbad = <<'EOT';
<xml>
this is bad
# handle_initiation is called as part of the process_request, but best to test
# anyway
ok( !$ncip->handle_initiation($xmlbad), 'Bad xml' );
-ok( $ncip->handle_initiation($xml), 'Good XML' );
my $lookupitem = read_file('t/sample_data/LookupItem.xml');
-ok( $response = $ncip->process_request($lookupitem), 'Try looking up an item');
-is ($response, 'LookupItem', 'We got lookupitem');
-
-$lookupitem = read_file('t/sample_data/LookupItemWithExampleItemIdentifierType.xml');
-ok( $response = $ncip->process_request($lookupitem), 'Try looking up an item, with agency');
-is ($response, 'LookupItem', 'We got lookupitem with agency');
+ok( my $response = $ncip->process_request($lookupitem),
+ 'Try looking up an item' );
+is( $response, 'LookupItem', 'We got lookupitem' );
+
+$lookupitem =
+ read_file('t/sample_data/LookupItemWithExampleItemIdentifierType.xml');
+ok(
+ $response = $ncip->process_request($lookupitem),
+ 'Try looking up an item, with agency'
+);
+is( $response, 'LookupItem', 'We got lookupitem with agency' );
--- /dev/null
+#
+#===============================================================================
+#
+# FILE: NCIP_Handler.t
+#
+# DESCRIPTION:
+#
+# FILES: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
+# ORGANIZATION: Koha Development Team
+# VERSION: 1.0
+# CREATED: 19/09/13 11:32:01
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+
+use Test::More tests => 1; # last test to print
+use lib 'lib';
+
+use_ok('NCIP::Handler');
+
+my $type='LookupItem';
+
+ok (my $handler = NCIP::Handler->new($type), 'Create new handler');
+ok (my $response = $handler->handle());