Beefy Boxes and Bandwidth Generously Provided by pair Networks
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... =)

Update

Just 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
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


In reply to Re: Making it clearer to say that a sub is defined within current package by LanX
in thread Making it clearer to say that a sub is defined within current package by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-19 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found