in reply to (tye)Re2: Why doesn't @EXPORT = (keys %METHODS) work?
in thread Why doesn't @EXPORT = (keys %METHODS) work?

Obviously I wouldn't advocate obvious mistakes. For this code my preference would look something like this:
package Example; use Exporter; @ISA = 'Exporter'; $VERSION = 1.02; use strict; use vars qw(@EXPORT_OK); my %METHODS = ( foo => 'bar', bo => 'baz', ); @EXPORT_OK = (keys %METHODS); foreach my $method (keys %METHODS) { no strict 'refs'; *$method = sub { return $METHODS{ $method }; }; } 1;
Move strict after all bog standard headers, but leave it before any complex logic. And, of course, where you need to, remove it. In this case 2 of 3 variables didn't need to be declared.

As for your objection about needing to use it, if you actually need to use it (as here) then of course it goes into a vars. But I find that 90% of the time the standard variables that you need for inheritance, Exporter, and versioning really shouldn't appear a second time. I see no need to spend effort making it possible unless I need to. And note the detail that if you have a typo on these standard variables, then warnings will catch it. So spelling isn't an issue.

As for the stupid mistakes that you refer to, we went through that before and there was not one you could find that I agreed on. Basically my attitude is that if you get in the habit of not playing unnecessarily cute games, then those mistakes don't happen. Plus your games wind up confusing other tools, like Carp. Trying to counteract one trick with another is something that I prefer to avoid.

Replies are listed 'Best First'.
(tye)Re3: Why doesn't @EXPORT = (keys %METHODS) work?
by tye (Sage) on Mar 18, 2001 at 22:07 UTC

    You should check your assertion that mispellings of the standard variables will be caught by warnings when you play your latest "cute game". q-: Some will, some won't. See my example if you need specific ideas. ;)

    I meant to add that I can understand not wanting to worry about such stupid mistakes. I didn't want to rehash the argument. (:

            - tye (but my friends call me "Tye")