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

cvs@template-toolkit.org cvs@template-toolkit.org
Fri, 17 Dec 2004 14:20:50 +0000


cvs         04/12/17 14:20:50

  Modified:    lib/Template Context.pm
  Log:
  * minor changes, checking in before refit
  
  Revision  Changes    Path
  1.14      +28 -13    TT3/lib/Template/Context.pm
  
  Index: Context.pm
  ===================================================================
  RCS file: /template-toolkit/TT3/lib/Template/Context.pm,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Context.pm	2004/12/16 19:24:54	1.13
  +++ Context.pm	2004/12/17 14:20:49	1.14
  @@ -16,7 +16,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Context.pm,v 1.13 2004/12/16 19:24:54 abw Exp $
  +#   $Id: Context.pm,v 1.14 2004/12/17 14:20:49 abw Exp $
   #
   #========================================================================
   
  @@ -39,7 +39,7 @@
   use constant FETCH => 'fetch';
   use constant GET   => 'get';
   
  -our $VERSION   = sprintf("%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/);
  +our $VERSION   = sprintf("%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/);
   our $DEBUG     = 0 unless defined $DEBUG;
   our $ERROR     = '';
   our $THROW     = 'context';
  @@ -150,15 +150,21 @@
   
       # TODO: handle get/set path and delete path_obj cache
   
  -    # look for a component path if the context path is undefined
  -    $path = $self->{ path } = $self->{ component }->{ path }
  -        unless defined $self->{ path };
  -
  -    # failing that, set the path to an empty string
  -    $path = $self->{ path } = ''
  -        unless defined $path;
  +    if (@_) {
  +        delete $self->{ path_obj };
  +        return $self->{ path } = shift;
  +    }
  +    else {
  +        # look for a component path if the context path is undefined
  +        $path = $self->{ path } = $self->{ component }->{ path }
  +            unless defined $self->{ path };
  +
  +        # failing that, set the path to an empty string
  +        $path = $self->{ path } = ''
  +            unless defined $path;
   
  -    return $path;
  +        return $path;
  +    }
   }
   
   
  @@ -219,6 +225,8 @@
       my $cclass = $self->pkgvar( COMPONENT => $COMPONENT );
       my $debug  = $self->{ DEBUG };
   
  +    $self->debug("component($name)\n") if $debug;
  +
       # TODO: check local component cache
   
       my $global = $self->{ global } || $self->global();
  @@ -241,12 +249,15 @@
   
           # let template() handle a reference to something else, 
           $template = $self->template($name) || return;
  -        $id = $template->id();
  +        $id   = $template->id();
  +        $path = $template->path();
       }
       else {
           # expand $name template name into full path name(s) computed
           # relative to the current context path
           my $names = $self->paths($name) || return;
  +        $self->debug("paths: ", join(', ', @$names), "\n"), if $debug;
  +
           
           foreach $path (@$names) {
               $self->debug(" - path: $path\n") if $debug;
  @@ -275,6 +286,7 @@
           return $self->error("template not found: $name")
               unless $id;
       }
  +    $self->debug("template path : $path\n") if $debug;
   
       # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
       # Cache
  @@ -309,7 +321,7 @@
           $template ||= $self->template($path) || return;
   
           # notify component of its source object
  -        $component->template($template);
  +        $component->source($template);
   
           if ($component->fresh()) {
               $self->debug(" - found stored template\n") if $debug;
  @@ -330,6 +342,7 @@
       #   then we need to get fetch it now.
       # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
           
  +    # TODO: $path may be undefined?
       $template ||= $self->template($path) || do {
           # this should probably never happen, but never say never....
           # we could get an id for a template one minute, cache it in
  @@ -341,6 +354,8 @@
       };
   
       # cache the template id for a static path
  +    # TODO: warning ($path undefined)
  +    $self->debug("setting path [$path]\n") if $debug;
       $paths->{ $path } = $template->id() if $static;
   
       # now we should have a valid source ready to be compiled
  @@ -536,7 +551,7 @@
   
   =head1 VERSION
   
  -$Revision: 1.13 $
  +$Revision: 1.14 $
   
   =head1 COPYRIGHT