]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/WWW/AddedContent.pm
using org email as reply-to
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / AddedContent.pm
1 package OpenILS::WWW::AddedContent;
2 use strict; use warnings;
3
4 use lib qw(/usr/lib/perl5/Bundle/);
5
6 use CGI;
7 use Apache2 ();
8 use Apache2::Log;
9 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
10 use APR::Const    -compile => qw(:error SUCCESS);
11 use Apache2::RequestRec ();
12 use Apache2::RequestIO ();
13 use Apache2::RequestUtil;
14 use Data::Dumper;
15
16 use OpenSRF::EX qw(:try);
17 use OpenSRF::Utils::Cache;
18 use OpenSRF::System;
19 use OpenSRF::Utils::Logger qw/$logger/;
20 use XML::LibXML;
21
22
23 # set the bootstrap config when this module is loaded
24 my $bs_config;
25 my $handler;
26
27 sub import {
28         my $self = shift;
29         $bs_config = shift;
30 }
31
32
33 sub child_init {
34
35         OpenSRF::System->bootstrap_client( config_file => $bs_config );
36
37         my $sclient = OpenSRF::Utils::SettingsClient->new();
38         my $ac_data = $sclient->config_value("added_content");
39         my $ac_handler = $ac_data->{module};
40         return unless $ac_handler;
41
42         $logger->debug("Attempting to load Added Content handler: $ac_handler");
43
44         eval "use $ac_handler";
45
46         if($@) {        
47                 $logger->error("Unable to load Added Content handler [$ac_handler]: $@"); 
48                 return; 
49         }
50
51         $handler = $ac_handler->new($ac_data);
52         $logger->debug("added content loaded handler: $handler");
53 }
54
55
56 sub handler {
57
58         my $r           = shift;
59         my $cgi = CGI->new;
60         my $path = $r->path_info;
61
62         child_init() unless $handler; # why isn't apache doing this for us?
63         return Apache2::Const::NOT_FOUND unless $handler;
64
65         my( undef, $data, $format, $key ) = split(/\//, $r->path_info);
66
67         my $err;
68         my $success;
69         my $method = "${data}_${format}";
70
71         try {
72                 $success = $handler->$method($key);
73         } catch Error with {
74                 my $err = shift;
75                 $logger->error("added content handler failed: $method($key) => $err");
76         };
77
78         return Apache2::Const::NOT_FOUND if $err or !$success;
79         return Apache2::Const::OK;
80 }
81
82
83
84 1;
85