| 1 | #!/usr/bin/env perl | ||
| 2 | ###################################################################### | ||
| 3 | # | ||
| 4 | # batsh.pl - command-line launcher for BATsh | ||
| 5 | # | ||
| 6 | # Copyright (c) 2026 INABA Hitoshi <ina.cpan@gmail.com> | ||
| 7 | # | ||
| 8 | # Installed via EXE_FILES so that "batsh.pl script.batsh" works after | ||
| 9 | # "make install" (ExtUtils::MakeMaker creates a .bat wrapper on Win32). | ||
| 10 | # The process exit code is the script's exit code. | ||
| 11 | # | ||
| 12 | # COMPATIBILITY: Perl 5.005_03 and later | ||
| 13 | # | ||
| 14 | ###################################################################### | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | BEGIN { if ($] < 5.006 && !defined(&warnings::import)) { | ||
| 18 | $INC{'warnings.pm'} = 'stub'; eval 'package warnings; sub import {}' } } | ||
| 19 | use warnings; local $^W = 1; | ||
| 20 | BEGIN { pop @INC if $INC[-1] eq '.' } | ||
| 21 | |||
| 22 | # Prefer the sibling lib/ when run from an unpacked distribution | ||
| 23 | # (perl bin/batsh.pl ...); an installed BATsh is found via @INC as usual. | ||
| 24 | # | ||
| 25 | # The sibling directory is added only when the parent really is an | ||
| 26 | # unpacked BATsh distribution, which is what MANIFEST next to it means. | ||
| 27 | # An unconditional "use lib" would, once this script is installed into | ||
| 28 | # (say) /usr/local/bin, put /usr/local/lib at the head of @INC on every | ||
| 29 | # run; a stale or unrelated BATsh.pm left in that directory would then | ||
| 30 | # shadow the copy that was just installed. Testing only for the module | ||
| 31 | # would not help, since that is exactly the case that goes wrong. | ||
| 32 | use FindBin (); | ||
| 33 | BEGIN { | ||
| 34 | my $root = "$FindBin::Bin/.."; | ||
| 35 | my $devlib = "$root/lib"; | ||
| 36 | if (-e "$root/MANIFEST" && -e "$devlib/BATsh.pm") { | ||
| 37 | require lib; | ||
| 38 | lib->import($devlib); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | use BATsh; | ||
| 43 | |||
| 44 | exit(BATsh->main(@ARGV)); | ||
| 45 | |||
| 46 | __END__ |