With reference to:
> http://catalyst.perl.org/random/castaway/2005/12/16/Template_Provider_DBI 

Jess Robinson wrote:
> And while I'm at it, does anything actually use the PREFIX_MAP code? It 
> seems that the FAQ, the Changes doc and the code itself are all 
> contradictory, and the implementation appears as if it would not work. 

It's confusing I admit, and only partially documented in a half-hearted
attempt to discourage people from using it in case I ever decided to 
think about it properly and implement something better.

But as far as I can tell, it is consistent and does work.

The values in PREFIX_MAP are numbers or strings containing a list 
of numbers, delimited by any sequence of non-number characters.

   foo => 1
   bar => '2'
   baz => '3 4 5'
   boz => '6, 7, 8'

This gets expanded by the Template::Content::_init() method to reference
the actual providers in LOAD_TEMPLATES ($providers in the code fragment 
below):

    while (my ($key, $val) = each %$prefix_map) {
        $prefix_map->{ $key } = [ 
            ref $val 
              ? $val 
              : map { $providers->[$_] } 
                split(/\D+/, $val) 
        ] unless ref $val eq 'ARRAY';
    }

Then in the template() method we select the providers based on any
prefix specified, or the { default } option, or the whole LOAD_TEMPLATES
list.

    if (defined $prefix) {
        $providers = $self->{ PREFIX_MAP }->{ $prefix } 
            || return $self->throw("bad prefix blah...);
    }

    $providers = $self->{ PREFIX_MAP }->{ default } 
        || $self->{ LOAD_TEMPLATES }
        unless $providers;

Then we ask each $provider in @$providers in turn for the template
and that pretty much wraps it up.

HTH
A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to