[Jifty-commit] r4912 - in jifty/trunk: lib/Jifty lib/Jifty/Mason
lib/Jifty/Plugin
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 23 15:32:43 EST 2008
Author: sartak
Date: Wed Jan 23 15:32:40 2008
New Revision: 4912
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Mason/Halo.pm
jifty/trunk/lib/Jifty/Plugin.pm
jifty/trunk/lib/Jifty/Plugin/Halo.pm
Log:
r50694 at onn: sartak | 2008-01-23 15:32:26 -0500
Some refactoring of Jifty::Mason::Halo. Now it too can support plugins munging the halo data. And its query logging is now off unless the SQLQueries plugin is used
Modified: jifty/trunk/lib/Jifty/Mason/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Mason/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Mason/Halo.pm Wed Jan 23 15:32:40 2008
@@ -2,8 +2,8 @@
use strict;
package Jifty::Mason::Halo;
use base qw/HTML::Mason::Plugin/;
-use Time::HiRes ();
-Jifty->handle->log_sql_statements(1);
+use Time::HiRes 'time';
+use Class::Trigger;
=head1 NAME
@@ -28,38 +28,35 @@
my $self = shift;
my $context = shift;
- return if ($context->comp->path && $context->comp->path eq "/__jifty/halo");
+ return if ($context->comp->path || '') eq "/__jifty/halo";
- Jifty->handler->stash->{ '_halo_index_stack' } ||= [];
-
- my $DEPTH = Jifty->handler->stash->{'_halo_depth'} || 0;
- my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
-
+ my $STACK = Jifty->handler->stash->{'_halo_stack'} ||= [];
+ my $DEPTH = ++Jifty->handler->stash->{'_halo_depth'};
+ my $ID = Jifty->web->serial;
my $INDEX_STACK = Jifty->handler->stash->{'_halo_index_stack'};
- my $halo_base = Jifty->web->serial;
-
- Jifty->handler->stash->{'_halo_depth'} = ++$DEPTH;
- if ($STACK->[-1]) {
- push @{$STACK->[-1]->{sql_statements}}, Jifty->handle->sql_statement_log;
- Jifty->handle->clear_sql_statement_log;
- }
-
- push @$STACK, {
- id => $halo_base,
+ my $frame = {
+ id => $ID,
args => [map { eval { defined $_ and fileno( $_ ) } ? "*GLOB*" : $_} @{$context->args}],
- start_time => Time::HiRes::time(),
+ start_time => time,
path => $context->comp->path || '',
- subcomponent => ( $context->comp->is_subcomp() ? 1:0),
- name => $context->comp->name || '(Unamed component)',
- proscribed => ($self->_unrendered_component($context) ? 1 :0 ),
- depth => $DEPTH
+ subcomponent => $context->comp->is_subcomp() ? 1 : 0,
+ name => $context->comp->name || '(Unnamed component)',
+ proscribed => $self->_unrendered_component($context) ? 1 : 0,
+ depth => $DEPTH,
};
- push @$INDEX_STACK, $#{$STACK};
+ my $previous = $STACK->[-1];
+ push @$STACK, $frame;
+
+
+ push @$INDEX_STACK, $#$STACK;
+
return if $self->_unrendered_component($context);
- $context->request->out(qq{<div id="halo-@{[$halo_base]}">});
+ $self->call_trigger('halo_pre_template', frame => $frame, previous => $previous);
+
+ $context->request->out(qq{<div id="halo-$ID" class="halo">});
}
=head2 end_component_hook CONTEXT_OBJECT
@@ -67,31 +64,27 @@
When we're done rendering a component, record how long it took
and close off the halo C<span> if we have one.
-
=cut
sub end_component_hook {
my $self = shift;
my $context = shift;
- return if ($context->comp->path && $context->comp->path =~ "^/__jifty/halo");
+ return if ($context->comp->path || '') eq "/__jifty/halo";
- my $STACK = Jifty->handler->stash->{'_halo_stack'};
+ 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_ID = pop @$INDEX_STACK;
+ my $FRAME_ID = pop @$INDEX_STACK;
my $frame = $STACK->[$FRAME_ID];
- $frame->{'render_time'} = int((Time::HiRes::time - $frame->{'start_time'}) * 1000)/1000;
+ $frame->{'render_time'} = int((time - $frame->{'start_time'}) * 1000)/1000;
- push @{$frame->{sql_statements}}, Jifty->handle->sql_statement_log;
- Jifty->handle->clear_sql_statement_log;
+ my $previous = $FRAME_ID ? $STACK->[$FRAME_ID - 1] : {};
+ $self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
- Jifty->handler->stash->{'_halo_depth'} = $DEPTH-1 ;
+ --Jifty->handler->stash->{'_halo_depth'};
- # If
return if $self->_unrendered_component($context);
# print out the div with our halo magic actions.
@@ -152,7 +145,7 @@
my @stack = @{ Jifty->handler->stash->{'_halo_stack'} };
for (@stack) {
- $_->{'render_time'} = int((Time::HiRes::time - $_->{'start_time'}) * 1000)/1000
+ $_->{'render_time'} = int((time - $_->{'start_time'}) * 1000)/1000
unless defined $_->{'render_time'};
}
Modified: jifty/trunk/lib/Jifty/Plugin.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin.pm Wed Jan 23 15:32:40 2008
@@ -65,13 +65,25 @@
# plugins are loaded, initialized, and prereq-examined in the order they're
# listed in the config files. Instead, each phase should be separate.
Jifty::Util->require("Jifty::Plugin::Halo");
- Jifty::Plugin::Halo->add_trigger(
- halo_pre_template => sub { $self->halo_pre_template(@_) },
- ) if $self->can('halo_pre_template');
-
- Jifty::Plugin::Halo->add_trigger(
- halo_post_template => sub { $self->halo_post_template(@_) },
- ) if $self->can('halo_post_template');
+ Jifty::Util->require("Jifty::Mason::Halo");
+
+ if ($self->can('halo_pre_template')) {
+ Jifty::Plugin::Halo->add_trigger(
+ halo_pre_template => sub { $self->halo_pre_template(@_) },
+ );
+ Jifty::Mason::Halo->add_trigger(
+ halo_pre_template => sub { $self->halo_pre_template(@_) },
+ );
+ }
+
+ if ($self->can('halo_post_template')) {
+ Jifty::Plugin::Halo->add_trigger(
+ halo_post_template => sub { $self->halo_post_template(@_) },
+ );
+ Jifty::Mason::Halo->add_trigger(
+ halo_post_template => sub { $self->halo_post_template(@_) },
+ );
+ }
return $self;
}
Modified: jifty/trunk/lib/Jifty/Plugin/Halo.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Halo.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Halo.pm Wed Jan 23 15:32:40 2008
@@ -3,6 +3,7 @@
package Jifty::Plugin::Halo;
use base qw/Jifty::Plugin/;
+use Time::HiRes 'time';
use Class::Trigger;
=head1 NAME
@@ -50,7 +51,7 @@
my $frame = {
id => $ID,
args => [ %{ Jifty->web->request->arguments } ], # ugh :)
- start_time => Time::HiRes::time(),
+ start_time => time,
path => $path,
subcomponent => 0,
name => $name,
@@ -70,6 +71,9 @@
$orig->();
Jifty->web->out(qq{</div>});
+ $frame->{'render_time'} = int((time - $frame->{'start_time'}) * 1000)/1000
+ unless defined $frame->{'render_time'};
+
$self->call_trigger('halo_post_template', frame => $frame, previous => $previous);
--Jifty->handler->stash->{'_halo_depth'};
More information about the Jifty-commit
mailing list