[cgiapp] re: why do I get "Bad name after ::" in Perl? (was: Re: Model design in C::A/Titanium)

Mark Stosberg mark at summersault.com
Wed Sep 24 20:54:58 EDT 2008


> [Dispatch] ERROR' for request '/': Unable to load module 
> 'WebApp::Controller::Foo': Bad name after :: at 
> WebApp/Controller/Base.pm line 98.
> 
> ############ WebApp::Controller::Base ###################
> sub model {
>    my $c = shift;
>    my $subclass = shift or die 'Required attribute missing';
>    ..
>    my $obj = WebApp::DB::$subclass->new(); # <= THIS IS LINE 98

You need quotes around the package name. With them 'WebApp::DB::' is
like a constant...and you just can't concatenate variables like this. 

This little script demonstates the bug and the fix:

package Foo::Zoo;
sub new { print "you found me!\n"; }

package main;
use strict;

my $a = 'Zoo';

# Uncomment either one for testing. 
Foo::$a->new;
# "Foo::$a"->new;

    Mark

-- 
http://mark.stosberg.com/





More information about the cgiapp mailing list