package Private; use Exporter; @ISA = 'Exporter'; @EXPORT = 'is_private'; use strict; use warnings; use Carp; sub is_private() { my %c0; @c0{qw( pkg fn l sub )} = caller 0; my %c1; @c1{qw( pkg fn l sub )} = caller 1; if ( $c0{'pkg'} ne $c1{'pkg'} ) # throw an exception: { my %c2; @c2{qw( pkg fn l sub )} = caller 2; my $caller = $c2{'sub'} || $c2{'pkg'} || 'main'; croak "$caller cannot call $c1{'sub'} (private to $c0{'pkg'})"; } } 1;