[Jifty-commit] r2970 - in Template-Declare: lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Mar 15 12:28:02 EDT 2007
Author: evdb
Date: Thu Mar 15 12:27:59 2007
New Revision: 2970
Modified:
Template-Declare/META.yml
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/private.t
Template-Declare/t/subclassing.t
Log:
Added carped warning when you try to 'show' a template that either does not exist or is private and so cannot be used.
Modified: Template-Declare/META.yml
==============================================================================
--- Template-Declare/META.yml (original)
+++ Template-Declare/META.yml Thu Mar 15 12:27:59 2007
@@ -4,7 +4,7 @@
HTML::Lint: 0
Test::More: 0
distribution_type: module
-generated_by: Module::Install version 0.64
+generated_by: Module::Install version 0.61
license: perl
name: Template-Declare
no_index:
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Thu Mar 15 12:27:59 2007
@@ -329,12 +329,19 @@
# if we're inside a template, we should show private templates
if ( caller()->isa('Template::Declare') ) { $INSIDE_TEMPLATE = 1; }
else { Template::Declare->new_buffer_frame }
+
my $callable =
ref($template) eq 'CODE'
? $template
: Template::Declare->has_template( $template, $INSIDE_TEMPLATE );
- return '' unless ($callable);
+ # If the template was not found let the user know.
+ unless ( $callable ) {
+ my $msg = "The template '$template' could not be found";
+ $msg .= " (it might be private)" if !$INSIDE_TEMPLATE;
+ carp $msg;
+ return '';
+ }
Template::Declare->new_buffer_frame;
&$callable($self);
Modified: Template-Declare/t/private.t
==============================================================================
--- Template-Declare/t/private.t (original)
+++ Template-Declare/t/private.t Thu Mar 15 12:27:59 2007
@@ -31,11 +31,17 @@
};
+template 'private_not_found' => sub {
+ show('does_not_exist');
+};
+
+
package main;
use Template::Declare::Tags;
Template::Declare->init(roots => ['Wifty::UI']);
-use Test::More tests => 7;
+use Test::More tests => 12;
+use Test::Warn;
require "t/utils.pl";
{
@@ -45,12 +51,29 @@
ok_lint($simple);
}
{
- my $simple = ( show('does_not_exist') );
+ my $simple;
+ warning_like
+ { $simple = ( show('does_not_exist') ); }
+ qr/could not be found.*private/,
+ "got warning";
+ unlike( $simple , qr'This is my content' );
+ ok_lint($simple);
+}
+{
+ my $simple;
+ warning_like
+ { $simple = ( show('private_not_found') ); }
+ qr/could not be found/,
+ "got warning";
unlike( $simple , qr'This is my content' );
ok_lint($simple);
}
{
- my $simple = ( show('private-content') );
+ my $simple;
+ warning_like
+ { $simple = ( show('private-content') ); }
+ qr/could not be found.*private/,
+ "got warning";
unlike( $simple , qr'This is my content', "Can't call private templates" );
ok_lint($simple);
}
Modified: Template-Declare/t/subclassing.t
==============================================================================
--- Template-Declare/t/subclassing.t (original)
+++ Template-Declare/t/subclassing.t Thu Mar 15 12:27:59 2007
@@ -51,7 +51,8 @@
use Template::Declare::Tags;
Template::Declare->init(roots => ['Baseclass::UI', 'Wifty::UI']);
-use Test::More tests => 9;
+use Test::More tests => 11;
+use Test::Warn;
require "t/utils.pl";
{
@@ -72,12 +73,21 @@
}
{
- my $simple = ( show('does_not_exist') );
+ my $simple;
+ warning_like
+ { $simple = ( show('does_not_exist') ); }
+ qr/could not be found.*private/,
+ "got warning";
unlike( $simple , qr'This is my content' );
ok_lint($simple);
}
+
{
- my $simple = ( show('private-content') );
+ my $simple;
+ warning_like
+ { $simple = ( show('private-content') ); }
+ qr/could not be found.*private/,
+ "got warning";
unlike( $simple , qr'This is my content', "Can't call private templates" );
ok_lint($simple);
}
More information about the Jifty-commit
mailing list