use v5.10; use strict; use warnings; package System::Sub::Env; use Carp qw(croak); use File::Which qw(which); use base qw(System::Sub); sub import { my $class = shift; my @super; while (@_) { my $cmd = shift; my %opt = @{ ref($_[0]) ? shift : [] }; my $env = uc("PATH_TO_$cmd"); $opt{'$0'} //= ($ENV{$env} // which($cmd)); -x $opt{'$0'} or croak("Could not find '$cmd'; please set '$env' environment variable; stopped"); push @super, $cmd => [%opt]; } @_ = ($class, @super); goto \&System::Sub::import; } 1; #### use System::Sub::Env "mv"; mv("oldname.txt" => "newname.txt");