pbeckingham has asked for the wisdom of the Perl Monks concerning the following question:
I have asked before ("use" modifiers) about modifying the use statement for a module, as in:
I wondered how it was done. Now I have a working version of this, I would like critique, in order to improve or fix it. Specifically, I want to know if the sub import is good - the sample sub1 is irrelevant. Here is the code:use Test::More tests => 5;
And now I can use this module and override $value if I wish:package sample; our $value = 0; use strict; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(sub1); sub import { my @imports; while (my $arg = shift) { if ($arg eq 'value') { $value = shift; next; } push @imports, $arg; } sample->export_to_level (1, @imports); } sub sub1 () {$value + 1} 1;
Thank you.#! /usr/bin/perl -w use strict; use sample value => 5; print sub1() , "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "use" modifier code via import()
by tilly (Archbishop) on May 17, 2004 at 22:32 UTC | |
by pbeckingham (Parson) on May 18, 2004 at 00:43 UTC | |
by tilly (Archbishop) on May 18, 2004 at 01:29 UTC | |
|
Re: "use" modifier code via import()
by perrin (Chancellor) on May 17, 2004 at 21:06 UTC | |
by pbeckingham (Parson) on May 18, 2004 at 00:22 UTC | |
by tilly (Archbishop) on May 18, 2004 at 00:37 UTC | |
by perrin (Chancellor) on May 18, 2004 at 01:10 UTC | |
by tye (Sage) on May 18, 2004 at 02:04 UTC | |
by perrin (Chancellor) on May 18, 2004 at 03:17 UTC | |
| |
|
Re: "use" modifier code via import()
by Solo (Deacon) on May 18, 2004 at 13:30 UTC | |
|
Re: "use" modifier code via import()
by TomDLux (Vicar) on May 17, 2004 at 20:59 UTC |