[Jifty-commit] r769 - in jifty/trunk: lib/Jifty lib/Jifty/Mason t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Mar 30 01:38:19 EST 2006


Author: jesse
Date: Thu Mar 30 01:38:17 2006
New Revision: 769

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/Mason/Halo.pm
   jifty/trunk/lib/Jifty/Web.pm
   jifty/trunk/t/01-dependencies.t

Log:
 r10545 at hualien:  jesse | 2006-03-30 15:37:09 +0900
 * test for indented requirements


Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Thu Mar 30 01:38:17 2006
@@ -409,13 +409,14 @@
 
 
     local $Dispatcher = $self->new();
+
+    # XXX TODO: refactor this out somehow?
     # We don't want the previous mason request hanging aroudn once we start dispatching
     local $HTML::Mason::Commands::m = undef;
     # Mason introduces a DIE handler that generates a mason exception
     # which in turn generates a backtrace. That's fine when you only
     # do it once per request. But it's really, really painful when you do it
     # often, as is the case with fragments
-    #
     local $SIG{__DIE__} = 'DEFAULT';
 
     eval {
@@ -672,14 +673,14 @@
     $path ||= $self->{path};
     $self->log->debug("Showing path $path");
 
-    # If we've got a working directory (from an "under" rule) and we have 
+    # If we've got a working directory (from an "under" rule) and we have
     # a relative path, prepend the working directory
     $path = "$self->{cwd}/$path" unless $path =~ m{^/};
 
-    # If we're requesting a directory, go looking for the index.html
-    if ( $path =~ m{/$} and
-        Jifty->handler->mason->interp->comp_exists( $path . "/index.html" ) )
+    # When we're requesting a directory, go looking for the index.html
+    if ( $path =~ m{/$} and $self->template_exists( $path . "/index.html" ) )
     {
+
         $path .= "/index.html";
     }
 
@@ -687,40 +688,18 @@
     # the directory itself
 
     # XXX TODO, we should search all component roots
-    
+
     if ($path !~ m{/$}
-        and -d Jifty::Util->absolute_path(
-            Jifty->config->framework('Web')->{'TemplateRoot'} . $path
-        )
-        )
+        and -d Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} . $path))
     {
-
         $self->_do_show( $path . "/" );
     }
 
     # Set the request path
     request->path($path);
+    $self->render_template(request->path);
 
-    $self->log->debug("Having Mason handle ".request->path);
-    eval { Jifty->handler->mason->handle_comp(request->path); };
-    my $err = $@;
-    # Handle parse errors
-    if ( $err and not eval { $err->isa( 'HTML::Mason::Exception::Abort' ) } ) {
-        # Save the request away, and redirect to an error page
-        Jifty->web->response->error($err);
-        my $c = Jifty::Continuation->new(
-            request  => Jifty->web->request,
-            response => Jifty->web->response,
-            parent   => Jifty->web->request->continuation,
-        );
-
-        warn "$err";
 
-        # Redirect with a continuation
-        Jifty->web->_redirect( "/__jifty/error/mason_internal_error?J:C=" . $c->id );
-    } elsif ($err) {
-        die $err;
-    }
     last_rule;
 }
 
@@ -933,6 +912,58 @@
     $glob;
 }
 
+=head2 template_exists PATH
+
+Returns true if PATH is a valid template inside your template root.
+
+=cut
+
+sub template_exists {
+    my $self = shift;
+    my $template = shift;
+
+      return  Jifty->handler->mason->interp->comp_exists( $template);
+
+}
+
+
+=head2 render_template PATH
+
+Use our templating system to render a template. If there's an error, do the right thing.
+
+
+=cut
+
+sub render_template {
+    my $self = shift;
+    my $template = shift;
+
+    $self->log->debug( "Handling template " . $template );
+    eval { Jifty->handler->mason->handle_comp( $template ); };
+    my $err = $@;
+
+    # Handle parse errors
+    if ( $err and not eval { $err->isa('HTML::Mason::Exception::Abort') } ) {
+
+        # Save the request away, and redirect to an error page
+        Jifty->web->response->error($err);
+        my $c = Jifty::Continuation->new(
+            request  => Jifty->web->request,
+            response => Jifty->web->response,
+            parent   => Jifty->web->request->continuation,
+        );
+
+        warn "$err";
+
+        # Redirect with a continuation
+        Jifty->web->_redirect(
+            "/__jifty/error/mason_internal_error?J:C=" . $c->id );
+    }
+    elsif ($err) {
+        die $err;
+    }
+
+}
 
 
 1;

Modified: jifty/trunk/lib/Jifty/Mason/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Mason/Halo.pm	(original)
+++ jifty/trunk/lib/Jifty/Mason/Halo.pm	Thu Mar 30 01:38:17 2006
@@ -3,6 +3,7 @@
 package Jifty::Mason::Halo;
 use base qw/HTML::Mason::Plugin/;
 use Time::HiRes ();
+use YAML ();
 Jifty->handle->log_sql_statements(1);
 
 =head1 NAME

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Thu Mar 30 01:38:17 2006
@@ -122,7 +122,6 @@
 # Create the Jifty::Web::Session object
 sub setup_session {
     my $self = shift;
-    my $m = Jifty->web->mason;
 
     return if $self->session->loaded;
     $self->session->load();
@@ -893,24 +892,6 @@
     return '';
 }
 
-=head3 render_request_debug_info
-
-Outputs the request arguments.
-
-=cut
-
-sub render_request_debug_info {
-    my $self = shift;
-    my $m    = $self->mason;
-    use YAML;
-    $m->out('<div class="debug">');
-    $m->out('<hr /><h1>Request args</h1><pre>');
-    $m->out( YAML::Dump( { $m->request_args } ) );
-    $m->out('</pre></div>');
-
-    return '';
-}
-
 =head3 query_string KEY => VALUE [, KEY => VALUE [, ...]]
 
 Returns an URL-encoded query string piece representing the arguments

Modified: jifty/trunk/t/01-dependencies.t
==============================================================================
--- jifty/trunk/t/01-dependencies.t	(original)
+++ jifty/trunk/t/01-dependencies.t	Thu Mar 30 01:38:17 2006
@@ -36,7 +36,7 @@
     ok(open(MAKEFILE,"Makefile.PL"), "Opened Makefile");
     my $data = <MAKEFILE>;
     close(FILE);
-    while ($data =~ /^requires\('([\w:]+)'.*?(?:#(.*))?$/gm) {
+    while ($data =~ /^\s*?requires\('([\w:]+)'.*?(?:#(.*))?$/gm) {
         $required{$1}++;
         if (defined $2 and length $2) {
             $required{$_}++ for split ' ', $2;


More information about the Jifty-commit mailing list