Perl 5.00503, perl 5.61, and perl5.8.0 (at least) have a bug/misfeature
when die is overrideen via assignment to *CORE::GLOBAL::die. When this
happens, |die Foo->new(...)| is parsed as |(die Foo->new(...)|, and so we
get the not-very-informative error message 'Foo', with no
context.
See
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-09/msg01204.html
for testcase and discussion.
Since this is what TT's exception stuff des (which is how I noticed this),
and newer CGI::Carp versions use CORE::GLOBAL::die instead of
$::SIG{__DIE__}, TT should work arround this so that we can get
informative error messages from $template->error().
I've attached a patch which just adds an extra set of brackets arround all
calls to |die Template::Exception->new|, which works arround this problem.
There aren't any tests, because its not a TT bug, and I can't think of a
way to test it w/o affecting the rest of the test suite. It could go into
a separate .t file, though, I guess.
The patch passes the tests from CVS TT, except for test 10 of html.t,
which fails even w/o my patch. (This is perl 5.8.0 on RH8, if it matters)
Thanks,
Bradley
? die.diff
Index: Changes
===================================================================
RCS file: /template-toolkit/Template2/Changes,v
retrieving revision 2.68
diff -u -r2.68 Changes
--- Changes 2002/08/15 16:39:40 2.68
+++ Changes 2002/10/05 04:40:19
@@ -2574,7 +2574,7 @@
All errors should be thrown via one of the following:
die $error_msg;
- die Template::Exception->new($type, $info);
+ die (Template::Exception->new($type, $info));
$context->throw($msg);
$context->throw($type, $info);
$context->throw($exception);
Index: docsrc/lib/misc/exceptions
===================================================================
RCS file: /template-toolkit/Template2/docsrc/lib/misc/exceptions,v
retrieving revision 1.1
diff -u -r1.1 exceptions
--- docsrc/lib/misc/exceptions 2001/03/27 11:15:01 1.1
+++ docsrc/lib/misc/exceptions 2002/10/05 04:40:45
@@ -10,7 +10,7 @@
or from Perl code by calling die() with a Template::Exception object,
- die Template::Exception->new('user.denied', 'Invalid User ID');
+ die (Template::Exception->new('user.denied', 'Invalid User ID'));
or by simply calling die() with an error string. This is
automagically caught and converted to an exception of 'undef'
Index: docsrc/src/Manual/Internals.tt2
===================================================================
RCS file: /template-toolkit/Template2/docsrc/src/Manual/Internals.tt2,v
retrieving revision 1.2
diff -u -r1.2 Internals.tt2
--- docsrc/src/Manual/Internals.tt2 2001/08/21 17:46:31 1.2
+++ docsrc/src/Manual/Internals.tt2 2002/10/05 04:40:49
@@ -166,7 +166,7 @@
convenient wrapper for the 'type' and 'info' fields.
sub my_solilique_template {
- die Template::Exception->new('yorrick', 'Fellow of infinite jest');
+ die (Template::Exception->new('yorrick', 'Fellow of infinite jest'));
}
Templates generally need to do a lot more than just generate static
Index: docsrc/src/Manual/Variables.tt2
===================================================================
RCS file: /template-toolkit/Template2/docsrc/src/Manual/Variables.tt2,v
retrieving revision 1.14
diff -u -r1.14 Variables.tt2
--- docsrc/src/Manual/Variables.tt2 2002/07/19 14:54:35 1.14
+++ docsrc/src/Manual/Variables.tt2 2002/10/05 04:40:49
@@ -416,7 +416,7 @@
The exception types 'stop' and 'return' are used to implement the
STOP and RETURN directives. Throwing an exception as:
- die Template::Exception->new('stop');
+ die (Template::Exception->new('stop'));
has the same effect as the directive:
Index: docsrc/src/Release/Changes.tt2
===================================================================
RCS file: /template-toolkit/Template2/docsrc/src/Release/Changes.tt2,v
retrieving revision 1.68
diff -u -r1.68 Changes.tt2
--- docsrc/src/Release/Changes.tt2 2002/09/12 12:38:35 1.68
+++ docsrc/src/Release/Changes.tt2 2002/10/05 04:40:57
@@ -2588,7 +2588,7 @@
All errors should be thrown via one of the following:
die $error_msg;
- die Template::Exception->new($type, $info);
+ die (Template::Exception->new($type, $info));
$context->throw($msg);
$context->throw($type, $info);
$context->throw($exception);
Index: lib/Template/Context.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Context.pm,v
retrieving revision 2.71
diff -u -r2.71 Context.pm
--- lib/Template/Context.pm 2002/08/15 16:41:19 2.71
+++ lib/Template/Context.pm 2002/10/05 04:41:25
@@ -472,11 +472,11 @@
die $error;
}
elsif (defined $info) {
- die Template::Exception->new($error, $info, $output);
+ die (Template::Exception->new($error, $info, $output));
}
else {
$error ||= '';
- die Template::Exception->new('undef', $error, $output);
+ die (Template::Exception->new('undef', $error, $output));
}
# not reached
Index: lib/Template/Exception.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Exception.pm,v
retrieving revision 2.52
diff -u -r2.52 Exception.pm
--- lib/Template/Exception.pm 2002/08/15 16:41:21 2.52
+++ lib/Template/Exception.pm 2002/10/05 04:41:25
@@ -201,7 +201,7 @@
or from Perl code by calling die() with a Template::Exception object,
- die Template::Exception->new('user.denied', 'Invalid User ID');
+ die (Template::Exception->new('user.denied', 'Invalid User ID'));
or by simply calling die() with an error string. This is
automagically caught and converted to an exception of 'undef'
Index: lib/Template/Service.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Service.pm,v
retrieving revision 2.62
diff -u -r2.62 Service.pm
--- lib/Template/Service.pm 2002/08/15 16:41:25 2.62
+++ lib/Template/Service.pm 2002/10/05 04:41:25
@@ -647,7 +647,7 @@
or from Perl code by calling die() with a Template::Exception object,
- die Template::Exception->new('user.denied', 'Invalid User ID');
+ die (Template::Exception->new('user.denied', 'Invalid User ID'));
or by simply calling die() with an error string. This is
automagically caught and converted to an exception of 'undef'
Index: lib/Template/Manual/Config.pod
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Manual/Config.pod,v
retrieving revision 1.39
diff -u -r1.39 Config.pod
--- lib/Template/Manual/Config.pod 2002/08/15 16:41:57 1.39
+++ lib/Template/Manual/Config.pod 2002/10/05 04:41:32
@@ -985,7 +985,7 @@
or from Perl code by calling die() with a Template::Exception object,
- die Template::Exception->new('user.denied', 'Invalid User ID');
+ die (Template::Exception->new('user.denied', 'Invalid User ID'));
or by simply calling die() with an error string. This is
automagically caught and converted to an exception of 'undef'
Index: lib/Template/Manual/Internals.pod
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Manual/Internals.pod,v
retrieving revision 1.38
diff -u -r1.38 Internals.pod
--- lib/Template/Manual/Internals.pod 2002/08/15 16:42:02 1.38
+++ lib/Template/Manual/Internals.pod 2002/10/05 04:41:34
@@ -212,7 +212,7 @@
convenient wrapper for the 'type' and 'info' fields.
sub my_solilique_template {
- die Template::Exception->new('yorrick', 'Fellow of infinite jest');
+ die (Template::Exception->new('yorrick', 'Fellow of infinite jest'));
}
Templates generally need to do a lot more than just generate static
Index: lib/Template/Manual/Variables.pod
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Manual/Variables.pod,v
retrieving revision 1.38
diff -u -r1.38 Variables.pod
--- lib/Template/Manual/Variables.pod 2002/08/15 16:42:03 1.38
+++ lib/Template/Manual/Variables.pod 2002/10/05 04:41:35
@@ -461,7 +461,7 @@
The exception types 'stop' and 'return' are used to implement the
STOP and RETURN directives. Throwing an exception as:
- die Template::Exception->new('stop');
+ die (Template::Exception->new('stop'));
has the same effect as the directive:
Index: lib/Template/Plugin/DBI.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/DBI.pm,v
retrieving revision 2.50
diff -u -r2.50 DBI.pm
--- lib/Template/Plugin/DBI.pm 2002/08/15 16:42:14 2.50
+++ lib/Template/Plugin/DBI.pm 2002/10/05 04:41:35
@@ -341,7 +341,7 @@
my $error = shift || die "DBI throw() called without an error string\n";
# throw error as DBI exception
- die Template::Exception->new('DBI', $error);
+ die (Template::Exception->new('DBI', $error));
}
Index: lib/Template/Plugin/Date.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/Date.pm,v
retrieving revision 2.60
diff -u -r2.60 Date.pm
--- lib/Template/Plugin/Date.pm 2002/08/20 23:29:01 2.60
+++ lib/Template/Plugin/Date.pm 2002/10/05 04:41:36
@@ -150,7 +150,7 @@
sub throw {
my $self = shift;
- die Template::Exception->new('date', join(', ', @_));
+ die (Template::Exception->new('date', join(', ', @_)));
}
Index: lib/Template/Plugin/Directory.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/Directory.pm,v
retrieving revision 2.53
diff -u -r2.53 Directory.pm
--- lib/Template/Plugin/Directory.pm 2002/08/15 16:42:15 2.53
+++ lib/Template/Plugin/Directory.pm 2002/10/05 04:41:36
@@ -160,7 +160,7 @@
sub throw {
my ($self, $error) = @_;
- die Template::Exception->new('Directory', $error);
+ die (Template::Exception->new('Directory', $error));
}
__END__
Index: lib/Template/Plugin/File.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/File.pm,v
retrieving revision 2.53
diff -u -r2.53 File.pm
--- lib/Template/Plugin/File.pm 2002/08/15 16:42:16 2.53
+++ lib/Template/Plugin/File.pm 2002/10/05 04:41:38
@@ -140,7 +140,7 @@
sub throw {
my ($self, $error) = @_;
- die Template::Exception->new('File', $error);
+ die (Template::Exception->new('File', $error));
}
__END__
Index: lib/Template/Plugin/List.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/List.pm,v
retrieving revision 1.1
diff -u -r1.1 List.pm
--- lib/Template/Plugin/List.pm 2002/03/12 17:16:19 1.1
+++ lib/Template/Plugin/List.pm 2002/10/05 04:41:38
@@ -98,7 +98,7 @@
sub throw {
my $self = CORE::shift;
- die Template::Exception->new('List', CORE::join('', @_));
+ die (Template::Exception->new('List', CORE::join('', @_)));
}
Index: lib/Template/Plugin/String.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/String.pm,v
retrieving revision 2.22
diff -u -r2.22 String.pm
--- lib/Template/Plugin/String.pm 2002/08/15 16:42:19 2.22
+++ lib/Template/Plugin/String.pm 2002/10/05 04:41:38
@@ -97,7 +97,7 @@
sub throw {
my $self = shift;
- die Template::Exception->new('String', join('', @_));
+ die (Template::Exception->new('String', join('', @_)));
}
Index: lib/Template/Plugin/XML/DOM.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/XML/DOM.pm,v
retrieving revision 2.44
diff -u -r2.44 DOM.pm
--- lib/Template/Plugin/XML/DOM.pm 2002/08/15 16:42:50 2.44
+++ lib/Template/Plugin/XML/DOM.pm 2002/10/05 04:41:40
@@ -141,7 +141,7 @@
sub _throw {
my ($self, $error) = @_;
- die Template::Exception->new('XML.DOM', $error);
+ die (Template::Exception->new('XML.DOM', $error));
}
Index: lib/Template/Plugin/XML/Simple.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/XML/Simple.pm,v
retrieving revision 2.51
diff -u -r2.51 Simple.pm
--- lib/Template/Plugin/XML/Simple.pm 2002/08/15 16:42:51 2.51
+++ lib/Template/Plugin/XML/Simple.pm 2002/10/05 04:41:40
@@ -57,7 +57,7 @@
sub _throw {
my ($self, $error) = @_;
- die Template::Exception->new('XML.XPath', $error);
+ die (Template::Exception->new('XML.XPath', $error));
}
Index: lib/Template/Plugin/XML/View.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/XML/View.pm,v
retrieving revision 2.2
diff -u -r2.2 View.pm
--- lib/Template/Plugin/XML/View.pm 2001/11/20 14:10:56 2.2
+++ lib/Template/Plugin/XML/View.pm 2002/10/05 04:41:40
@@ -115,7 +115,7 @@
sub _throw {
my ($self, $error) = @_;
- die Template::Exception->new('XML.View', $error);
+ die (Template::Exception->new('XML.View', $error));
}
sub DEBUG { print STDERR @_ };
Index: lib/Template/Plugin/XML/XPath.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/XML/XPath.pm,v
retrieving revision 2.56
diff -u -r2.56 XPath.pm
--- lib/Template/Plugin/XML/XPath.pm 2002/08/15 16:42:52 2.56
+++ lib/Template/Plugin/XML/XPath.pm 2002/10/05 04:41:40
@@ -91,7 +91,7 @@
sub _throw {
my ($self, $error) = @_;
# print STDERR "about to throw $error\n";
- die Template::Exception->new('XML.XPath', $error);
+ die (Template::Exception->new('XML.XPath', $error));
}
Index: t/filter.t
===================================================================
RCS file: /template-toolkit/Template2/t/filter.t,v
retrieving revision 2.17
diff -u -r2.17 filter.t
--- t/filter.t 2002/08/16 16:15:36 2.17
+++ t/filter.t 2002/10/05 04:41:42
@@ -146,7 +146,7 @@
die "keeled over\n";
}
else {
- die Template::Exception->new('unwell', 'sick as a parrot');
+ die (Template::Exception->new('unwell', 'sick as a parrot'));
}
}
Index: t/try.t
===================================================================
RCS file: /template-toolkit/Template2/t/try.t,v
retrieving revision 2.2
diff -u -r2.2 try.t
--- t/try.t 2001/03/29 23:00:54 2.2
+++ t/try.t 2002/10/05 04:41:42
@@ -31,7 +31,7 @@
};
my $replace = &callsign();
$replace->{ throw_egg } = sub {
- die Template::Exception->new('egg', 'scrambled');
+ die (Template::Exception->new('egg', 'scrambled'));
};
$replace->{ throw_any } = sub {
die "undefined error\n";