]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/Web.pm.in
Make Evergreen Perl modules installable via Module::Build to match OpenSRF
[Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / Web.pm.in
1 package OpenILS::WWW::Web;
2 use strict;
3 use warnings;
4
5 use Apache2::Log;
6 use Apache2::Const -compile => qw(OK REDIRECT :log);
7 use APR::Const     -compile => qw(:error SUCCESS);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO  ();
10 use Apache2::RequestUtil;
11
12 #use CGI ();
13 use Template;
14
15 use OpenSRF::EX qw(:try);
16 use OpenSRF::System;
17
18 my $main_ttk       = "opac/logic/page_router.ttk";
19 my $error_ttk      = "opac/pages/error.ttk";
20 my $init_ttk       = "opac/logic/page_init.ttk";
21 my $bootstrap      = "@sysconfdir@/opensrf_core.xml";
22 my $child_init_ttk = "opac/logic/child_init.ttk";
23
24 my $includes = [];    # [  '/pines/cvs/ILS/Open-ILS/src/templates' ];
25
26 sub import {
27     my ( $self, $tdir ) = @_;
28     $includes = [$tdir];
29 }
30
31 my $plugin_base = 'OpenILS::Template::Plugin';
32
33 sub handler {
34
35     my $apache = shift;
36     print "Content-type: text/html; charset=utf-8\n\n";
37
38     _process_template(
39         apache      => $apache,
40         template    => $main_ttk,
41         pre_process => $init_ttk
42     );
43
44     return Apache2::Const::OK;
45 }
46
47 sub child_init_handler {
48     _process_template( template => $child_init_ttk );
49 }
50
51 sub _process_template {
52
53     my %params      = @_;
54     my $ttk         = $params{template}    || return undef;
55     my $apache      = $params{apache}      || undef;
56     my $pre_process = $params{pre_process} || undef;
57     my $param_hash  = $params{params}      || {};
58
59     my $template;
60
61     $template = Template->new(
62         {
63             OUTPUT       => $apache,
64             ABSOLUTE     => 1,
65             RELATIVE     => 1,
66             PLUGIN_BASE  => $plugin_base,
67             PRE_PROCESS  => $pre_process,
68             INCLUDE_PATH => $includes,
69             PRE_CHOMP    => 1,
70             POST_CHOMP   => 1,
71         }
72     );
73
74     try {
75
76         if ( !$template->process( $ttk, $param_hash ) ) {
77             warn "Error Occured: " . $template->error();
78             my $err = $template->error();
79             $err =~ s/\n/\<br\/\>/g;
80             warn "Error processing template $ttk\n";
81             my $string =
82                 "<br><b>Unable to process template:<br/><br/> " 
83               . $err
84               . "!!!</b>";
85             $template->process( $error_ttk, { error => $string } );
86         }
87
88     }
89     catch Error with {
90         my $e = shift;
91         warn "Error processing template $ttk:  $e - $@ \n";
92         print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
93         return;
94     };
95
96 }
97
98 # This module appears obsolete (probably superceded by EGWeb.pm
99 # The template files it references do not exist in the codebase.
100 # File is not referenced elsewhere in the codebase.  Candidate for deletion.
101
102 1;