[Israel.pm] symbolic references and class names
Ephraim Dan
E.Dan at F5.com
Wed Feb 28 06:10:35 PST 2007
Here's some example code:
use Data::Dumper qw/Dumper/;
package Obj;
sub new {
my $class = shift;
return bless { @_ }, $class;
}
package Factory;
sub create {
my $class = shift;
return $class->new( @_ );
}
package main;
print Dumper Factory::create( 'Obj', arg1 => 123, arg2 => 456 );
__END__
-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Yossi Itzkovich
Sent: Monday, February 26, 2007 13:07
To: Perl at perl.org.il
Subject: [Israel.pm] symbolic references and class names
Hi,
I would like to write a method that gets class name as a parameter and
creates an object of this class with a parameter.
For example, for class MyClass I should have something like:
sub factory
{
my ($className,$param)=@_;
my $returnValue= new {$className}($param);
}
This syntax doesn't work, and I can't find something that works. Can
someone help me?
Thanks
Yossi
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl
More information about the Perl
mailing list