I have asked before ("use" modifiers) about modifying the use statement for a module, as in:

use Test::More tests => 5;
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:
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;
And now I can use this module and override $value if I wish:
#! /usr/bin/perl -w use strict; use sample value => 5; print sub1() , "\n";
Thank you.


In reply to "use" modifier code via import() by pbeckingham

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.