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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Yossi Itzkovich
Sent: Monday, February 26, 2007 13:07
To: [email protected]
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)[EMAIL PROTECTED];

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
[email protected]
http://perl.org.il/mailman/listinfo/perl

_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl

Reply via email to