NAME

OP::Utility

DESCRIPTION

System functions required globally by OP

SYNOPSIS

use OP::Utility;

ENVIRONMENT

Using this module will enable backtraces for all warns and fatals. The messages are informative and nicely formatted, but can be quite verbose. To disable them, set the environment variable OP_QUIET to 1.

FUNCTIONS

  • grabLock($lockName, [$timeout], [$lockType]);

    Acquire a lock, keyed using the received name. Optionally accepts a timeout value as a second argument, and a lock type (as string) as third argument (e.g. "LOCK_SH", "LOCK_EX"). If no lock type is specified, an exclusive lock is used. Returns an IO::File object, or throws a warn and returns undef if a lock could not be acquired.

  • releaseLock($lock);

    Release the received resource back to the system.

  • humanSize($seconds, [$optionalSuffix]);

    Convert the received byte count to something more human-readable (eg Kilo, Mega, Giga). Optionally acceps a second argument to use as a "suffix" to the label, otherwise the word "Bytes" is used.

  • humanTime($seconds);

    Convert the received number of seconds into something more human-readable (eg Minutes, Hours, Years)

  • loadYaml($path);

    Load the YAML file at the specified path into a native Perl data structure.

  • randstr()

    Return a random 6-byte alphabetic string

  • timestamp([$time])

    Return the received unix epoch seconds as YYYY-MM-DD HH:MM:DD. Uses the current time if none is provided.

  • date([$time]);

    Return the received unix epoch seconds as YYYY-MM-DD. Uses the current time if none is provided.

  • time([$time]);

    Return the received unix epoch seconds as hh:mm:ss. Uses the current time if none is provided.

  • hour([$time]);

    Return the received unix epoch seconds as the current hour of the day. Uses the current time if none is provided.

  • decodeExitStatus($status);

    Decodes the status ($?) from running perl's system(). Returns exit code, signal, and core dump true/false

  • cleanupMutexes()

    Perform a housekeeping sweep of mutex files.

  • newId();

    Return a new alpha-numeric ID (GUID).

  • geturl($url, [$timeout]);

    Returns the content from the received URL; accepts an optional timeout as a second value. Warns and returns undef on failure.

  • warnHandler([$exception])

    Pretty-print a warning to STDERR

  • dieHandler([$exception])

    Pretty-print a fatal error to STDERR

  • formatErrorString($errStr)

    Backtrace formatter called by error printing functions.

SEE ALSO

This file is part of OP.

REVISON

$Id: //depotit/tools/source/snitchd-0.20/lib/OP/Utility.pm#7 $