$ perl -Mstrict -E 'use warnings; my $x; say $x+1' Use of uninitialized value $x in addition (+) at -e line 1. 1 $ perl -Mstrict -E 'use warnings (); my $x; say $x+1' 1 #### $ perl -Mstrict -E 'use if 1==1, warnings => (); my $x; say $x+1' Use of uninitialized value $x in addition (+) at -e line 1. 1 #### $ perl -Mstrict -E 'BEGIN { require warnings if 1==1 } my $x; say $x+1' 1 #### $ perl -MO=Deparse,-p -e 'use if 1==1, warnings => ()' use if (1, 'warnings', ()); -e syntax OK $ perl -Mstrict -E 'use if (1, "warnings", ()); my $x; say $x+1' Use of uninitialized value $x in addition (+) at -e line 1. 1 #### $ perl -wMstrict -E 'use open ()' $ perl -wMstrict -E 'use if 1==1, open => ()' open: needs explicit list of PerlIO layers at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -wMstrict -E 'use feature ()' $ perl -wMstrict -E 'use if 1==1, feature => ()' No features specified at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -wMstrict -E 'use List::Util ()' $ perl -wMstrict -E 'use if 1==1, List::Util => ()' Bareword "List::Util" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. #### package if; $VERSION = '0.0606'; sub work { my $method = shift() ? 'import' : 'unimport'; unless (@_ >= 2) { my $type = ($method eq 'import') ? 'use' : 'no'; die "Too few arguments to '$type if' (some code returning an empty list in list context?)" } return unless shift; # CONDITION my $p = $_[0]; # PACKAGE (my $file = "$p.pm") =~ s!::!/!g; require $file; # Works even if $_[0] is a keyword (like open) my $m = $p->can($method); goto &$m if $m; } sub import { shift; unshift @_, 1; goto &work } sub unimport { shift; unshift @_, 0; goto &work } 1; #### $ perl -wMstrict -E '@_ = (1, 2, ()); say 0+@_' 2 #### use if CONDITION, MODULE => (); #### use if CONDITION, MODULE;