[freeside-commits] freeside/htetc handler.pl,1.86.2.4,1.86.2.5

Ivan,,, ivan at wavetail.420.am
Thu Dec 27 23:45:37 PST 2007


Update of /home/cvs/cvsroot/freeside/htetc
In directory wavetail:/tmp/cvs-serv2984

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	handler.pl 
Log Message:
a little late help from kwanzabot for XSSmas... clean up handler.pl so we can have separate default_escape_flags for FS and RT and don't have to make FS's |h flag useless

Index: handler.pl
===================================================================
RCS file: /home/cvs/cvsroot/freeside/htetc/handler.pl,v
retrieving revision 1.86.2.4
retrieving revision 1.86.2.5
diff -u -d -r1.86.2.4 -r1.86.2.5
--- handler.pl	28 Oct 2007 03:55:28 -0000	1.86.2.4
+++ handler.pl	28 Dec 2007 07:45:35 -0000	1.86.2.5
@@ -1,13 +1,12 @@
 #!/usr/bin/perl
-#
-# This is a basic, fairly fuctional Mason handler.pl.
-#
-# For something a little more involved, check out session_handler.pl
 
 package HTML::Mason;
 
-# Bring in main Mason package.
-use HTML::Mason 1.1;
+use strict;
+use vars qw($r);
+use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
+use HTML::Mason::Interp;
+use HTML::Mason::Compiler::ToObject;
 
 # Bring in ApacheHandler, necessary for mod_perl integration.
 # Uncomment the second line (and comment the first) to use
@@ -15,11 +14,6 @@
 use HTML::Mason::ApacheHandler;
 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
 
-# Uncomment the next line if you plan to use the Mason previewer.
-#use HTML::Mason::Preview;
-
-use strict;
-
 ###use Module::Refresh;###
 
 # List of modules that you want to use from components (see Admin
@@ -28,18 +22,6 @@
 #   use CGI;
 #}
 
-# Create Mason objects
-#
-
-#my $parser = new HTML::Mason::Parser;
-#my $interp = new HTML::Mason::Interp (parser=>$parser,
-#                                      comp_root=>'/var/www/masondocs',
-#                                      data_dir=>'/usr/local/etc/freeside/masondata',
-#                                      out_mode=>'stream',
-#                                     );
-
-use vars qw($r);
-
 if ( %%%RT_ENABLED%%% ) {
  eval '
    use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
@@ -48,26 +30,43 @@
    RT::LoadConfig();
  ';
  die $@ if $@;
+}
 
+# Create Mason objects
 
-}
+my %interp = (
+  request_class        => 'HTML::Mason::Request::ApacheHandler',
+  data_dir             => '%%%MASONDATA%%%',
+  ignore_warnings_expr => '.',
+  comp_root            => [
+                            [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%'    ],
+                            [ 'rt'       => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
+                          ],
+);
 
+my $fs_interp = new HTML::Mason::Interp (
+  %interp,
+  escape_flags => { 'js_string' => sub {
+                      #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
+                      ${$_[0]} =~ s/(['\\])/\\$1/g;
+                      ${$_[0]} =~ s/\n/\\n/g;
+                      ${$_[0]} = "'". ${$_[0]}. "'";
+                    }
+                  },
+);
 
-my $ah = new HTML::Mason::ApacheHandler (
-  #interp => $interp,
-  #auto_send_headers => 0,
-  comp_root=> [
-                [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%'    ],
-                [ 'rt'       => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
-              ],
-  data_dir=>'%%%MASONDATA%%%',
-  #out_mode=>'stream',
+my $rt_interp = new HTML::Mason::Interp (
+  %interp,
+  escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
+  compiler     => HTML::Mason::Compiler::ToObject->new(
+                    default_escape_flags => 'h',
+                    allow_globals        => [qw(%session)],
+                  ),
+);
 
-  #RT
-  args_method => 'CGI',
-  default_escape_flags => 'h',
-  allow_globals => [qw(%session)],
-  #autoflush => 1,
+my $ah = new HTML::Mason::ApacheHandler (
+  interp      => $fs_interp,
+  args_method => 'CGI', #(and FS too)
 );
 
 # Activate the following if running httpd as root (the normal case).
@@ -119,8 +118,7 @@
       use Chart::LinesPoints;
       use Chart::Mountain;
       use Color::Scheme;
-      use HTML::Widgets::SelectLayers 0.06;
-      #use HTML::Widgets::SelectLayers 0.07; # after 1.7.2
+      use HTML::Widgets::SelectLayers 0.07;
       use Locale::Country;
       use FS;
       use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
@@ -320,29 +318,26 @@
 
 #    $r->send_http_header;
 
-    #$ah->interp->remove_escape('h');
-
     if ( $r->filename =~ /\/rt\// ) { #RT
-      #warn "processing RT file". $r->filename. "; escaping for RT\n";
 
+      $ah->interp($rt_interp);
       # MasonX::Request::ExtendedCompRoot
       #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
 
-      $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
-
       local $SIG{__WARN__};
       local $SIG{__DIE__};
 
       RT::Init();
 
       # We don't need to handle non-text, non-xml items
-      return -1 if defined( $r->content_type ) && $r->content_type !~ m!(^text/|\bxml\b)!io;
+      return -1 if defined( $r->content_type )
+                && $r->content_type !~ m!(^text/|\bxml\b)!io;
 
     } else {
-      $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
-    }
 
-    $ah->interp->ignore_warnings_expr('.');
+      $ah->interp($fs_interp);
+
+    }
 
     my %session;
     my $status;



More information about the freeside-commits mailing list