use strict; use warnings; { package Foo; my $private = sub { my $self = shift; print "From $self: @_\n" }; sub public { my $self = shift; $self->$private( @_ ); } } ( bless [], 'Foo' )->public( 'Howdy!' ); __END__ From Foo=ARRAY(0x816cc20): Howdy! #### use strict; use warnings; { package Foo; sub restricted { die "Calling this method from external code is STRONGLY deprecated\n" unless __PACKAGE__ eq caller; my $self = shift; print "From $self: @_\n" }; sub public { my $self = shift; $self->restricted( @_ ); } } my $foo = bless [], 'Foo'; $foo->public( 'Howdy!' ); $foo->restricted( 'Hey wassup!' ); __END__ From Foo=ARRAY(0x816cc20): Howdy! Calling this method from external code is STRONGLY deprecated #### { package Foo; $foo->restricted( 'Hey wassup!' ); } __END__ From Foo=ARRAY(0x816cc20): Howdy! From Foo=ARRAY(0x816cc20): Hey wassup! #### use strict; { package Foo; sub terfuge { die "DON'T YOU BE CALLIN' THIS HERE METHOD, DANG IT!!!\n" unless __FILE__ . __PACKAGE__ eq join '', ( caller )[ 1, 0 ]; my $self = shift; print "From $self: @_\n" }; sub public { my $self = shift; $self->terfuge( @_ ); } } 1; #### use strict; use warnings; use Foo; my $foo = bless [], 'Foo'; $foo->public( 'Howdy!' ); { package Foo; $foo->terfuge( 'Hey wassup!' ); } __END__ From Foo=ARRAY(0x816cc20): Howdy! DON'T YOU BE CALLIN' THIS HERE METHOD, DANG IT!!!