| 1 | package OpenInteract2::TT2::Context; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: Context.pm,v 1.3 2005/03/18 04:09:51 lachoy Exp $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base qw( Template::Context ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Template::Constants qw( STATUS_ERROR ERROR_FILE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | $OpenInteract2::TT2::Context::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Overriding Template::Context so we can get around the issue of the | ||||||||||||||||||||||||||||
| 12 | # template name 'x::y' being interpreted as a directive to have a | ||||||||||||||||||||||||||||
| 13 | # particular provider parse it (yuck) | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub template { | ||||||||||||||||||||||||||
|
Subroutine
template: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | my ( $template ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Template::Document (or sub-class) objects, or CODE refs are | ||||||||||||||||||||||||||||
| 20 | # assumed to be pre-compiled templates and are returned intact | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ( UNIVERSAL::isa( $name, 'Template::Document' ) || ref( $name ) eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
UNIVERSAL::isa($name, "Template::Document") or ref $name eq "CODE"
MC/DC0%0/2
UNIVERSAL::isa($name, "Template::Document") or ref $name eq "CODE"
UNIVERSAL::isa($name, "Template::Document")
ref $name eq "CODE"
Truth table0%0/3
A or B
A= UNIVERSAL::isa($name, "Template::Document")B= ref $name eq "CODE"
| |||||||||||||||||||||||||||||
| 23 | 0 | return $name; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless ( ref $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # we first look in the BLOCKS hash for a BLOCK that may have | ||||||||||||||||||||||||||||
| 29 | # been imported from a template (via PROCESS) | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return $template if ( $template = $self->{ BLOCKS }->{ $name } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # then we iterate through the BLKSTACK list to see if any of the | ||||||||||||||||||||||||||||
| 34 | # Template::Documents we're visiting define this BLOCK | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | foreach my $blocks (@{ $self->{ BLKSTACK } }) { | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | return $template if ( $blocks && ( $template = $blocks->{ $name } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$blocks and $template = $blocks->{$name}
MC/DC0%0/2
$blocks and $template = $blocks->{$name}
$blocks
$template = $blocks->{$name}
Truth table0%0/3
A and B
A= $blocksB= $template = $blocks->{$name}
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $providers = $self->{ PREFIX_MAP }->{ default } || $self->{ LOAD_TEMPLATES }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'PREFIX_MAP'}{'default'} || $self->{'LOAD_TEMPLATES'}
MC/DC0%0/2
$self->{'PREFIX_MAP'}{'default'} || $self->{'LOAD_TEMPLATES'}
$self->{'PREFIX_MAP'}{'default'}
$self->{'LOAD_TEMPLATES'}
Truth table0%0/3
A || B
A= $self->{'PREFIX_MAP'}{'default'}B= $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 | 0 | foreach my $provider ( @{ $providers } ) { | |||||||||||||||||||||||||||
| 48 | 0 | my ( $error ); | |||||||||||||||||||||||||||
| 49 | 0 | ( $template, $error ) = $provider->fetch( $name ); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | return $template unless ( $error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $error == STATUS_ERROR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $self->throw( $template ) if ( ref $template ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->throw( ERROR_FILE, $template ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | $self->throw( ERROR_FILE, "$name: not found" ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||