First of all I should note that Exporter offers export_fail which can be used for the same purpose. You can glance at the implementation of Carp to see how you might use it.

In the past (particularly with Perl 5.6) I've noticed that export_to_level does not work exactly like you would want. (It reports errors at the wrong level.) Therefore this alternate strategy may be more reliable.

I also notice that you are using prototypes in your definition of sub1. There was an excellent article on perl.com explaining prototypes in Perl and demonstrating why they are problematic. Unfortunately the link to it isn't working very well at the moment, so I can't direct you to read that article. But I can assure you that if your understanding of prototypes are shaped by prototypes in any other language, that Perl's version of the same is pretty definitely not what you want, and you're better off forgetting that you ever heard about them.

I also have to second perrin's comment. While playing around with export semantics can achieve all sorts of cool effects, unless it is really important for what your module does, it is better programming practice to stick to normal export semantics and not overload your export semantics.


In reply to Re: "use" modifier code via import() by tilly
in thread "use" modifier code via import() by pbeckingham

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.