Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

There's no real difference between the two solutions you provide,

The difference is real enough. One of the variants has multiple non-obvious modes of failure.

First of all, the difference is that sub Package::func { ... } compiles the function in the current package and places it in the target package, whereas { package Package; sub func { ... } } compiles the function in the target package. There are a few issues with using sub Package::func { ... }:

It causes a problem when Carp is used. Carp will treat the function as belonging in the current package (main in this case), while it should treat it as being part of the target package to properly identify the caller.

It causes a problem when the function imports symbols. The symbols will be placed in the current pacakge while they should be placed in the target package.

It causes a problem when bless is used with one argument in the function. It will bless objects into the current package while they should be blessed into the target package.

It causes __PACKAGE__ to be the name of the current package instead of the name of the target package.


In reply to Re^2: Reopen a class, add methods ? by ikegami
in thread Reopen a class, add methods ? by Rudif

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 imbibing at the Monastery: (5)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found