[Catalyst] Moving to YAML config file when you use ->path_to

James FitzGibbon jfitzgibbon at primustel.ca
Fri Jan 20 23:20:42 CET 2006


I notice that 5.6.2 has added support for putting your config into a YAML
file rather than having "sub config" littered through your components.

(side question: is this a proper adoption of the CPAN module
Catalyst::Plugin::Config::YAML into the Catalyst core?  The changelog
doesn't say.)

My problem is that my view component uses ->path_to:

__PACKAGE__->config({
    CATALYST_VAR => 'Catalyst',
    INCLUDE_PATH => [
        Foo->path_to('root', 'src'),
        Foo->path_to('root', 'lib'),
    ],
    TEMPLATE_EXTENSION => '.tt',
    PRE_PROCESS        => 'config/main',
    WRAPPER            => 'site/wrapper',
    TIMER              => 0,
});

Now if I move this verbatim into a YAML file:

View::TT:
    CATALYST_VAR: Catalyst
    INCLUDE_PATH:
        - Foo->path_to('root', 'src')
        - Foo->path_to('root', 'lib')
    TEMPLATE_EXTENSION: .tt
    PRE_PROCESS: config/main
    WRAPPER: site/wrapper
    TIMER: 0

Then things break because the method calls aren't executed and TT2 is given
the literal string "Foo->path_to('root', 'src')" as a path to look for
templates in.

Is there any easy way to solve this?  Right now all I can think of is to
either define the literal components ('root, 'src') in the config file and
then have a "config" sub in Foo/View/TT.pm to take those elements and
replace them with the results of calling Foo->path_to() on them.

But that seems wrong.

I don't want to go down the slippery path of doing an eval of what YAML
pulls back in, and YAML's built support to deserialize code references only
uses 'eval', not 'Safe'.  Additionally, a high performance app might want to
use YAML::Syck instead of YAML for the speed increase, and I don't believe
that libsyck will ever handle code references.

Another idea is to use special tokens in the YAML file, then use something
like Data::Rmap to walk the resulting data structure, looking for the tokens
and doing replacement as described above.  Also icky.

Any thoughts?

Thanks

-- 
j.
 
James FitzGibbon
Systems Developer, Primus Telecommunications Canada Inc.
416.644.6111

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.21/235 - Release Date: 1/19/2006
 



-- 
----------------------------------------------------------------------------
This electronic message contains information from Primus Telecommunications
Canada Inc. ("PRIMUS") , which may be legally privileged and confidential.
The information is intended to be for the use of the individual(s) or entity
named above. If you are not the intended recipient, be aware that any
disclosure, copying, distribution or use of the contents of this information
is prohibited. If you have received this electronic message in error, please
notify us by telephone or e-mail (to the number or address above)
immediately. Any views, opinions or advice expressed in this electronic
message are not necessarily the views, opinions or advice of PRIMUS.
It is the responsibility of the recipient to ensure that
any attachments are virus free and PRIMUS bears no responsibility
for any loss or damage arising in any way from the use
thereof.The term "PRIMUS" includes its affiliates.
----------------------------------------------------------------------------
Pour la version en français de ce message, veuillez voir
 http://www.primustel.ca/fr/legal/cs.htm
----------------------------------------------------------------------------




More information about the Catalyst mailing list