[Catalyst] ConfigLoader and components

Nathan Kurz nate at verse.com
Wed May 10 09:09:43 CEST 2006


On Tue, May 09, 2006 at 10:40:52PM -0600, Nathan Kurz wrote:
> I've been beating my head against this for an hour now, and think I
> must be missing something.  How can I use ConfigLoader to let me set
> the database dsn in myapp.yml, and pass that along to the component
> I'm deriving from Catalyst::Model::DBIC::Schema?

Silly me.  It turned out that I had deleted Makefile.PL to make the
sample code simpler, and obviously this causes $config->{home} to be
set one subdirectory deeper than it otherwise would.  So all I needed
to do was move my app.yml file into 'lib' and things started working.

Nothing wasted by a few hours of my time... :(

By the way, why does Catalyst::Utils::home() rely on Makefile.PL?
And does the rest of the code in that function smell right to you?

sub home {
    my $name = shift;
    $name =~ s/\:\:/\//g;
    my $home = 0;
    if ( my $path = $INC{"$name.pm"} ) {
        $home = file($path)->absolute->dir;
        $name =~ /(\w+)$/;
        my $append = $1;
        my $subdir = dir($home)->subdir($append);
        for ( split '/', $name ) { $home = dir($home)->parent }
        if ( $home =~ /blib$/ ) { $home = dir($home)->parent }
        elsif (!-f file( $home, 'Makefile.PL' )
            && !-f file( $home, 'Build.PL' ) )
        {
            $home = $subdir;
        }

        # clean up relative path:
        # MyApp/script/.. -> MyApp
        my ($lastdir) = $home->dir_list( -1, 1 );
        if ( $lastdir eq '..' ) {
            $home = dir($home)->parent->parent;
        }
    }
    return $home;
}

--nate







More information about the Catalyst mailing list