[Jifty-commit] r3956 - in Template-Declare: lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Aug 24 01:22:37 EDT 2007
Author: agentz
Date: Fri Aug 24 01:22:30 2007
New Revision: 3956
Added:
Template-Declare/t/tag_sub_list.t
Modified:
Template-Declare/MANIFEST
Template-Declare/lib/Template/Declare/Tags.pm
Log:
TD - renamed @Template::Declare::TagSubs to @Template::Declare::TAG_SUB_LIST to be more consistent in naming. @TagSubs is now aliased to @TAG_SUB_LIST for backward-compatibility reasons :) (jifty trunk needs updates)
Modified: Template-Declare/MANIFEST
==============================================================================
--- Template-Declare/MANIFEST (original)
+++ Template-Declare/MANIFEST Fri Aug 24 01:22:30 2007
@@ -44,6 +44,7 @@
t/smart_tag_wrapper.t
t/subclassing.t
t/subtemplates.t
+t/tag_sub_list.t
t/tagset_html.t
t/tagset_mix.t
t/tagset_xul.t
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Fri Aug 24 01:22:30 2007
@@ -1,7 +1,7 @@
use 5.006;
use warnings;
use strict;
-#use Smart::Comments '####';
+#use Smart::Comments;
#use Smart::Comments '#####';
package Template::Declare::Tags;
@@ -9,7 +9,7 @@
our $VERSION = '0.26';
use Template::Declare;
-use vars qw( @EXPORT_OK $PRIVATE $self );
+use vars qw( @EXPORT_OK $PRIVATE $self @TagSubs );
use base 'Exporter';
use Carp qw(carp croak);
use Symbol 'qualify_to_ref';
@@ -19,7 +19,8 @@
outs_raw in_isolation $self under
get_current_attr xml_decl
smart_tag_wrapper current_template );
-our @TagSubs;
+our @TAG_SUB_LIST;
+*TagSubs = \@TAG_SUB_LIST; # For backward compatibility only
our %ATTRIBUTES = ();
our %ELEMENT_ID_CACHE = ();
@@ -29,32 +30,39 @@
our $SKIP_XML_ESCAPING = 0;
sub import {
- ### caller: caller(0)
- ### @_
my $self = shift;
my @set_modules;
if (!@_) {
push @_, 'HTML';
}
- @TagSubs = ();
+ ### @_
+ ### caller: caller()
+
+ # XXX We can't reset @TAG_SUB_LIST here since
+ # use statements always run at BEGIN time.
+ # A better approach may be install such lists
+ # directly into the caller's namespace...
+ #undef @TAG_SUB_LIST;
+
while (@_) {
my $lang = shift;
my $opts;
if (ref $_[0] and ref $_[0] eq 'HASH') {
$opts = shift;
$opts->{package} ||= $opts->{namespace};
- ### XXX TODO: carp if the derived package already exists?
+ # XXX TODO: carp if the derived package already exists?
}
$opts->{package} ||= scalar(caller);
my $module = $opts->{from} ||
"Template::Declare::TagSet::$lang";
+ ### Loading tag set: $module
eval "use $module";
if ($@) {
warn $@;
croak "Failed to load tagset module $module";
}
- ##### TagSet options: $opts
+ ### TagSet options: $opts
my $tagset = $module->new($opts);
my $tag_list = $tagset->get_tag_list;
Template::Declare::Tags::install_tag($_, $tagset)
@@ -66,8 +74,6 @@
sub _install {
my ($override, $package, $subname, $coderef) = @_;
- ###### Installing sub: $subname
-
my $name = $package . '::' . $subname;
my $slot = qualify_to_ref($name);
return if !$override and *$slot{CODE};
@@ -410,7 +416,6 @@
my $name = $tag;
my $tagset = $_[1];
- ### caller: (caller(0))[0]
my $alternative = $tagset->get_alternate_spelling($tag);
if ( defined $alternative ) {
_install(
@@ -420,11 +425,11 @@
die "$tag {...} is invalid; use $alternative {...} instead.\n";
}
);
- #### Exporting place-holder sub: $name
+ ### Exporting place-holder sub: $name
# XXX TODO: more checking here
if ($name !~ /^(?:base|tr)$/) {
push @EXPORT, $name;
- push @TagSubs, $name;
+ push @TAG_SUB_LIST, $name;
}
$name = $alternative or return;
}
@@ -432,7 +437,7 @@
# We don't need this since we directly install
# subs into the target package.
#push @EXPORT, $name;
- push @TagSubs, $name;
+ push @TAG_SUB_LIST, $name;
no strict 'refs';
no warnings 'redefine';
@@ -456,8 +461,6 @@
_tag($tagset, @_);
}
};
- ##### package: $tagset->package
- ##### sub name: $name
_install(
1, # do override the existing sub with the same name
$tagset->package => $name => $code
@@ -564,7 +567,6 @@
= caller(1);
# This is the hash of attributes filled in by attr() calls in the code;
- ### Caller: (caller(1))[0]
my $tag = $subroutine;
$tag =~ s/^.*\:\://;
@@ -586,7 +588,6 @@
shift;
my $field = our $AUTOLOAD;
- ### $field
$field =~ s/.*:://;
$field =~ s/__/:/g; # xml__lang is 'foo' ====> xml:lang="foo"
@@ -810,11 +811,14 @@
tag subroutines generated from certain tag set, however,
are not included here.
-=item C<< @Template::Declare::Tags::TagSubs >>
+=item C<< @Template::Declare::Tags::TAG_SUB_LIST >>
Contains the names of the tag subroutines generated
from certain tag set.
+C<@Template::Declare::Tags::TagSubs> is supported only
+for backward-compatibility.
+
=item C<< $Template::Declare::Tags::TAG_NEST_DEPTH >>
Controls the indentation of the XML tags in the final outputs. For example, you can temporarily disable a tag's indentation by the following lines of code:
Added: Template-Declare/t/tag_sub_list.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/tag_sub_list.t Fri Aug 24 01:22:30 2007
@@ -0,0 +1,50 @@
+#use Smart::Comments;
+use strict;
+use warnings;
+use Test::More tests => 8;
+
+{
+ package Foo;
+ use List::Util 'first';
+ use Template::Declare::Tags 'HTML';
+
+ my @list = @Template::Declare::Tags::TAG_SUB_LIST;
+ ### @list
+ my $tag = first { $_ eq 'table' } @list;
+ ::is $tag, 'table', 'table {...} found';
+
+ $tag = first { $_ eq 'li' } @list;
+ ::is $tag, 'li', 'li {...} found';
+
+ # Backward compatibility:
+ @list = @Template::Declare::Tags::TagSubs;
+ ### @list
+ $tag = first { $_ eq 'table' } @list;
+ ::is $tag, 'table', 'table {...} found';
+
+ $tag = first { $_ eq 'li' } @list;
+ ::is $tag, 'li', 'li {...} found';
+
+}
+
+{
+ package Bar;
+ use List::Util 'first';
+ use Template::Declare::Tags 'XUL';
+ my @list = @Template::Declare::Tags::TAG_SUB_LIST;
+
+ my $tag = first { $_ eq 'div' } @list;
+ ::is $tag, 'div', 'HTML tag div {...} also found';
+ $tag = first { $_ eq 'tabbox' } @list;
+ ::is $tag, 'tabbox', 'tabbox {...} found';
+
+ # Backward compatibility:
+ @list = @Template::Declare::Tags::TagSubs;
+
+ $tag = first { $_ eq 'div' } @list;
+ ::is $tag, 'div', 'HTML tag div {...} also found';
+ $tag = first { $_ eq 'tabbox' } @list;
+ ::is $tag, 'tabbox', 'tabbox {...} found';
+
+}
+
More information about the Jifty-commit
mailing list