2 use NCIP::Configuration;
9 use Object::Tiny qw{xmldoc config namespace ils};
11 our $VERSION = '0.01';
12 our $nsURI = 'http://www.niso.org/2008/ncip';
21 my $nicp = NCIP->new($config_dir);
29 my $class = ref $proto || $proto;
30 my $config_dir = shift;
32 my $config = NCIP::Configuration->new($config_dir);
33 $self->{config} = $config;
34 $self->{namespace} = $nsURI;
36 # load the ILS dependent module
37 my $module = 'NCIP::ILS::' . $config->('NCIP.ils.value');
38 load $module || die "Can not load ILS module $module";
39 my $ils = $module->new( name => $config->('NCIP.ils.value') );
40 $self->{'ils'} = $ils;
41 return bless $self, $class;
45 =head2 process_request()
47 my $response = $ncip->process_request($xml);
55 my ($request_type) = $self->handle_initiation($xml);
56 unless ($request_type) {
58 # We have invalid xml, or we can't figure out what kind of request this is
64 my $handler = NCIP::Handler->new( $self->namespace(), $request_type );
65 return $handler->handle( $self->xmldoc );
68 =head2 handle_initiation
72 sub handle_initiation {
77 $dom = XML::LibXML->load_xml( string => $xml );
80 warn "Invalid xml, caught error: $_";
84 # should check validity with validate at this point
85 if ( $self->validate($dom) ) {
86 my $request_type = $self->parse_request($dom);
88 # do whatever we should do to initiate, then hand back request_type
90 $self->{xmldoc} = $dom;
97 # not valid throw error
108 # this should perhaps be in it's own module
115 warn "Bad xml, caught error: $_";
119 # we could validate against the dtd here, might be good?
120 # my $dtd = XML::LibXML::Dtd->parse_string($dtd_str);
121 # $dom->validate($dtd);
122 # perhaps we could check the ncip version and validate that too
129 my $nodes = $dom->getElementsByTagNameNS( $nsURI, 'NCIPMessage' );
131 my @childnodes = $nodes->[0]->childNodes();
132 if ( $childnodes[1] ) {
133 return $childnodes[1]->localname();