[Jifty-commit] r3896 - in Template-Declare: lib/Template/Declare t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Aug 14 02:18:59 EDT 2007


Author: agentz
Date: Tue Aug 14 02:18:58 2007
New Revision: 3896

Modified:
   Template-Declare/lib/Template/Declare.pm
   Template-Declare/lib/Template/Declare/Tags.pm
   Template-Declare/t/pitfalls.t

Log:
[TD]
* made the _install interface more intuitive.
* improved the POD a bit more.
* added a test to t/pitfallls.t.

Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Tue Aug 14 02:18:58 2007
@@ -269,13 +269,13 @@
 
 =head2 PITFALLS
 
-We're reusing the perl interpreter for our templating langauge, but Perl was not designed perfectly for our purpose here. Here are some known pitfalls while you're scripting your templates with this module.
+We're reusing the perl interpreter for our templating langauge, but Perl was not designed specifically for our purpose here. Here are some known pitfalls while you're scripting your templates with this module.
 
 =over
 
 =item *
 
-It's quite common to see tag sub calling statements without trailing semi-colons right after C<}> in code that uses this module. For example,
+It's quite common to see tag sub calling statements without trailing semi-colons right after C<}>. For instance,
 
     template foo => {
         p {
@@ -295,22 +295,22 @@
         };
     };
 
-But C<xml_decl> is a notable exception. Please always put a trailing semicolon after C<xml_decl { ... }>, or the outputs will be messed up.
+But C<xml_decl> is a notable exception. Please always put a trailing semicolon after C<xml_decl { ... }>, or you'll mess up the outputs.
 
 =item *
 
-Another place that requires trailing semicolon is the statements before a Perl looping and branching statements, for example:
+Another place that requires trailing semicolon is the statements before a Perl looping or branching statement, for example:
 
     p { "My links:" };
     for (@links) {
         with( src => $_ ), a {}
     }
 
-the C<;> after C< p { ... } > is required here, or Perl will croak for syntax errors.
+The C<;> after C< p { ... } > is required here, or Perl will complaint about syntax errors.
 
 =item *
 
-Literal strings that are not in the last statement in a code block won't be captured. So the following template
+Literal strings that have tag siblings won't be captured. So the following template
 
     p { 'hello'; em { 'world' } }
 
@@ -331,6 +331,10 @@
 
     p { outs 'hello'; em { 'world' } }
 
+Note you can always get rid of the C<outs> crap if the string literal is the only element of the containing block:
+
+   p { 'hello, world!' }
+
 =back
 
 =cut

Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Tue Aug 14 02:18:58 2007
@@ -62,13 +62,13 @@
 }
 
 sub _install {
-    my ($no_override, $package, $subname, $coderef) = @_;
+    my ($override, $package, $subname, $coderef) = @_;
 
     ###### Installing sub: $subname
 
     my $name = $package . '::' . $subname;
     my $slot = qualify_to_ref($name);
-    return if $no_override and *$slot{CODE};
+    return if !$override and *$slot{CODE};
 
     no warnings 'redefine';
     *$slot = $coderef;
@@ -397,9 +397,9 @@
 }
 
 
-=head2 install_tag TAGNAME
+=head2 install_tag TAGNAME, TAGSET
 
-Sets up TAGNAME as a tag that can be used in user templates.
+Sets up TAGNAME as a tag that can be used in user templates. TAGSET is an instance of a subclass for L<Template::Declare::TagSet>.
 
 =cut
 
@@ -408,15 +408,11 @@
     my $name = $tag;
     my $tagset = $_[1];
 
-    # XXX We treat the 'link' tag specially...
-    # Yeah, maybe we should do it for all the perl builtins...
-    # I know this is hacky...
-
     ### caller: (caller(0))[0]
     my $alternative = $tagset->get_alternate_spelling($tag);
     if ( defined $alternative ) {
         _install(
-            1, # do not override
+            0, # do not override
             scalar(caller), $tag,
             sub (&) {
                 die "$tag {...} is invalid; use $alternative {...} instead.\n";
@@ -461,7 +457,7 @@
     ##### package: $tagset->package
     ##### sub name: $name
     _install(
-        0, # do override the existing sub with the same name
+        1, # do override the existing sub with the same name
         $tagset->package => $name => $code
     );
 }

Modified: Template-Declare/t/pitfalls.t
==============================================================================
--- Template-Declare/t/pitfalls.t	(original)
+++ Template-Declare/t/pitfalls.t	Tue Aug 14 02:18:58 2007
@@ -29,6 +29,7 @@
 
 template inline => sub {
     html::p { "hello, "; html::em { "world" } }
+    html::p { html::em { 'hello' }; 'world' }
 };
 
 eval q{
@@ -65,5 +66,8 @@
 <html:p>
  <html:em>world</html:em>
 </html:p>
+<html:p>
+ <html:em>hello</html:em>
+</html:p>
 _EOC_
 


More information about the Jifty-commit mailing list