[Templates-cvs] cvs commit: TT3/lib/Template Base.pm

cvs@template-toolkit.org cvs@template-toolkit.org
Wed, 24 Mar 2004 15:53:27 +0000


cvs         04/03/24 15:53:27

  Modified:    lib/Template Base.pm
  Log:
  * some more changes to decline(), having it set ERROR as per error(), but
    also set DECLINE flag.  Still not sure if this is right, but I think it's
    better.
  
  Revision  Changes    Path
  1.3       +29 -9     TT3/lib/Template/Base.pm
  
  Index: Base.pm
  ===================================================================
  RCS file: /template-toolkit/TT3/lib/Template/Base.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Base.pm	2004/03/24 14:16:25	1.2
  +++ Base.pm	2004/03/24 15:53:26	1.3
  @@ -18,7 +18,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Base.pm,v 1.2 2004/03/24 14:16:25 abw Exp $
  +#   $Id: Base.pm,v 1.3 2004/03/24 15:53:26 abw Exp $
   #
   #========================================================================
   
  @@ -33,7 +33,7 @@
   require Template::Utils;
   require Template::Exception;
   
  -$VERSION   = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  +$VERSION   = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
   $DEBUG     = 0 unless defined $DEBUG;
   $ERROR     = '';
   $PAD       = 2;
  @@ -206,8 +206,9 @@
           ${"$class\::ERROR"} = $error;
   
           if (ref $self) {
  -            # set object error
  -            $self->{ ERROR } = $error;
  +            # set ERROR and DECLINED items
  +            $self->{ ERROR    } = $error;
  +            $self->{ DECLINED } = 0;
   
               # look for errors action in object, then package
               $throw = exists $self->{ THROW }
  @@ -220,7 +221,13 @@
           }
   
           # throw error or return undef/0 value of $throw
  -        return $throw ? $self->throw($throw, $error) : $throw;
  +        if ($throw) {
  +            $error .= "\n" unless $error =~ /\n$/;
  +            return $self->throw($throw, $error);
  +        }
  +        else {
  +            return $throw;
  +        }
       }
       elsif (ref $self) {
           return $self->{ ERROR };
  @@ -302,12 +309,23 @@
   # 
   # General purpose method used to decline a request of some kind.  Joins
   # all the arguments into a single string and stores it in the internal 
  -# DECLINED item to be accessed via the declined() method.  Returns undef.
  +# ERROR item to be accessed via the error() method.  Also sets the 
  +# internal DECLINED flag and then returns undef.
   #------------------------------------------------------------------------
   
   sub decline {
  -    my $self = shift;
  -    $self->{ DECLINED } = join('', @_) if ref $self;
  +    my $self  = shift;
  +    my $class = ref $self || $self;
  +    my $reason = join('', @_);
  +    no strict 'refs';
  +
  +    ${"$class\::ERROR"} = $reason;
  +
  +    if (ref $self) {
  +        $self->{ ERROR    } = $reason;
  +        $self->{ DECLINED } = 1;
  +    }
  +
       return undef;
   }
   
  @@ -576,6 +594,8 @@
   
   =head1 DESCRIPTION
   
  +TODO: decline() and decline() have changed a litte from what is documented.
  +
   This module implements a base class object from which most of the
   other Template Toolkit modules are derived.  It implements a number of
   methods to aid in object creation and configuration, error reporting,
  @@ -980,7 +1000,7 @@
   
   =head1 VERSION
   
  -$Revision: 1.2 $
  +$Revision: 1.3 $
   
   =head1 COPYRIGHT