Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to a construct objects with variables as class names?

by Adam (Vicar)
on Feb 14, 2001 at 11:16 UTC ( [id://58303]=note: print w/replies, xml ) Need Help??


in reply to How to a construct objects with variables as class names?

The problem looks to be with your call to new(). When you don't have new() defined in the current name space, and you call
new class, @args
Perl guesses that class::new() is defined and tries that. But you havn't given it a class name, you've given it a variable. You might try
$class->new( @args )
I've had some luck with that in the past. By the way, 'pointy' is the preferable way to invoke methods on objects and classes, as it eliminates the uncertainty of who's method is being called. Also, make sure that $class has been required, and actually is compiled.

Replies are listed 'Best First'.
Re: Re: How to a construct objects with variables as class names?
by joecamel (Hermit) on Feb 14, 2001 at 11:32 UTC
    Thanks Adam,

    I changed the method to the following, which worked perfectly:

    my $fullClass = "SuperWidget::Widget::" . $className; my $widget = $fullClass->new($widgetID);
    I normally use the -> operator for method calls, but figured the only way to dynamically name an object was with the new class (@args) format.

    joecamel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://58303]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found