On Tue, May 12, 2009 at 12:19:28PM +0100, Andy Wardley wrote:
> > I've attached a patch written against Template-Toolkit-2.20.
>
> No you haven't :-)
Damn - I always do that. I need the "It looks like you forgot an
attachment" Google Labs plugin for mutt. Or to be less forgetful.
> Before you re-send it, can you confirm that all the tests pass with the
> patch in. If they do then I have no objection to the patch in principle.
> But I've got a nasty suspicion that there may be problems...
They did all pass:
---- cut here ----
t/args.t .............. ok
t/assert.t ............ ok
t/autoform.t .......... skipped: (no reason given)
t/base.t .............. ok
# ...
# ...
t/url2.t .............. skipped: (no reason given)
t/vars.t .............. ok
t/varsv1.t ............ ok
t/view.t .............. ok
t/vmethods/hash.t ..... ok
t/vmethods/list.t ..... ok
t/vmethods/replace.t .. ok
t/vmethods/text.t ..... ok
t/while.t ............. ok
t/wrap.t .............. ok
t/wrapper.t ........... ok
All tests successful.
Files=86, Tests=2809, 28 wallclock secs ( 1.14 usr 0.24 sys + 13.17 cusr 1.51
csys = 16.06 CPU)
Result: PASS
---- cut here ----
--
Chisel Wright
e: [email protected]
w: http://www.herlpacker.co.uk/
Everyone's first vi session:
^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat
diff -Naur lib.orig/Template/Iterator.pm lib/Template/Iterator.pm
--- lib.orig/Template/Iterator.pm 2009-05-12 09:51:18.000000000 +0100
+++ lib/Template/Iterator.pm 2009-05-12 10:21:16.000000000 +0100
@@ -26,6 +26,8 @@
use base 'Template::Base';
use Template::Constants;
use Template::Exception;
+use UNIVERSAL::can;
+use Scalar::Util qw(blessed);
our $VERSION = 2.68;
our $DEBUG = 0 unless defined $DEBUG;
@@ -54,7 +56,7 @@
$data = [ map { { key => $_, value => $data->{ $_ } } }
sort keys %$data ];
}
- elsif (UNIVERSAL::can($data, 'as_list')) {
+ elsif (blessed($data) && $data->can('as_list')) {
$data = $data->as_list();
}
elsif (ref $data ne 'ARRAY') {
diff -Naur lib.orig/Template/Plugin/Scalar.pm lib/Template/Plugin/Scalar.pm
--- lib.orig/Template/Plugin/Scalar.pm 2009-05-12 09:51:18.000000000 +0100
+++ lib/Template/Plugin/Scalar.pm 2009-05-12 10:18:15.000000000 +0100
@@ -93,10 +93,15 @@
my $item = $AUTOLOAD;
$item =~ s/.*:://;
return if $item eq 'DESTROY';
-
- # lookup the method...
- my $method = UNIVERSAL::can($this, $item)
- || die $EXCEPTION->new( scalar => "invalid object method: $item" );
+
+ my $method;
+ if (Scalar::Util::blessed($this)) {
+ # lookup the method...
+ $method = $this->can($item);
+ }
+ else {
+ die $EXCEPTION->new( scalar => "invalid object method: $item" );
+ }
# ...and call it in scalar context
my $result = $method->($this, @_);
diff -Naur lib.orig/Template/Stash.pm lib/Template/Stash.pm
--- lib.orig/Template/Stash.pm 2009-05-12 09:51:18.000000000 +0100
+++ lib/Template/Stash.pm 2009-05-12 10:20:16.000000000 +0100
@@ -22,6 +22,7 @@
use strict;
use warnings;
use Template::VMethods;
+use UNIVERSAL::can();
use Scalar::Util 'blessed';
our $VERSION = 2.91;
@@ -445,7 +446,7 @@
# doesn't appear to work with CGI, returning true for the first call
# and false for all subsequent calls.
- elsif (ref($root) && UNIVERSAL::can($root, 'can')) {
+ elsif (blessed($root) && $root->can('can')) {
# if $root is a blessed reference (i.e. inherits from the
# UNIVERSAL object base class) then we call the item as a method.
diff -Naur lib.orig/Template.pm lib/Template.pm
--- lib.orig/Template.pm 2009-05-12 09:51:18.000000000 +0100
+++ lib/Template.pm 2009-05-12 10:22:26.000000000 +0100
@@ -29,6 +29,8 @@
use Template::Service;
use File::Basename;
use File::Path;
+use UNIVERSAL::can;
+use Scalar::Util qw(blessed);
our $VERSION = '2.20';
our $ERROR = '';
@@ -170,7 +172,7 @@
}
# call the print() method on an object that implements the method
# (e.g. IO::Handle, Apache::Request, etc)
- elsif (UNIVERSAL::can($where, 'print')) {
+ elsif (blessed($where) && $where->can('print')) {
$where->print($$textref);
}
# a simple string is taken as a filename
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates