This probably falls under the category of Don't Do It!(tm), but what the hay.

I've seen some modules in the past that used LIST args in import to activate different defaults for the usage of that module.

For example, let's say I have a Foo module that can be set to ignore or Carp errors during the course of its lifetime. I can add a method to toggle this behaviour:

use Foo; Foo->err_raise(1); Foo->err_raise(0);
or I can use 'use' (Who's on first?) funkyness to accomplish the same:
use Foo qw(:err_raise); use Foo qw(:err_ignore);

Besides the argument of whether it should or shouldn't be done, how is that accomplished?

Is it simply a matter of overloading import, or is there a cleaner way?

package Foo; use Exporter; @ISA = qw( Exporter ); ... sub import { my ($self, @args) = @_; ... check @args for :err_raise, :err_ignore change err handling defaults remove those fake tags from @args and call the real import ... $self->export_to_level(1, @cleanargs); };

Mod -1 points: Too Much Time On My Hands


In reply to Exporter, import, and tags w/ double meanings. by jk2addict

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.