]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIPResponder.pm
Continuing on with the changes
[working/NCIPServer.git] / lib / NCIPResponder.pm
1 package NCIPResponder;
2 use Modern::Perl;
3 use NCIP;
4
5 use FileHandle;
6
7 use Apache2::Const -compile => qw(OK :log :http :methods :cmd_how :override);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10
11 sub handler {
12     my $r = shift;
13
14     return Apache2::Const::HTTP_METHOD_NOT_ALLOWED unless $r->method_number eq Apache2::Const::M_POST;
15
16     my $NCIPConfigFile = $r->dir_config('NCIPConfigFile');
17
18     if (!defined($NCIPConfigFile)) {
19         die sprintf "error: There is no NCIPConfigFile defined\n";
20     } else {
21         if (! (-r $NCIPConfigFile)) {
22             die sprintf "error: NCIPConfigFile %s does not exist or is not readable\n", $NCIPConfigFile;
23         }
24     }
25
26     my $ncip = NCIP->new($NCIPConfigFile);
27
28     $r->content_type('text/html');
29     my $tmp_buf;
30     my $input_xml;
31
32     while ($r->read($tmp_buf, 1024)) {
33         $input_xml .= $tmp_buf;
34     }
35
36     my $response_xml = $ncip->process_request($input_xml);
37
38     $r->print($response_xml);
39     return Apache2::Const::OK;
40 }
41
42 1;