I don't recall having actually discussed your "move use strict" idea before. For this code, would it look something like this?
package Fred;
require Exporter;
@ISA = qw( Exportor );
$VERSION = 1.01;
%EXPORT_TAGS = ( 'all' => [ qw( ) ] );
@EXPORT_OK = ( @{ $EXPORT_TAG{'all'} } );
my %METHODS = (
foo => 'bar',
bo => 'baz',
);
@EXPORT = (keys %METHOD);
use strict;
foreach my $method (keys %METHODS) {
*$method = sub {
return $METHODS{ $method };
};
}
die "Use of ", __PACKAGE__, " (v$VERSION) not supported.\n"
if ! prerequisites();
1;
Note that the above code contains several mistakes but the only complaint you'll get from Perl will be a fatal error for one thing that isn't a mistake. (Hmm, I would have thought that having warnings enabled would have given you a warning about one of the real mistakes, but my testing shows otherwise.)
I guess your idea might make sense if you only ever mention each variable exactly once (the "standard" variables appear to be exempt from the "used only once" warning, so there is one more thing to worry about if you try this trick when you need any nonstandard package variables). But I still don't consider it a sound design as it is too easy to imagine future changes resulting in some of the variables actually being used within the package.
And if you use the variable as part of a standard initialization (above the use strict), then your typos are not caught. If you use the variable below the use strict, then you get a fatal compile-time error.
Note that I did suggest just removing the BEGIN block before I mentioned my personal preference, which I find makes things more robust in the face of several kinds of stupid mistakes. Not that I want to encourage such mistakes. It is just that the failure modes of those mistakes don't clearly point a finger at the mistake. Otherwise I think I'd stop that habit.
-
tye
(but my friends call me "Tye") |