]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP.pm
Working on extending the functionality and test suite.
[working/NCIPServer.git] / lib / NCIP.pm
1 package NCIP;
2 use NCIP::Configuration;
3 use Modern::Perl;
4 use XML::LibXML;
5 use Try::Tiny;
6
7 use base qw(Class::Accessor);
8
9 our $VERSION = '0.01';
10
11 =head1 NAME
12   
13     NCIP
14
15 =head1 SYNOPSIS
16
17     use NCIP;
18     my $nicp = NCIP->new($config_dir);
19
20 =head1 FUNCTIONS
21
22 =cut
23
24 sub new {
25     my $proto      = shift;
26     my $class      = ref $proto || $proto;
27     my $config_dir = shift;
28     my $self       = {};
29     my $config     = NCIP::Configuration->new($config_dir);
30     $self->{config} = $config;
31     return bless $self, $class;
32
33 }
34
35 =head2 process_request()
36
37  my $response = $ncip->process_request($xml);
38
39 =cut
40
41 sub process_request {
42     my $self = shift;
43     my $xml  = shift;
44
45     my $request_type = $self->handle_initiation($xml);
46     unless ($request_type) {
47
48       # We have invalid xml, or we can't figure out what kind of request this is
49       # Handle error here
50     }
51     my $response =
52 "<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>";
53
54     return $response;
55 }
56
57 =head2 handle_initiation
58
59 =cut
60
61 sub handle_initiation {
62     my $self = shift;
63     my $xml  = shift;
64     my $dom;
65     try {
66         $dom = XML::LibXML->load_xml( string => $xml );
67     }
68     catch {
69         warn "Invalid xml, caught error: $_";
70     };
71     if ($dom) {
72         return ('lookup_item');
73     }
74     else {
75         return;
76     }
77 }
78
79 1;