Solutions:
  1. Learn to love the parens.
  2. Replace your constants with lexically scoped variables.
  3. Hack up a utility module that makes what you want easy to do.
Here is a sample implementation of the third option:
package Import; sub import { shift; # I don't care about my package. my $to_call = shift; my $call_from = caller; eval qq( package $call_from; # So the import goes into the right package. $to_call\->import(\@_); ); } 1;
Call that Import.pm. And then the following little test script shows it in operation:
package Foo; BEGIN { use base Exporter; @EXPORT = "HELLO"; @EXPORT_OK = "BYE"; } use constant HELLO => "Hello, world\n"; use constant BYE => "Goodbye, cruel world\n"; package Bar; use Import "Foo"; print HELLO; package Baz; use Import qw(Foo BYE); print BYE;
OK, so you still have to put the definition of what you are willing to export into a BEGIN block. But that is one block, one place. If that bugs you, take a page from base and write a module that will set your @EXPORT and @EXPORT_OK for you in its import method.

In reply to Re (tilly) 1: Inheriting constants in the same file -- help me find a better way! by tilly
in thread Inheriting constants in the same file -- help me find a better way! by bikeNomad

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.