tadman has asked for the wisdom of the Perl Monks concerning the following question:

It doesn't seem to be specified in the documentation, but apparently there are ordering issues with Exporter:
use Foo qw[ baz :bar ]; # ERROR: ":bar" not exported use Foo qw[ :bar baz ]; # OK
Did I miss the part where they talk about having to put your sets first? Either way, this seems to be an oversight in Exporter::Heavy.

What about this patch?
*** Heavy.pm Wed May 15 19:38:18 2002 --- /usr/local/lib/perl5/5.6.1/Exporter/Heavy.pm Wed May 15 19:35:5 +1 2002*************** *** 36,48 **** } } ! if ($imports[0] =~ m#^[/!:]#){ my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; my $tagdata; my %imports; my($remove, $spec, @names, @allexports); # negated first item implies starting with default set: ! unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; foreach $spec (@imports){ $remove = $spec =~ s/^!//; --- 54,66 ---- } } ! if (grep {m#^[/!:]#} @imports){ my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; my $tagdata; my %imports; my($remove, $spec, @names, @allexports); # negated first item implies starting with default set: ! unshift @imports, ':DEFAULT' if (grep{m/^!/} @imports); foreach $spec (@imports){ $remove = $spec =~ s/^!//;
Is this making it worse, or is this already patched in the more recent versions?

Replies are listed 'Best First'.
Re: Exporter::Heavy Ordering Shenanigans?
by IlyaM (Parson) on May 16, 2002 at 05:46 UTC
    From perldoc Exporter:

    If the first entry in an import list begins with !, : or / then the list is treated as a series of specifications which either add to or delete from the list of names to import. They are processed left to right.

    So it is documented but probably not very clearly. On the other hand I fail to see why it should be this way. IMHO it is not Perlish (i.e. it is no DWIM). I've been biten by it myself. Once I spent about an hour trying to understand what the hell is going on and why I can't get Exporter work when I placed :foobar at the end of the import list.

    --
    Ilya Martynov (http://martynov.org/)

Re: Exporter::Heavy Ordering Shenanigans?
by chromatic (Archbishop) on May 16, 2002 at 03:55 UTC
    It's not patched in the recent versions, and I don't know if that's the right fix. If I did, I'd probably drop the second change. The comment seems fairly important.
      I don't expect that this would be encountered frequently, but you would get unusual behaviour if you did something like:
      use Foo qw[ :bar !:frank ];
      The boolean logic here is kind of fuzzy, so YMMV.

      The second change was one of those "It Seemed Like A Good Idea At The Time" things, so you're probably right.