in reply to Making a new object of an undecided class with Moose

«Erlang::Parser::Node::Atom» in «Erlang::Parser::Node::Atom->new(atom => 'xyz');» is just a string literal. It can be any expression that produces the string «Erlang::Parser::Node::Atom» (although you might need parens around some expressions because -> binds rather tightly).

my $class = "Erlang::Parser::Node::$type"; $class->new(@args)

or even

"Erlang::Parser::Node::$type"->new(@args)

Altogether:

sub new_node { my $kind = shift; return "Erlang::Parser::Node::$kind"->new(@_); }

Replies are listed 'Best First'.
Re^2: Making a new object of an undecided class with Moose
by anneli (Pilgrim) on Oct 22, 2011 at 07:43 UTC

    Thanks! That makes things a lot more clear.