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";
In reply to "use" modifier code via import() by pbeckingham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |