package Foo;
my $_private = sub { ... };
my _private = sub { ... };
sub foo {
my $self = shift;
# we can specify the full package name
$self->Foo::_private();
# we can call as a subroutine
_private($self);
# we can use lexically scoped subs
$self->$_private();
};
####
package Foo;
sub Foo::private::method { ... };
sub foo {
my $self = shift;
$self->Foo::private::method { ... };
};
##
##
sub Foo::MY::method { ... };
sub foo {
my $self = shift;
$self->MY::method();
};
##
##
package MY;
sub AUTOLOAD {
my $self = shift;
our $AUTOLOAD;
my $method = caller() . "::$AUTOLOAD";
$self->$method(@_);
};
##
##
sub MY::method { ... };
##
##
sub MyLongPackageName::MY::method { ... };
##
##
package MY;
use strict;
use warnings;
my $Imported_from;
sub import { $Imported_from = caller };
use Filter::Simple;
FILTER_ONLY code => sub { s/(\w+::)*MY::/${Imported_from}::MY::/gs };
1;
##
##
package Foo;
use MY;
sub new { bless {}, shift };
sub hello {
my $self = shift;
$self->MY::greet_world("hi");
};
sub MY::greet_world {
my ($self, $greeting) = @_;
print "$greeting world\n";
};
package Bar;
use base qw(Foo);
use MY;
sub new {
my $class = shift;
$class->MY::greet_world();
return $class->SUPER::new(@_);
};
sub MY::greet_world {
print "A new Bar has entered the world\n";
};