Sjis
view release on metacpan or search on metacpan
lib/Esjis.pm view on Meta::CPAN
$quotemeta .= quotemeta $char;
}
}
return $quotemeta;
}
#
# via File::HomeDir::Windows 1.00
#
sub my_home_MSWin32 {
# A lot of unix people and unix-derived tools rely on
# the ability to overload HOME. We will support it too
# so that they can replace raw HOME calls with File::HomeDir.
if (exists $ENV{'HOME'} and $ENV{'HOME'}) {
return $ENV{'HOME'};
}
# Do we have a user profile?
elsif (exists $ENV{'USERPROFILE'} and $ENV{'USERPROFILE'}) {
return $ENV{'USERPROFILE'};
}
# Some Windows use something like $ENV{'HOME'}
elsif (exists $ENV{'HOMEDRIVE'} and exists $ENV{'HOMEPATH'} and $ENV{'HOMEDRIVE'} and $ENV{'HOMEPATH'}) {
return join '', $ENV{'HOMEDRIVE'}, $ENV{'HOMEPATH'};
}
return undef;
}
#
# via File::HomeDir::MacOS9 1.00
#
sub my_home_MacOS {
# Try for $ENV{'HOME'} if we have it
if (defined $ENV{'HOME'}) {
return $ENV{'HOME'};
}
### DESPERATION SETS IN
# We could use the desktop
SCOPE: {
local $@;
CORE::eval {
# Find the desktop via Mac::Files
local $SIG{'__DIE__'} = '';
CORE::require Mac::Files;
my $home = Mac::Files::FindFolder(
Mac::Files::kOnSystemDisk(),
Mac::Files::kDesktopFolderType(),
);
return $home if $home and Esjis::d($home);
};
}
# Desperation on any platform
SCOPE: {
# On some platforms getpwuid dies if called at all
local $SIG{'__DIE__'} = '';
my $home = CORE::eval q{ (getpwuid($<))[7] };
return $home if $home and Esjis::d($home);
}
croak "Could not locate current user's home directory";
}
#
# via File::HomeDir::Unix 1.00
#
sub my_home {
my $home;
if (exists $ENV{'HOME'} and defined $ENV{'HOME'}) {
$home = $ENV{'HOME'};
}
# This is from the original code, but I'm guessing
# it means "login directory" and exists on some Unixes.
elsif (exists $ENV{'LOGDIR'} and $ENV{'LOGDIR'}) {
$home = $ENV{'LOGDIR'};
}
### More-desperate methods
# Light desperation on any (Unixish) platform
else {
$home = CORE::eval q{ (getpwuid($<))[7] };
}
# On Unix in general, a non-existant home means "no home"
# For example, "nobody"-like users might use /nonexistant
if (defined $home and ! Esjis::d($home)) {
$home = undef;
}
return $home;
}
#
# ShiftJIS file lstat (with parameter)
#
sub Esjis::lstat(*) {
local $_ = shift if @_;
if (-e $_) {
return CORE::lstat _;
}
elsif (_MSWin32_5Cended_path($_)) {
# Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Esjis::lstat()
# on Windows opens the file for the path which has 5c at end.
# (and so on)
local *MUST_BE_BAREWORD_AT_HERE;
if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
if (wantarray) {
my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
return @stat;
}
else {
my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
return $stat;
}
}
}
return wantarray ? () : undef;
}
#
# ShiftJIS file lstat (without parameter)
#
sub Esjis::lstat_() {
if (-e $_) {
return CORE::lstat _;
}
elsif (_MSWin32_5Cended_path($_)) {
local *MUST_BE_BAREWORD_AT_HERE;
if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
if (wantarray) {
my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
return @stat;
}
else {
( run in 1.946 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )