Hello,

I have the following expression in one of templates

IF msg.subject.length > max_subject_length

and got a warning when the subject happened to be not defined:

Argument "" isn't numeric in numeric gt (>) at (eval 49) line 284.

Then I tried to make $SCALAR_OPS->{ length } return 0 but it turned
out that method calls are skipped on undefined values in _dotop().

Isn't it a right thing to have a special UNDEF_OPS table or maybe
just treat undef as a scalar?  Most scalar methods except 'length'
and 'defined' already check whether their argument is defined, so
I have made a quick patch which is attached.

--
Vladimir Pastukhov <[EMAIL PROTECTED]>
--- ./lib/Template/Stash.pm.orig        Mon Jun 25 18:51:55 2001
+++ ./lib/Template/Stash.pm     Wed Jun 27 16:03:09 2001
@@ -53,8 +53,8 @@
     'item'    => sub {   $_[0] },
     'list'    => sub { [ $_[0] ] },
     'hash'    => sub { { value => $_[0] } },
-    'length'  => sub { length $_[0] },
-    'defined' => sub { return 1 },
+    'length'  => sub { defined $_[0] ? length $_[0] : 0 },
+    'defined' => sub { defined $_[0] ? 1 : 0 },
     'repeat'  => sub { 
         my ($str, $count) = @_;
         $str = '' unless defined $str;  
@@ -290,9 +290,7 @@
        # ($self) as the first implicit 'result'...
 
        foreach (my $i = 0; $i <= $size; $i += 2) {
-           $result = $self->_dotop($root, @$ident[$i, $i+1]);
-           last unless defined $result;
-           $root = $result;
+           $root = $result = $self->_dotop($root, @$ident[$i, $i+1]);
        }
     }
     else {
@@ -455,8 +453,7 @@
 
     # return undef without an error if either side of the dot is unviable
     # or if an attempt is made to access a private member, starting _ or .
-    return undef
-       unless defined($root) and defined($item) and $item !~ /^[\._]/;
+    return undef unless defined($item) and $item !~ /^[\._]/;
 
     if ($rootref eq __PACKAGE__ || $rootref eq 'HASH') {
 

Reply via email to