| 1 | package OpenInteract::Template::Context; | ||
| 2 | |||
| 3 | # $Id: Context.pm,v 1.60 2002/09/16 20:21:29 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use base qw( Template::Context ); | ||
| 7 | |||
| 8 | $OpenInteract::Template::Context::VERSION = sprintf("%d.%02d", q$Revision: 1.60 $ =~ /(\d+)\.(\d+)/); | ||
| 9 | |||
| 10 | # Overriding Template::Context so we can get around the issue of the | ||
| 11 | # template name 'x::y' being interpreted as a directive to have a | ||
| 12 | # particular provider parse it (yuck) | ||
| 13 | |||
| 14 | sub template { | ||
| 15 | my ( $self, $name ) = @_; | ||
| 16 | my ( $template ); | ||
| 17 | |||
| 18 | # Template::Document (or sub-class) objects, or CODE refs are | ||
| 19 | # assumed to be pre-compiled templates and are returned intact | ||
| 20 | |||
| 21 | if ( UNIVERSAL::isa( $name, 'Template::Document' ) || ref( $name ) eq 'CODE' ) { | ||
| 22 | return $name; | ||
| 23 | } | ||
| 24 | |||
| 25 | unless ( ref $name ) { | ||
| 26 | |||
| 27 | # we first look in the BLOCKS hash for a BLOCK that may have | ||
| 28 | # been imported from a template (via PROCESS) | ||
| 29 | |||
| 30 | return $template if ( $template = $self->{BLOCKS}->{ $name } ); | ||
| 31 | |||
| 32 | # then we iterate through the BLKSTACK list to see if any of the | ||
| 33 | # Template::Documents we're visiting define this BLOCK | ||
| 34 | |||
| 35 | foreach my $blocks (@{ $self->{BLKSTACK} }) { | ||
| 36 | return $template if ( $blocks && ( $template = $blocks->{ $name } ) ); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | my $providers = $self->{PREFIX_MAP}->{default} || | ||
| 41 | $self->{LOAD_TEMPLATES}; | ||
| 42 | |||
| 43 | # Finally we try the regular template providers which will | ||
| 44 | # handle references to files, text, etc., as well as templates | ||
| 45 | # reference by name | ||
| 46 | |||
| 47 | foreach my $provider ( @{ $providers } ) { | ||
| 48 | my ( $error ); | ||
| 49 | ( $template, $error ) = $provider->fetch( $name ); | ||
| 50 | return $template unless ( $error ); | ||
| 51 | # return $self->error($template) | ||
| 52 | if ( $error == Template::Constants::STATUS_ERROR) { | ||
| 53 | $self->throw( $template ) if ( ref $template ); | ||
| 54 | $self->throw( Template::Constants::ERROR_FILE, $template ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | $self->throw( Template::Constants::ERROR_FILE, "$name: not found" ); | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | |||
| 62 | __END__ |