[Catalyst] $c->comp($name) fails to return the correct class

Alan Tam Tam at SiuLung.com
Sat Sep 24 14:32:52 CEST 2005


Hi,

I am new in perl, so please forgive me if it is stupid.

I tried to use $c->comp("MyApp::M::CDBI::Book") to get a class for the 
"Book" table, but turns out it returned me the class for 
$c->comp("MyApp::M::CDBI::Booklet").

I traced down into Catalyst::Engine::component:
sub component {
    my $c = shift;
    if (@_) {
        my $name = shift;
        if ( my $component = $c->components->{$name} ) { # 
------------------- (*)
            return $component;
        }
        else {
            # try to match $name as regex
        }
    }
}

I found that $component has obtained the correct class for 
"MyApp::M::CDBI::Book" in (*) but the "if" condition FAILED and hence 
control jumped to the else part, matching the "MyApp::M::CDBI::Booklet" 
class instead.

I tried modifying it to
-        if ( my $component = $c->components->{$name} ) {
+        if ( defined( my $component = $c->components->{$name} ) ) {
then it works.

Anyone can tell me what did I do wrong? Thanks a lot!

-- 
Regards,
Alan




More information about the Catalyst mailing list