Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
But then is the cute little ::xyz(). ... Any ideas for the other packages?

Yes: xyz()

;-)

So, I thought perhaps there is another way in Perl to write xyz() to mean in this package, in order to show to the reader (and perl) that this function's source code is just below or above this line and should not open another window to search for it.

A plain xyz() always means "in this package".

Remember than when importing, for example, Other::Package::foo() into the current package This::Package, you're creating a symbol table entry This::Package::foo that just points to the original foo(). But to the code in This::Package, the symbol exists in the local This::Package symbol table!

Based on your description, I think maybe you want to differentiate between subs that come from other packages and the ones actually defined in the current package? The two typical ways to do this would be to not actually import anything (use Other::Package ();) and then call the functions explicitly (Other::Package::foo()), or an alternative would be to always list all functions imported from other packages in the use (i.e. use Other::Package qw/foo/; instead of use Other::Package;), because that would allow doing a quick search for "foo" and finding it right at the top of the file, telling the reader where it came from.

Your idea of calling subs that are defined in the current package with some kind of prefix, I would probably find kind of confusing when reading the code, because package prefixes are in my experience more commonly used when the sub comes from a different package than the current one.


In reply to Re: Making it clearer to say that a sub is defined within current package by haukex
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 exploiting the Monastery: (4)
As of 2024-04-25 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found