af7ac7d5e6810de1b49cfae340c0bef42b45fcc7
[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; charset=utf-8');
48     $r->content_type('text/html; charset=iso-8859-1');
49     #eorar
50
51     my $headers = $r->headers_out;
52     $headers->{'Cache-control'} = 'no-cache';
53     #$r->no_cache(1);
54     $headers->{'Expires'} = '0';
55
56 #    $r->send_http_header;
57
58     if ( $r->filename =~ /\/rt\// ) { #RT
59
60       $ah->interp($rt_interp);
61
62       local $SIG{__WARN__};
63       local $SIG{__DIE__};
64
65       RT::Init();
66
67       # We don't need to handle non-text, non-xml items
68       return -1 if defined( $r->content_type )
69                 && $r->content_type !~ m!(^text/|\bxml\b)!io;
70
71     } else {
72
73       local $SIG{__WARN__};
74       local $SIG{__DIE__};
75
76       RT::Init() if $RT::VERSION; #for lack of something else
77
78       #we don't want the RT error handlers under FS
79       {
80         local $^W = 0;
81         undef($SIG{__WARN__}) if defined($SIG{__WARN__});
82         undef($SIG{__DIE__})  if defined($SIG{__DIE__} );
83       }
84
85       $ah->interp($fs_interp);
86
87     }
88
89     my %session;
90     my $status;
91     eval { $status = $ah->handle_request($r); };
92 #!!
93 #    if ( $@ ) {
94 #       $RT::Logger->crit($@);
95 #    }
96     warn $@ if $@;
97
98     undef %session;
99
100 #!!
101 #    if ($RT::Handle->TransactionDepth) {
102 #       $RT::Handle->ForceRollback;
103 #       $RT::Logger->crit(
104 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
105 #       );
106 #    }
107
108     $status;
109 }
110
111 1;