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/local_package.pl xyz called at d:/exp/local_package.pl line 6. Undefined subroutine &my::xyz called at d:/exp/local_package.pl line 3 +0.

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

update

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"

Update

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.