A little convention can go a long way:

$class->SUPER::import(ARRAY => __PACKAGE__.'::Work');

I personally believe that it would still amount to "double hardcoding," albeit in a more "hyerarchical" (for what that it may mean in Perl 5) and thus clean way: what if I decide to change say "::Work" to "::Tool" later?

If you want to be more fancy/flexible, you could do it like this:

Well, this is just as ugly as working with symrefs generally is ;) and somehow unsatisfactory for leaving the same sub in two namespaces. (I presume that one could go just as far as deleting it from Array::Extract, but that would be kind of an exaggeration, I admit.) Or else I may actually adopt an anonymous sub to start with:

package Array::Extract; my $worker_package = __PACKAGE__ . '::Work'; # or whatever other name +you want { no strict 'refs'; *{"$worker_package\::extract"} = sub { ... your code ... }; }

And that would be nearly the same thing in most cases: that is, unless that sub creates a closure, which after all may be what I want anyway...

The only problem I see with this approach is that instead of having a single sub like that, I may have quite a lot of them. (In which case I would probably put them into a hash and generate their package names programmatically...)

--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re^2: How not to hardcode a package name? by blazar
in thread How not to hardcode a package name? by blazar

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.