Acme::UseStrict - use strict constantly
use Acme::UseStrict; # not in strict mode sub foo { "use strict"; # in strict mode here } sub bar { no Acme::UseStrict; "use strict"; # not in strict mode }
ECMAScript 5.1 (i.e. Javascript) introduces a "strict mode" similar in spirit to Perl's strict mode. Usually you enable Perl's strict mode like this:
use strict;
But in ECMAScript it must be a quoted string:
"use strict";
It is received wisdom that Perl has an ugly syntax, so it naturally follows that any change to make Perl's syntax closer to Javascript will be welcome.
This module allows you use use strict by simply including the string constant "use strict" anywhere in a scope.
sub do_stuff { warn "use strict"; *{"do_more_stuff"} = sub { }; # dies because of strict refs. }
But what if you'd rather have a different trigger to enable strict mode? Yes, that can be done:
use Acme::UseStrict 'complain'; sub do_stuff { my $foo = { complain => 'lots' }; *{"do_more_stuff"} = sub { }; # dies because of strict refs. }
You can even provide a regular expression:
use Acme::UseStrict qr/^(complain|whine|moan|grumble)$/i;
Or an list of values:
use Acme::UseStrict [qw/complain whine moan grumble/];
Or basically anything that works as a right-hand-side with the smart match operator.
You can disable this module for a lexical scope using:
no Acme::UseStrict;
You can check if this module is enabled:
warn Acme::UseStrict::in_effect() ? 'mind your language' : 'curse freely';
Note that this checks if this module is enabled; not if strict is enabled.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Acme-UseStrict.
https://developer.mozilla.org/en/JavaScript/Strict_mode.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2011, 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Acme::UseStrict, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::UseStrict
CPAN shell
perl -MCPAN -e shell install Acme::UseStrict
For more information on module installation, please visit the detailed CPAN module installation guide.