Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is pretty clean, put your private stuff into a sub-package and alias that long package path it to a shorter package name at compile time.

(of course these subs won't be able to call imported subs in the parent package without full qualification or inheritance ;-)

use strict; use warnings; package X::Y::Z::my; # sub package sub xyz {warn "xyz called" } package Y::Y::Z; BEGIN { *::my:: = *X::Y::Z::my:: ; # alias sub package to my:: } # END { # delete alias at file's end # delete $::{"my::"}; # } my::xyz(); BEGIN { # delete alias here for demo delete $::{"my::"}; } package Other; my::xyz(); # fails alias already gone

C:/Perl_524/bin\perl.exe d:/exp/ xyz called at d:/exp/ line 6. Undefined subroutine &my::xyz called at d:/exp/ line 3 +0.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


the magic in the BEGIN/END blocks could be done in the importer of a module called with

use  PackageAlias "X::Y:Z::my" => "my" and no PackageAlias "my"


I just realised that Package::Alias already exists, even with a pretty similar interface.

Skipped colons in my example to avoid confusion.

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

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-07-01 10:33 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.