[Jifty-commit] r2498 - in Template-Declare: lib/Template/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Jan 15 20:58:26 EST 2007
Author: jesse
Date: Mon Jan 15 20:58:25 2007
New Revision: 2498
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare/Tags.pm
Log:
r20991 at hualien: jesse | 2007-01-15 17:57:23 -0500
* refactoring for readability
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Mon Jan 15 20:58:25 2007
@@ -7,24 +7,12 @@
use base 'Exporter';
use Carp;
- at EXPORT =
- qw( with template private show get_current_attr attr outs outs_raw in_isolation $self under Tr td ); # these two warns the user to use row/cell instead
+ at EXPORT = qw( with template private show get_current_attr attr outs outs_raw in_isolation $self under);
+push @EXPORT, qw(Tr td ); # these two warns the user to use row/cell instead
-sub under ($) { return shift }
-
-our $DEPTH = 0;
our %ATTRIBUTES = ();
our $BUFFER = '';
-
-sub Tr (&) {
- die
- "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
-}
-
-sub td (&) {
- die
- "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
-}
+our $DEPTH = 0;
sub attr (&;$) {
my ( $code, $out ) = @_;
@@ -226,10 +214,15 @@
=head2 show [$class or $object] [$template_name or $template_coderef]
-show can either be called with a template name or a package/object and
+C<show> displays templates.
+
+Do not call templates with arguments. That's not supported.
+XXX TODO: This makes jesse cry. Audrey/cl: sanity check?
+
+
+C<show> can either be called with a template name or a package/object and
a template. (It's both functional and OO.)
-Displays that template, if it exists.
If called from within a Template::Declare subclass, then private
templates are accessible and visible. If called from something that
@@ -240,26 +233,21 @@
sub show {
my $template = shift;
- my $buf = '';
+ my $buf = '';
my $INSIDE_TEMPLATE = 0;
my $caller = caller();
+
+ # if we're inside a template, we should show private templates
if ( $caller->isa('Template::Declare') ) { $INSIDE_TEMPLATE = 1; }
+ my $callable =
+ ref($template) eq 'CODE'
+ ? $template
+ : Template::Declare->has_template( $template, $INSIDE_TEMPLATE );
+ return '' unless ($callable);
+
{
local $BUFFER = '';
-
- my $callable;
- if ( ref($template) eq 'CODE' ) {
- $callable = $template;
- } else {
- # if we're inside a template, we should show private templates
- $callable = Template::Declare->has_template( $template, $INSIDE_TEMPLATE );
- }
-
- # may want to just use the return value of has_template eventually
- if ($callable) {
- # no strict 'refs';
- &$callable( $self );
- }
+ &$callable($self);
$buf = $BUFFER;
}
@@ -281,4 +269,41 @@
return $val;
}
+=head2 import 'Package' under 'path'
+
+Import the templates from C<Package> into the subpath 'path' of the current package, clobbering any
+of your own package's templates that you'd already defined.
+
+=cut
+
+=head2 under
+
+C<under> is a helper function for the "import" semantic sugar.
+
+=cut
+
+sub under ($) { return shift }
+
+=head2 Tr
+
+Template::Declare::Tags uses C<row> and C<cell> for table definitions rather than C<tr> and C<td>.
+(C<tr> is reserved by the perl interpreter for the operator of that name. We can't override it.)
+
+=cut
+
+sub Tr (&) {
+ die "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
+}
+
+=head2 td
+
+Template::Declare::Tags uses C<row> and C<cell> for table definitions rather than C<tr> and C<td>.
+(C<tr> is reserved by the perl interpreter for the operator of that name. We can't override it.)
+
+=cut
+
+sub td (&) {
+ die "Tr {...} and td {...} are invalid; use row {...} and cell {...} instead.";
+}
+
1;
More information about the Jifty-commit
mailing list