There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Like I told you in the CB your "approach" doesn't even work.
Importing means aliasing into the current package, hence any function will be available. Your approach is quite inside out, it's common to import explicitly, hence use module qw/one two three/ makes it obvious, even if module is badly designed and exports one two and three by default. There is also the convention to mark private methods with a leading underscore, so _xyz() would be obvious for the reader. In order to enforce privacy you can also use private code refs like my $xyz=sub {} and dereference every call. It's not (easily) possible to import private variables so this is safe. There is AFAIK also an experimental feature to allow private sub declarations. If all of this is not enough ... Sigh.... you could hack yourself a solution, by aliasing the "local" subs to another temporary package like "_" and call _::xyz(). This export must happen at compile time and prior to any call. IIRC it's possible to use introspection to determine where a sub was declared, hence you could even automate this aliasing in a module use _ where the importer inspects the caller's stash. Brain fucked and you'll probably sabotage OOP inheritance but hey it's Perl and TIMTOWTDI... =)
UpdateJust saw Eily's post and his "My::" seems to correspond to my "_::" . Using AUTOLOAD is another option but IMHO this would come with a performance penalty.
Cheers Rolf
In reply to Re: Making it clearer to say that a sub is defined within current package
by LanX
|
|