[Jifty-commit] r4972 - in jifty/trunk: lib/Jifty/Mason lib/Jifty/Plugin

Jifty commits jifty-commit at lists.jifty.org
Fri Feb 1 13:16:35 EST 2008


Author: sartak
Date: Fri Feb  1 13:16:01 2008
New Revision: 4972

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Mason/Halo.pm
   jifty/trunk/lib/Jifty/Plugin/Halo.pm

Log:
 r51318 at onn:  sartak | 2008-02-01 13:15:27 -0500
 Remove a bunch of code duplication between Jifty::{Mason,Plugin}::Halo


Modified: jifty/trunk/lib/Jifty/Mason/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Mason/Halo.pm	(original)
+++ jifty/trunk/lib/Jifty/Mason/Halo.pm	Fri Feb  1 13:16:01 2008
@@ -31,27 +31,16 @@
 
     return if ($context->comp->path || '') eq "/__jifty/halo";
 
-    my $STACK       = Jifty->handler->stash->{'_halo_stack'} ||= [];
-    my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'} ||= [];
-    my $DEPTH       = ++Jifty->handler->stash->{'_halo_depth'};
-
-    my $frame = Jifty::Plugin::Halo->new_frame(
+    my $frame = Jifty::Plugin::Halo->push_frame(
         args         => [map { eval { defined $_ and fileno( $_ ) }  ? "*GLOB*" : $_} @{$context->args}],
         path         => $context->comp->path || '',
         subcomponent => $context->comp->is_subcomp() ? 1 : 0,
         name         => $context->comp->name || '(Unnamed component)',
         proscribed   => $self->_unrendered_component($context) ? 1 : 0,
-        depth        => $DEPTH,
     );
 
-    my $previous = $STACK->[-1];
-    push @$STACK, $frame;
-    push @$INDEX_STACK, $#$STACK;
-
     return if $self->_unrendered_component($context);
 
-    $self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
-
     $context->request->out(Jifty::Plugin::Halo->halo_header($frame));
 }
 
@@ -68,18 +57,7 @@
 
     return if ($context->comp->path || '') eq "/__jifty/halo";
 
-    my $STACK       = Jifty->handler->stash->{'_halo_stack'};
-    my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'};
-    my $FRAME_ID    = pop @$INDEX_STACK;
-
-    my $frame = $STACK->[$FRAME_ID];
-    $frame->{'end_time'} = time;
-
-    my $previous = $FRAME_ID ? $STACK->[$FRAME_ID - 1] : {};
-
-    $self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
-
-    --Jifty->handler->stash->{'_halo_depth'};
+    my $frame = Jifty::Plugin::Halo->pop_frame;
 
     return if $self->_unrendered_component($context);
 

Modified: jifty/trunk/lib/Jifty/Plugin/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Halo.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Halo.pm	Fri Feb  1 13:16:01 2008
@@ -42,9 +42,6 @@
 sub around_template {
     my ($self, $orig, $path, $args, $code) = @_;
 
-    my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
-    my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
-
     # for now, call the last piece of the template's path the name
     $path =~ m{.*/(.+)};
     my $name = $1 || $path;
@@ -54,31 +51,18 @@
         Data::Dump::Streamer::Dump($code)->Out;
     };
 
-    my $frame = $self->new_frame(
+    my $frame = $self->push_frame(
         args  => [ %{ Jifty->web->request->arguments } ], # ugh :)
         path  => $path,
         name  => $name,
-        depth => $DEPTH,
         perl  => $deparsed,
     );
 
-    # if this is the first frame, discard anything from the previous queries
-    my $previous = $STACK->[-1] || {};
-
-    push @$STACK, $frame;
-    my $STACK_INDEX = $#$STACK;
-
-    $self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
-
     Template::Declare->buffer->append($self->halo_header($frame));
     $orig->();
-    Template::Declare->buffer->append($self->halo_footer($frame));
-
-    $frame->{'end_time'} = time;
-
-    $self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
 
-    --Jifty->handler->stash->{'_halo_depth'};
+    $frame = $self->pop_frame;
+    Template::Declare->buffer->append($self->halo_footer($frame));
 }
 
 sub halo_header {
@@ -158,4 +142,43 @@
     };
 }
 
+sub push_frame {
+    my $self = shift;
+
+    my $STACK       = Jifty->handler->stash->{'_halo_stack'} ||= [];
+    my $DEPTH       = ++Jifty->handler->stash->{'_halo_depth'};
+    my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'} ||= [];
+
+    # if this is the first frame, discard anything from the previous queries
+    my $previous = $STACK->[-1] || {};
+
+    my $frame = $self->new_frame(@_, previous => $previous, depth => $DEPTH);
+
+    push @$STACK, $frame;
+    push @$INDEX_STACK, $#$STACK;
+
+    $self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
+
+    return $frame;
+}
+
+sub pop_frame {
+    my $self = shift;
+
+    my $STACK       = Jifty->handler->stash->{'_halo_stack'} ||= [];
+    my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'} ||= [];
+    my $FRAME_ID    = pop @$INDEX_STACK;
+
+    my $frame = $STACK->[$FRAME_ID];
+    my $previous = $frame->{previous};
+
+    $frame->{'end_time'} = time;
+
+    $self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
+
+    --Jifty->handler->stash->{'_halo_depth'};
+
+    return $frame;
+}
+
 1;


More information about the Jifty-commit mailing list