[Rt-commit] r6519 - in rt/branches/3.7-EXPERIMENTAL: . lib/RT/Interface/Web

ruz at bestpractical.com ruz at bestpractical.com
Sun Nov 26 17:44:43 EST 2006


Author: ruz
Date: Sun Nov 26 17:44:42 2006
New Revision: 6519

Added:
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Request.pm
Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/html/Elements/Callback
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Handler.pm

Log:
 r4176 at cubic-pc:  cubic | 2006-11-27 01:49:32 +0300
  r3507 at cubic-pc:  cubic | 2006-06-29 05:59:03 +0400
  * new class RT::Interface::Web::Request
  ** subclass of the HTML::Mason::Request
  ** with method rt_callback which replaces Elements/Callback
  * add CallbackOnce option, to allow run callbacks once per
    perl interpreter, useful to push static data into RT
    structures from callbacks
  
 


Modified: rt/branches/3.7-EXPERIMENTAL/html/Elements/Callback
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Elements/Callback	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Elements/Callback	Sun Nov 26 17:44:42 2006
@@ -43,48 +43,9 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<%once>
-my %cache;
-</%once>
-<%init>
-$Page ||= $m->callers(1)->path;
-
-my $CacheKey = "Callback--$Page--$_CallbackName";
-my $callbacks = $cache{$CacheKey} || $m->notes($CacheKey);
-
-if (!$callbacks) {
-    my $path  = "/Callbacks/*$Page/$_CallbackName";
-
-    # Due to API changes after Mason 1.28, we have to check for which
-    # version we're running when getting the component roots
-    my @roots = map { $_->[1] }
-                    $HTML::Mason::VERSION <= 1.28
-                        ? $m->interp->resolver->comp_root_array
-                        : $m->interp->comp_root_array;
-    
-    my %seen;
-    
-    for my $root (@roots) {
-        push @$callbacks,
-            # Skip backup files, files without a leading package name,
-            # and files we've already seen
-            grep      !/\/\.|~$/
-                   && $_ ne "/Callbacks/$Page/$_CallbackName"
-                   && !$seen{$_}++,
-                 $m->interp->resolver->glob_path($path, $root);
-    }
-
-    $m->notes($CacheKey => $callbacks);
-    $cache{ $CacheKey } = $callbacks unless RT->Config->Get('DevelMode');
-}
-
-my @rv;
-foreach my $comp (sort @$callbacks) {
-    push @rv, $m->comp($comp, %ARGS);
-}
-return @rv;
-</%init>
-<%args>
-$_CallbackName => 'Default'
-$Page => undef
-</%args>
+<%INIT>
+$ARGS{'CallbackPage'} = delete $ARGS{'Page'} || $m->callers(1)->path;
+$ARGS{'CallbackName'} = delete $ARGS{'_CallbackName'};
+$RT::Logger->debug("$ARGS{'CallbackPage'} calls old style callback, use \$m->rt_callback");
+return $m->rt_callback( %ARGS );
+</%INIT>

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Handler.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Handler.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Handler.pm	Sun Nov 26 17:44:42 2006
@@ -56,6 +56,7 @@
 use HTML::Scrubber;
 use Text::Quoted;
 use RT::Interface::Web::Handler;
+use RT::Interface::Web::Request;
 use File::Path qw( rmtree );
 use File::Glob qw( bsd_glob );
 use File::Spec::Unix;
@@ -71,7 +72,8 @@
     # Turn off static source if we're in developer mode.
     static_source        => (RT->Config->Get('DevelMode') ? '0' : '1'), 
     use_object_files     => (RT->Config->Get('DevelMode') ? '0' : '1'), 
-    autoflush            => 0
+    autoflush            => 0,
+    request_class        => 'RT::Interface::Web::Request',
 ) };
 
 # {{{ sub new 
@@ -87,10 +89,7 @@
     my $class = shift;
     $class->InitSessionDir;
 
-    if ( $mod_perl::VERSION && $mod_perl::VERSION >= 1.9908 ) {
-        goto &NewApacheHandler;
-    }
-    elsif ($CGI::MOD_PERL) {
+    if ( ($mod_perl::VERSION && $mod_perl::VERSION >= 1.9908) || $CGI::MOD_PERL) {
         goto &NewApacheHandler;
     }
     else {
@@ -140,22 +139,6 @@
 
 # }}}
 
-# {{{ sub NewApache2Handler 
-
-=head2 NewApache2Handler
-
-  Takes extra options to pass to MasonX::Apache2Handler->new
-  Returns a new MasonX::Apache2Handler object
-
-=cut
-
-sub NewApache2Handler {
-    require MasonX::Apache2Handler;
-    return NewHandler('MasonX::Apache2Handler', args_method => "CGI", @_);
-}
-
-# }}}
-
 # {{{ sub NewCGIHandler 
 
 =head2 NewCGIHandler

Added: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Request.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Web/Request.pm	Sun Nov 26 17:44:42 2006
@@ -0,0 +1,100 @@
+package RT::Interface::Web::Request;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.30';
+use base qw(HTML::Mason::Request);
+
+sub new {
+    my $class = shift;
+
+    my $new_class = $HTML::Mason::ApacheHandler::VERSION ?
+        'HTML::Mason::Request::ApacheHandler' :
+            $HTML::Mason::CGIHandler::VERSION ?
+                'HTML::Mason::Request::CGI' :
+                    'HTML::Mason::Request';
+
+    $class->alter_superclass( $new_class );
+    $class->valid_params( %{ $new_class->valid_params } );
+    my $self = $class->SUPER::new(@_);
+    return if $self->is_subrequest;
+    return $self;
+}
+
+=head2 rt_callback
+
+Method replaces deprecated component C<Element/Callback>.
+
+Takes hash with optional C<CallbackPage>, C<CallbackName>
+and C<CallabckOnce> arguments, other arguments are passed
+throught to callback components.
+
+=over4
+
+=item CallbackPage
+
+Page path relative to the root, leading slash is mandatory.
+By default is equal to path of the caller component.
+
+=item CallbackName
+
+Name of the callback. C<Default> is used unless specified.
+
+=item CallbackOnce
+
+By default is false, otherwise runs callbacks only once per
+process of the server. Such callbacks can be used to fill
+structures.
+
+=back
+
+Searches for callback components in
+F<< /Callbacks/<any dir>/CallbackPage/CallbackName >>, for
+example F</Callbacks/MyExtension/autohandler/Default> would
+be called as default callback for F</autohandler>.
+
+=cut
+
+{
+my %cache = ();
+my %called = ();
+sub rt_callback {
+    my ($self, %args) = @_;
+
+    my $page = delete $args{'CallbackPage'} || $self->callers(0)->path;
+    my $name = delete $args{'CallbackName'} || 'Default';
+    my $once = delete $args{'CallbackOnce'};
+
+    my $CacheKey = "$page--$name";
+    my $callbacks = $cache{ $CacheKey };
+
+    return 1 if delete $args{'CallbackOnce'} && $called{ $CacheKey };
+    ++$called{ $CacheKey };
+
+    unless ( $callbacks ) {
+        my $path  = "/Callbacks/*$page/$name";
+        my @roots = map $_->[1],
+                        $HTML::Mason::VERSION <= 1.28
+                            ? $self->interp->resolver->comp_root_array
+                            : $self->interp->comp_root_array;
+
+        my %seen;
+        @$callbacks = sort map { 
+                # Skip backup files, files without a leading package name,
+                # and files we've already seen
+                grep      !$seen{$_}++ && !m'/.' && !/~$/
+                       && m{^/Callbacks/[^/]+\Q$page/$name\E$},
+                     $self->interp->resolver->glob_path($path, $_);
+            } @roots;
+
+        $cache{ $CacheKey } = $callbacks unless RT->Config->Get('DevelMode');
+    }
+
+    my @rv;
+    push @rv, scalar $self->comp( $_, %args) foreach @$callbacks;
+    return @rv;
+}
+}
+
+1;


More information about the Rt-commit mailing list