jk2addict has asked for the wisdom of the Perl Monks concerning the following question:
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:
or I can use 'use' (Who's on first?) funkyness to accomplish the same:use Foo; Foo->err_raise(1); Foo->err_raise(0);
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exporter, import, and tags w/ double meanings.
by Zaxo (Archbishop) on Sep 25, 2002 at 20:03 UTC | |
by hossman (Prior) on Sep 25, 2002 at 22:13 UTC | |
|
Re: Exporter, import, and tags w/ double meanings.
by chromatic (Archbishop) on Sep 25, 2002 at 20:16 UTC | |
|
Re: Exporter, import, and tags w/ double meanings.
by Anonymous Monk on Sep 26, 2002 at 00:07 UTC |