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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jan 22 17:58:50 EST 2008


Author: sartak
Date: Tue Jan 22 17:58:50 2008
New Revision: 4905

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

Log:
 r50681 at onn:  sartak | 2008-01-22 17:58:12 -0500
 Template::Declare halos! (you'll need a bleeding edge TD though)


Modified: jifty/trunk/lib/Jifty/Plugin/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Halo.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Halo.pm	Tue Jan 22 17:58:50 2008
@@ -4,10 +4,6 @@
 package Jifty::Plugin::Halo;
 use base qw/Jifty::Plugin/;
 
-# Your plugin goes here.  If takes any configuration or arguments, you
-# probably want to override L<Jifty::Plugin/init>.
-
-
 =head1 NAME
 
 Jifty::Plugin::Halo
@@ -20,5 +16,68 @@
 
 =cut
 
+sub init {
+    my $self = shift;
+
+    # 0.28 added around_template instrumentation
+    eval { Template::Declare->VERSION('0.28'); 1 }
+        or do {
+            Jifty->log->debug("Template::Declare 0.28 required for TD halos.");
+            return;
+        };
+
+    warn "Overwriting an existing Template::Declare->around_template"
+        if Template::Declare->around_template;
+
+    Template::Declare->around_template(sub { $self->around_template(@_) });
+
+}
+
+sub post_init {
+    Jifty->handle->log_sql_statements(1);
+}
+
+# parts of why this is.. weird is because we want to play nicely with Mason
+# halos
+sub around_template {
+    my ($self, $orig, $path, $args) = @_;
+
+    my $STACK       = Jifty->handler->stash->{'_halo_stack'} ||= [];
+    my $DEPTH       = ++Jifty->handler->stash->{'_halo_depth'};
+    my $ID          = Jifty->web->serial;
+
+    # if we have queries at this point, they belong to the previous template
+    if (@$STACK) {
+        push @{$STACK->[-1]->{sql_statements}}, Jifty->handle->sql_statement_log;
+        Jifty->handle->clear_sql_statement_log;
+    }
+
+    # for now, call the last piece of the template's path the name
+    $path =~ m{.*/(.+)};
+    my $name = $1 || $path;
+
+    my $frame = {
+        id           => $ID,
+        args         => [ %{ Jifty->web->request->arguments } ], # ugh :)
+        start_time   => Time::HiRes::time(),
+        path         => $path,
+        subcomponent => 0,
+        name         => $name,
+        proscribed   => 0,
+        depth        => $DEPTH,
+    };
+
+    push @$STACK, $frame;
+    my $STACK_INDEX = $#$STACK;
+
+    Jifty->web->out(qq{<div id="halo-$ID">});
+    $orig->();
+    Jifty->web->out(qq{</div>});
+
+    push @{$frame->{sql_statements}}, Jifty->handle->sql_statement_log;
+    Jifty->handle->clear_sql_statement_log;
+
+    --Jifty->handler->stash->{'_halo_depth'};
+}
 
 1;


More information about the Jifty-commit mailing list