in reply to Re^2: Perl OO: switch package context.
in thread Perl OO: switch package context.

It's too late at runtime, the rest of the script already got compiled. So "Object" is taken as a bareword string literal, and nothing can change that.

As a constant is nothing but a sub, you can use a similar sub that just returns the value of a scalar. You can always change the value for the scalar.

my $class = "Gemini::Model::Object"; sub Object () { return $class; } print ref Object->new();
You can always still change the value of that scalar.

But why the obfuscation? If you want to use a variable class, just say so. Perl lets you do that.

my $class = "Gemini::Model::Object"; print ref $class->new();
Looks fine to me.