develooper Front page | perl.perl5.porters | Postings from October 1999

Extending Exporter's import method

Thread Next
From:
Moore, Paul
Date:
October 28, 1999 03:57
Subject:
Extending Exporter's import method
Message ID:
714DFA46B9BBD0119CD000805FC1F53BB415AD@UKRUX002.rundc.uk.origin-it.com
Hi,
I'm putting the finishing touches on my changes to File::Glob. What I'd like
to do is to extend the import() method supplied by Exporter, to take two
"special" tags, :case and :nocase, which set the case sensitivity of the
exported csh_glob() function. The idea is that use File::Glob qw(csh_glob
:nocase) will make csh_glob() case insensitive, and use File::Glob
qw(csh_glob :case) will make it case sensitive. The default will be platform
dependent.

Ideally, I'd like these to be tags (starting with a ':') to stop people
thinking they might be exported functions... (The fact that the existing
'globally' export entry does not start with a colon worries me, that it may
not be easy to do this.)

My first thought was to define my own import sub, along the lines of

    sub import {
        my $self = shift;
        my @args;
        for (@_) {
            if (/^:(no)?case$/) {
                # Do the magic
                next;
            }
            push @args, $_;
        }
        $self->SUPER::import(@args);
    }

However, this didn't work. Can anybody tell me why, and how to do what I was
trying to do? (BTW, if this works, I'd be tempted to suggest doing
'globally' the same way - it would save nasty surprises for people doing
"use File::Glob ':ALL'".

On a slightly related note, is there any reason why GLOB_CSH is omitted from
the list of exported flag values?

On another related note, could I suggest a further tag, :flags, which
exported the flags, but NOT the glob() routine?

Paul.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About