Created
May 19, 2010 17:09
-
-
Save gardejo/406552 to your computer and use it in GitHub Desktop.
Let's try to build a home-brew path as an equivalent of $FindBin::Bin!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When your script dies at an "use FindBin" line on Win32 environment (because the "5C Problem"), | |
# let's try to build a home-brew path as an equivalent of $FindBin::Bin! | |
use 5.008_001; # For modern support to multi-byte languages. | |
# Rational ClearCase 7 contains ratlperl(ccperl) 5.008_006. | |
use strict; | |
use warnings; | |
use utf8; | |
use Encode qw(encode_utf8 find_encoding); | |
use File::Spec; | |
my ($encoding, $root_directory); | |
BEGIN { | |
exit | |
unless caller(); | |
$encoding = find_encoding('cp932'); | |
# Get an equivalent of "%~dp0" on Win32 shell script. | |
my ($volume, $directories, undef) | |
= File::Spec->splitpath( $encoding->decode( ( caller() )[1] ) ); | |
$root_directory = File::Spec->abs2rel( | |
File::Spec->canonpath | |
( File::Spec->catpath($volume, $directories, File::Spec->updir) ) | |
); | |
$root_directory = File::Spec->curdir | |
if $root_directory eq q{}; | |
} | |
use lib ( | |
$encoding->encode( File::Spec->catdir($root_directory, 'lib' ) ), | |
$encoding->encode( File::Spec->catdir($root_directory, 'extlib') ), | |
); | |
use Some::NonCore::Module; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also:
http://twitter.com/gardejo/status/14305974123
http://twitter.com/gardejo/status/14306083909