Big5HKSCS

 view release on metacpan or  search on metacpan

lib/Ebig5hkscs.pm  view on Meta::CPAN

    }
    return @piece;
}

#
# Big5-HKSCS parse path
#
sub _parse_path {

    my($path,$pathsep) = @_;

    $path .= '/';
    my @subpath = ();
    while ($path =~ /
        ((?: [^\x81-\xFE\/\\]|[\x81-\xFE][\x00-\xFF] )+?) [\/\\]
        /oxmsg
    ) {
        push @subpath, $1;
    }

    my $tail = pop @subpath;
    my $head = join $pathsep, @subpath;
    return $head, $tail;
}

#
# 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::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 ! Ebig5hkscs::d($home)) {
        $home = undef;
    }
    return $home;
}

#
# Big5-HKSCS file lstat (with parameter)
#
sub Ebig5hkscs::lstat(*) {

    local $_ = shift if @_;

    if (-e $_) {
        return CORE::lstat _;
    }
    elsif (_MSWin32_5Cended_path($_)) {

        # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Ebig5hkscs::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;
}

#
# Big5-HKSCS file lstat (without parameter)
#
sub Ebig5hkscs::lstat_() {

    if (-e $_) {
        return CORE::lstat _;

lib/Ebig5hkscs.pm  view on Meta::CPAN

  that $code in the character set. For example, Ebig5hkscs::chr(65) is "A" in either
  ASCII or Big5-HKSCS, not Unicode. For the reverse of Ebig5hkscs::chr, use Big5HKSCS::ord.

=item * File test subroutine Ebig5hkscs::X

  The following all subroutines function when the pathname ends with chr(0x5C) on
  MSWin32.

  A file test subroutine is a unary function that takes one argument, either a
  filename or a filehandle, and tests the associated file to see whether something
  is true about it. If the argument is omitted, it tests $_. Unless otherwise
  documented, it returns 1 for true and "" for false, or the undefined value if
  the file doesn't exist or is otherwise inaccessible. Currently implemented file
  test subroutines are listed in:

  Available in MSWin32, MacOS, and UNIX-like systems
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::r(*), Ebig5hkscs::r_()   File or directory is readable by this (effective) user or group
  Ebig5hkscs::w(*), Ebig5hkscs::w_()   File or directory is writable by this (effective) user or group
  Ebig5hkscs::e(*), Ebig5hkscs::e_()   File or directory name exists
  Ebig5hkscs::x(*), Ebig5hkscs::x_()   File or directory is executable by this (effective) user or group
  Ebig5hkscs::z(*), Ebig5hkscs::z_()   File exists and has zero size (always false for directories)
  Ebig5hkscs::f(*), Ebig5hkscs::f_()   Entry is a plain file
  Ebig5hkscs::d(*), Ebig5hkscs::d_()   Entry is a directory
  ------------------------------------------------------------------------------
  
  Available in MacOS and UNIX-like systems
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::R(*), Ebig5hkscs::R_()   File or directory is readable by this real user or group
                             Same as Ebig5hkscs::r(*), Ebig5hkscs::r_() on MacOS
  Ebig5hkscs::W(*), Ebig5hkscs::W_()   File or directory is writable by this real user or group
                             Same as Ebig5hkscs::w(*), Ebig5hkscs::w_() on MacOS
  Ebig5hkscs::X(*), Ebig5hkscs::X_()   File or directory is executable by this real user or group
                             Same as Ebig5hkscs::x(*), Ebig5hkscs::x_() on MacOS
  Ebig5hkscs::l(*), Ebig5hkscs::l_()   Entry is a symbolic link
  Ebig5hkscs::S(*), Ebig5hkscs::S_()   Entry is a socket
  ------------------------------------------------------------------------------
  
  Not available in MSWin32 and MacOS
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::o(*), Ebig5hkscs::o_()   File or directory is owned by this (effective) user
  Ebig5hkscs::O(*), Ebig5hkscs::O_()   File or directory is owned by this real user
  Ebig5hkscs::p(*), Ebig5hkscs::p_()   Entry is a named pipe (a "fifo")
  Ebig5hkscs::b(*), Ebig5hkscs::b_()   Entry is a block-special file (like a mountable disk)
  Ebig5hkscs::c(*), Ebig5hkscs::c_()   Entry is a character-special file (like an I/O device)
  Ebig5hkscs::u(*), Ebig5hkscs::u_()   File or directory is setuid
  Ebig5hkscs::g(*), Ebig5hkscs::g_()   File or directory is setgid
  Ebig5hkscs::k(*), Ebig5hkscs::k_()   File or directory has the sticky bit set
  ------------------------------------------------------------------------------

  The tests -T and -B takes a try at telling whether a file is text or binary.
  But people who know a lot about filesystems know that there's no bit (at least
  in UNIX-like operating systems) to indicate that a file is a binary or text file
  --- so how can Perl tell?
  The answer is that Perl cheats. As you might guess, it sometimes guesses wrong.

  This incomplete thinking of file test operator -T and -B gave birth to UTF8 flag
  of a later period.

  The Ebig5hkscs::T, Ebig5hkscs::T_, Ebig5hkscs::B, and Ebig5hkscs::B_ work as follows. The first block
  or so of the file is examined for strange chatracters such as
  [\000-\007\013\016-\032\034-\037\377] (that don't look like Big5-HKSCS). If more
  than 10% of the bytes appear to be strange, it's a *maybe* binary file;
  otherwise, it's a *maybe* text file. Also, any file containing ASCII NUL(\0) or
  \377 in the first block is considered a binary file. If Ebig5hkscs::T or Ebig5hkscs::B is
  used on a filehandle, the current input (standard I/O or "stdio") buffer is
  examined rather than the first block of the file. Both Ebig5hkscs::T and Ebig5hkscs::B
  return 1 as true on an empty file, or on a file at EOF (end-of-file) when testing
  a filehandle. Both Ebig5hkscs::T and Ebig5hkscs::B doesn't work when given the special
  filehandle consisting of a solitary underline. Because Ebig5hkscs::T has to read to
  do the test, you don't want to use Ebig5hkscs::T on special files that might hang or
  give you other kinds or grief. So on most occasions you'll want to test with a
  Ebig5hkscs::f first, as in:

  next unless Ebig5hkscs::f($file) && Ebig5hkscs::T($file);

  Available in MSWin32, MacOS, and UNIX-like systems
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::T(*), Ebig5hkscs::T_()   File looks like a "text" file
  Ebig5hkscs::B(*), Ebig5hkscs::B_()   File looks like a "binary" file
  ------------------------------------------------------------------------------

  File ages for Ebig5hkscs::M, Ebig5hkscs::M_, Ebig5hkscs::A, Ebig5hkscs::A_, Ebig5hkscs::C, and Ebig5hkscs::C_
  are returned in days (including fractional days) since the script started running.
  This start time is stored in the special variable $^T ($BASETIME). Thus, if the
  file changed after the script, you would get a negative time. Note that most time
  values (86,399 out of 86,400, on average) are fractional, so testing for equality
  with an integer without using the int function is usually futile. Examples:

  next unless Ebig5hkscs::M($file) > 0.5;     # files are older than 12 hours
  &newfile if Ebig5hkscs::M($file) < 0;       # file is newer than process
  &mailwarning if int(Ebig5hkscs::A_) == 90;  # file ($_) was accessed 90 days ago today

  Available in MSWin32, MacOS, and UNIX-like systems
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::M(*), Ebig5hkscs::M_()   Modification age (measured in days)
  Ebig5hkscs::A(*), Ebig5hkscs::A_()   Access age (measured in days)
                             Same as Ebig5hkscs::M(*), Ebig5hkscs::M_() on MacOS
  Ebig5hkscs::C(*), Ebig5hkscs::C_()   Inode-modification age (measured in days)
  ------------------------------------------------------------------------------

  The Ebig5hkscs::s, and Ebig5hkscs::s_ returns file size in bytes if succesful, or undef
  unless successful.

  Available in MSWin32, MacOS, and UNIX-like systems
  ------------------------------------------------------------------------------
  Subroutine and Prototype   Meaning
  ------------------------------------------------------------------------------
  Ebig5hkscs::s(*), Ebig5hkscs::s_()   File or directory exists and has nonzero size
                             (the value is the size in bytes)
  ------------------------------------------------------------------------------



( run in 0.692 second using v1.01-cache-2.11-cpan-5511b514fd6 )