Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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
|
|