[Jifty-commit] r4915 - in Template-Declare: lib/Template
lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 23 19:48:30 EST 2008
Author: sartak
Date: Wed Jan 23 19:48:30 2008
New Revision: 4915
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare.pm
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/instrumentation.t
Log:
r50700 at onn: sartak | 2008-01-23 19:48:19 -0500
Add another argument to around_template: the coderef of the template itself
Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm (original)
+++ Template-Declare/lib/Template/Declare.pm Wed Jan 23 19:48:30 2008
@@ -290,11 +290,11 @@
A coderef called B<instead> of rendering each template. The coderef will
receive three arguments: a coderef to invoke to render the template, the
-template's path, and a reference to the arguments to the template. You can use
-this for instrumentation. For example:
+template's path, an arrayref of the arguments to the template, and the coderef
+of the template itself. You can use this for instrumentation. For example:
Template::Declare->init(around_template => sub {
- my ($orig, $path, $args) = @_;
+ my ($orig, $path, $args, $code) = @_;
my $start = time;
$orig->();
warn "Rendering $path took " . (time - $start) . " seconds.";
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Wed Jan 23 19:48:30 2008
@@ -764,6 +764,7 @@
sub { &$callable($self, @$args) },
$template,
$args,
+ $callable,
);
}
else {
Modified: Template-Declare/t/instrumentation.t
==============================================================================
--- Template-Declare/t/instrumentation.t (original)
+++ Template-Declare/t/instrumentation.t Wed Jan 23 19:48:30 2008
@@ -31,7 +31,7 @@
package main;
use strict;
use warnings;
-use Test::More tests => 25;
+use Test::More tests => 32;
use Template::Declare;
my @args;
@@ -46,8 +46,9 @@
is(@args, 1, "one template called");
is(ref($args[0][0]), 'CODE', "first argument is \$orig");
-is($args[0][1], 'inner', "first argument is template path");
-is_deeply($args[0][2], ['inside'], "second argument is the list of arguments");
+is($args[0][1], 'inner', "second argument is template path");
+is_deeply($args[0][2], ['inside'], "third argument is the list of arguments");
+is(ref($args[0][3]), 'CODE', "fourth argument is template coderef");
@args = ();
$out = Template::Declare->show('outer', 'xyzzy');
@@ -60,6 +61,8 @@
is($args[1][1], 'inner', "nested templates)");
is_deeply($args[0][2], ['xyzzy'], "nested templates");
is_deeply($args[1][2], ['XYZZY'], "nested templates");
+is(ref($args[0][3]), 'CODE', "fourth argument is template coderef");
+is(ref($args[1][3]), 'CODE', "fourth argument is template coderef");
@args = ();
$out = Template::Declare->show('add', '32', '56');
@@ -67,8 +70,9 @@
is(@args, 1, "one template called");
is(ref($args[0][0]), 'CODE', "first argument is \$orig");
-is($args[0][1], 'add', "first argument is template path");
-is_deeply($args[0][2], [32, 56], "second argument is the list of arguments");
+is($args[0][1], 'add', "second argument is template path");
+is_deeply($args[0][2], [32, 56], "third argument is the list of arguments");
+is(ref($args[0][3]), 'CODE', "fourth argument is template coderef");
@args = ();
$out = Template::Declare->show('host');
@@ -76,9 +80,12 @@
is(@args, 2, "one template called");
is(ref($args[0][0]), 'CODE', "first argument is \$orig");
-is($args[0][1], 'host', "first argument is template path");
-is($args[1][1], 'add', "first argument is template path");
-is_deeply($args[0][2], [], "second argument is the list of arguments");
-is_deeply($args[1][2], [3, 7], "second argument is the list of arguments");
+is(ref($args[1][0]), 'CODE', "first argument is \$orig");
+is($args[0][1], 'host', "second argument is template path");
+is($args[1][1], 'add', "second argument is template path");
+is_deeply($args[0][2], [], "third argument is the list of arguments");
+is_deeply($args[1][2], [3, 7], "third argument is the list of arguments");
+is(ref($args[0][3]), 'CODE', "fourth argument is template coderef");
+is(ref($args[1][3]), 'CODE', "fourth argument is template coderef");
@args = ();
More information about the Jifty-commit
mailing list