in reply to Making it clearer to say that a sub is defined within current package
This is pretty clean, put your private stuff into a sub-package and alias that long package path it to a shorter package name at compile time.
(of course these subs won't be able to call imported subs in the parent package without full qualification or inheritance ;-)
use strict; use warnings; package X::Y::Z::my; # sub package sub xyz {warn "xyz called" } package Y::Y::Z; BEGIN { *::my:: = *X::Y::Z::my:: ; # alias sub package to my:: } # END { # delete alias at file's end # delete $::{"my::"}; # } my::xyz(); BEGIN { # delete alias here for demo delete $::{"my::"}; } package Other; my::xyz(); # fails alias already gone
C:/Perl_524/bin\perl.exe d:/exp/local_package.pl xyz called at d:/exp/local_package.pl line 6. Undefined subroutine &my::xyz called at d:/exp/local_package.pl line 3 +0.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
update
the magic in the BEGIN/END blocks could be done in the importer of a module called with
use PackageAlias "X::Y:Z::my" => "my" and no PackageAlias "my"
Update
I just realised that Package::Alias already exists, even with a pretty similar interface.
Skipped colons in my example to avoid confusion.
|
---|
In Section
Seekers of Perl Wisdom