borg RT menus, RT#1169
[freeside.git] / htetc / handler.pl
1 #!/usr/bin/perl
2
3 package HTML::Mason;
4
5 use strict;
6 use warnings;
7 use FS::Mason qw( mason_interps );
8
9 #use vars qw($r);
10
11 # Bring in ApacheHandler, necessary for mod_perl integration.
12 # Uncomment the second line (and comment the first) to use
13 # Apache::Request instead of CGI.pm to parse arguments.
14 use HTML::Mason::ApacheHandler;
15 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
16
17 ###use Module::Refresh;###
18
19 # Create Mason objects
20
21 my( $fs_interp, $rt_interp ) = mason_interps('apache');
22
23 my $ah = new HTML::Mason::ApacheHandler (
24   interp        => $fs_interp,
25   request_class => 'FS::Mason::Request',
26   args_method   => 'CGI', #(and FS too)
27 );
28
29 # Activate the following if running httpd as root (the normal case).
30 # Resets ownership of all files created by Mason at startup.
31 #
32 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
33
34 sub handler
35 {
36     #($r) = @_;
37     my $r = shift;
38
39     # If you plan to intermix images in the same directory as
40     # components, activate the following to prevent Mason from
41     # evaluating image files as components.
42     #
43     #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
44
45     ###Module::Refresh->refresh;###
46
47     $r->content_type('text/html');
48     #eorar
49
50     my $headers = $r->headers_out;
51     $headers->{'Cache-control'} = 'no-cache';
52     #$r->no_cache(1);
53     $headers->{'Expires'} = '0';
54
55 #    $r->send_http_header;
56
57     if ( $r->filename =~ /\/rt\// ) { #RT
58
59       $ah->interp($rt_interp);
60
61       local $SIG{__WARN__};
62       local $SIG{__DIE__};
63
64       RT::Init();
65
66       # We don't need to handle non-text, non-xml items
67       return -1 if defined( $r->content_type )
68                 && $r->content_type !~ m!(^text/|\bxml\b)!io;
69
70     } else {
71
72       RT::Init() if $RT::VERSION; #for lack of something else
73
74       $ah->interp($fs_interp);
75
76     }
77
78     my %session;
79     my $status;
80     eval { $status = $ah->handle_request($r); };
81 #!!
82 #    if ( $@ ) {
83 #       $RT::Logger->crit($@);
84 #    }
85     warn $@ if $@;
86
87     undef %session;
88
89 #!!
90 #    if ($RT::Handle->TransactionDepth) {
91 #       $RT::Handle->ForceRollback;
92 #       $RT::Logger->crit(
93 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
94 #       );
95 #    }
96
97     $status;
98 }
99
100 1;