perlのパッケージ名はただの文字列
4人のperl mongerのなかでアホなことを聞いて教えてもらった。
パッケージ名はただの文字列なので全体をスカラー変数に入れてnewすればふつうにnewできる。
package Animal::Cow; sub new { my $class = shift; $class = ref $class if ref $class; my $self = bless {}, $class; $self; } sub hello { "moooo"; } package main; $klass = "Animal::Cow"; print $klass->new->hello; # "moooo"