in reply to Perl OO: switch package context.
Perl does not provide any facilities for this. There is no more relation between My::Package and My::Package::Class than there is between Foo and Bar (aside from the fact that builtins such as use and require, when asked to load My::Package::Class will look for Class.pm under subdirectories My/Package off the search path).
You could choose to live dangerously by messing with symbol tables:
but I think that such tricks would make your code confusing to anyone else but you.use strict; use warnings; package My::Package::Class; sub new { return bless +{}; } sub foo { print "hello from " . __PACKAGE__ . "::foo\n"; } package main; *Class:: = \%My::Package::Class::; my $object = Class->new(); $object->foo(); __END__ hello from My::Package::Class::foo
the lowliest monk
|
|---|