[Bps-public-commit] template-declare branch, master, updated. c1d4d2427674c6a34171009374cb80c4906d3f08

sartak at bestpractical.com sartak at bestpractical.com
Sun Nov 1 15:49:44 EST 2009


The branch, master has been updated
       via  c1d4d2427674c6a34171009374cb80c4906d3f08 (commit)
       via  b015b8af57a88e079a5985b96f4e6aac67d4cf50 (commit)
      from  e3dea85ccbeee22f239bb50462c4b4ff80f132db (commit)

Summary of changes:
 Changes                        |    4 +++
 lib/Template/Declare.pm        |   27 ++++++++++--------
 lib/Template/Declare/TagSet.pm |    2 +-
 lib/Template/Declare/Tags.pm   |    6 +++-
 t/strict.t                     |   58 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 15 deletions(-)
 create mode 100644 t/strict.t

- Log -----------------------------------------------------------------
commit b015b8af57a88e079a5985b96f4e6aac67d4cf50
Author: David E. Wheeler <david at justatheory.com>
Date:   Sat Oct 31 12:26:03 2009 -0700

    Add "strict" attribute
    
    Its make exceptional situations fatal. False by default, but consider changing in the future.

diff --git a/Changes b/Changes
index a499c38..38c356d 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.42
+* Added the "strict" attribute to make exceptional situations fatal.
+
 0.41 2009-10-29
 * Documentation tweaks (Theory)
 
diff --git a/lib/Template/Declare.pm b/lib/Template/Declare.pm
index 94fd252..07a69c9 100644
--- a/lib/Template/Declare.pm
+++ b/lib/Template/Declare.pm
@@ -12,6 +12,7 @@ our $VERSION = '0.41';
 use base 'Class::Data::Inheritable';
 __PACKAGE__->mk_classdata('dispatch_to');
 __PACKAGE__->mk_classdata('postprocessor');
+__PACKAGE__->mk_classdata('strict');
 __PACKAGE__->mk_classdata('templates');
 __PACKAGE__->mk_classdata('private_templates');
 __PACKAGE__->mk_classdata('buffer');
@@ -473,6 +474,7 @@ Now let's have a look at how we use these templates with a post-processor:
     Template::Declare->init(
         dispatch_to   => ['MyApp::Templates'],
         postprocessor => \&emphasize,
+        strict        => 1,
     );
 
     print Template::Declare->show( 'before' );
@@ -1056,6 +1058,12 @@ of the template itself. You can use this for instrumentation. For example:
         warn "Rendering $path took " . (time - $start) . " seconds.";
     });
 
+=item strict
+
+Die in exceptional situations, such as when a template can't be found, rather
+than just warn. False by default for backward compatibility. The default may
+be changed in the future, so specifying the value explicitly is recommended.
+
 =back
 
 =cut
@@ -1064,20 +1072,15 @@ sub init {
     my $class = shift;
     my %args  = (@_);
 
-    if ( $args{'dispatch_to'} ) {
-        $class->dispatch_to( $args{'dispatch_to'} );
-    } elsif ( $args{'roots'} ) {
-        $class->roots( $args{'roots'} );
-    }
-
-    if ( $args{'postprocessor'} ) {
-        $class->postprocessor( $args{'postprocessor'} );
-    }
-
-    if ( $args{'around_template'} ) {
-        $class->around_template( $args{'around_template'} );
+    if ( $args{dispatch_to} ) {
+        $class->dispatch_to( $args{dispatch_to} );
+    } elsif ( $args{roots} ) {
+        $class->roots( $args{roots} );
     }
 
+    $class->strict( $args{strict} ) if exists $args{strict};
+    $class->postprocessor( $args{postprocessor} ) if $args{postprocessor};
+    $class->around_template( $args{around_template} ) if $args{around_template};
 }
 
 =head2 show TEMPLATE_NAME
diff --git a/lib/Template/Declare/Tags.pm b/lib/Template/Declare/Tags.pm
index 9304049..dfbb228 100644
--- a/lib/Template/Declare/Tags.pm
+++ b/lib/Template/Declare/Tags.pm
@@ -465,8 +465,9 @@ sub with (@) {
 
         if ( lc($key) eq 'id' ) {
             if ( $ELEMENT_ID_CACHE{$val}++ ) {
-                warn
-                    "HTML appears to contain illegal duplicate element id: $val";
+                my $msg = "HTML appears to contain illegal duplicate element id: $val";
+                die $msg if Template::Declare->strict;
+                warn $msg;
             }
         }
 
@@ -866,6 +867,7 @@ sub _show_template {
     unless ($callable) {
         my $msg = "The template '$template' could not be found";
         $msg .= " (it might be private)" if !$inside_template;
+        croak $msg if Template::Declare->strict;
         carp $msg;
         return '';
     }
diff --git a/t/strict.t b/t/strict.t
new file mode 100644
index 0000000..7283db7
--- /dev/null
+++ b/t/strict.t
@@ -0,0 +1,58 @@
+use warnings;
+use strict;
+
+package Wifty::UI;
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template oops => sub {
+    with( id => 'foo', id => 'foo' ), html {
+    };
+};
+
+package main;
+
+use Test::More tests => 11;
+use Test::Warn;
+
+##############################################################################
+Template::Declare->init(dispatch_to => ['Wifty::UI']);
+pass 'Init with no strict setting';
+
+warning_like { Template::Declare->show('nonesuch' ) }
+    qr/The template 'nonesuch' could not be found [(]it might be private[)]/,
+    'Should get warning for nonexistent template';
+
+warning_like { Template::Declare->show('oops' ) }
+    qr/HTML appears to contain illegal duplicate element id: foo/,
+    'Should get warning for duplicate "id" attribute';
+
+##############################################################################
+Template::Declare->init(dispatch_to => ['Wifty::UI'], strict => 0);
+pass 'Init with strict off';
+
+warning_like { Template::Declare->show('nonesuch' ) }
+    qr/The template 'nonesuch' could not be found [(]it might be private[)]/,
+    'Should still get warning for nonexistent template';
+
+warning_like { Template::Declare->show('oops' ) }
+    qr/HTML appears to contain illegal duplicate element id: foo/,
+    'Should still get warning for duplicate "id" attribute';
+
+##############################################################################
+Template::Declare->init(dispatch_to => ['Wifty::UI'], strict => 1);
+pass 'Init with strict on';
+
+undef $@;
+eval { Template::Declare->show('nonesuch' ) };
+ok my $err = $@, 'Should get exception for missing template';
+like $err,
+    qr/The template 'nonesuch' could not be found [(]it might be private[)]/,
+    '... and it should be about nonexistent template';
+
+undef $@;
+eval { Template::Declare->show('oops' ) };
+ok my $err = $@, 'Should get exception for duplicate "id"';
+like $err,
+    qr/HTML appears to contain illegal duplicate element id: foo/,
+    '... and it should be about the duplicate "id" attribute';

commit c1d4d2427674c6a34171009374cb80c4906d3f08
Author: David E. Wheeler <david at justatheory.com>
Date:   Sun Nov 1 12:46:38 2009 -0800

    Removed unused "implementor" attribute
    
    From Template::Declare::TagSet.

diff --git a/Changes b/Changes
index 38c356d..1fd5ef9 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 0.42
 * Added the "strict" attribute to make exceptional situations fatal.
+* Removed unused "implementor" attribute in Template::Declare::TagSet.
 
 0.41 2009-10-29
 * Documentation tweaks (Theory)
diff --git a/lib/Template/Declare/TagSet.pm b/lib/Template/Declare/TagSet.pm
index 82fb5b9..6d21d61 100644
--- a/lib/Template/Declare/TagSet.pm
+++ b/lib/Template/Declare/TagSet.pm
@@ -5,7 +5,7 @@ use warnings;
 use base qw(Class::Accessor::Fast);
 
 __PACKAGE__->mk_ro_accessors(
-    qw{ namespace package implementor }
+    qw{ namespace package }
 );
 
 sub get_alternate_spelling {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list