NAME

Hardware::UPS::Perl::PID - package for OO PID files.

SYNOPSIS

use Hardware::UPS::Perl::PID;

$Pid = Hardware::UPS::Perl::PID->new();

$Pid->setLogger($Logger);
$Logger = $Pid->getLogger();

$Pid = Hardware::UPS::Perl::PID->new(
    PIDFile =>  "/var/run/ups.pid"
    Logger  =>  $Logger,
);

$pid = $Pid->getPID();
$pidFile = $Pid->getPIDFile();

$Pid->delete();

undef $Pid;                         # deletes PID file, if possible

DESCRIPTION

Hardware::UPS::Perl::PID provides methods dealing with PID files.

LIST OF METHODS

new

Name:

new - creates a new PID file object

Synopsis:
	$Logger = Hardware::UPS::Perl::Logging->new();
	$Pid    = Hardware::UPS::Perl::PID->new();

	$Pid    = Hardware::UPS::Perl::PID->new({
	    PIDFile => $file,
	    Logger  => $Logger,
    });

	undef $Pid;                    # deletes the PID file
Description:

new initializes a PID file object by writing the PID of the current process to the PID file. The PID file will be deleted, when the object is destroyed. Thus, the object created must be globally declared, otherwise the PID file will vanish when leaving the local context.

new expects the options as an anonymous hash.

Arguments:
PIDFile => $file

optional; the PID file; if not specified, the default PID file UPSPIDFILE supplied by package Hardware::UPS::Perl::Constants will be used.

Logger => $logger

optional; a Hardware::UPS::Perl::Logging object; defines a logger; if not specified, a logger sending its output to STDERR is created.

See Also:

"delete", "getPID", "getPIDFile", "getLogger", "setLogger"

setLogger

Name:

setLogger - sets the logger to use

Synopsis:
$Pid    = Hardware::UPS::Perl::PID->new();

$Logger = Hardware::UPS::Perl::Logging->new();

$Pid->setLogger($logger);
Description:

setLogger sets the logger object used for logging. setLogger returns the previous logger used.

Arguments:
$logger

required; a Hardware::UPS::Perl:Logging object; defines the logger for logging.

See Also:

"new", "getLogger"

getLogger

Name:

getLogger - gets the current logger for logging

Synopsis:
$Pid    = Hardware::UPS::Perl::PID->new();

$logger = $Pid->getLogger();
Description:

getLogger returns the current logger, a Hardware::UPS::Perl::Logging object used for logging, if defined, undef otherwise.

See Also:

"new", "setLogger"

delete

Name:

delete - deletes the PID file currently used

Synopsis:
$Pid = Hardware::UPS::Perl::PID->new();

$Pid->delete();
undef $Pid;
Description:

delete removes the PID file from the disk. This method will be called automatically, when the object is destroyed. Thus, the PID file object created by method new must be globally declared, otherwise the PID file will vanish when leaving the local context.

See Also:

"new", "getPID", "getPIDFile"

getErrorMessage

Name:

getErrorMessage - gets the internal error message

Synopsis:
$Pid = Hardware::UPS::Perl::PID->new();

unless ( $Pid->delete() ) {
    print STDERR $Pid->getErrorMessage(), "\n";
    exit 0;
}
Description:

getErrorMessage returns the internal error message, if something went wrong.

getPID

Name:

getPID - gets the current PID file

Synopsis:
$Pid = Hardware::UPS::Perl::PID->new();

$pid = $Pid->getPID();
Description:

getPID returns the current PID if available, undef otherwise.

See Also:

"new", "getPIDFile"

getPIDFile

Name:

getPIDFile - gets the current PID file

Synopsis:
$Pid = Hardware::UPS::Perl::PID->new();

$pidFile = $Pid->getPIDFile();
Description:

getPIDFile returns the current PID file if available, undef otherwise.

See Also:

"new", "getPID"

SEE ALSO

Fcntl(3pm), FileHandle(3pm), Hardware::UPS::Perl::Connection(3pm), Hardware::UPS::Perl::Connection::Net(3pm), Hardware::UPS::Perl::Connection::Serial(3pm), Hardware::UPS::Perl::Constants(3pm), Hardware::UPS::Perl::Driver(3pm), Hardware::UPS::Perl::Driver::Megatec(3pm), Hardware::UPS::Perl::General(3pm), Hardware::UPS::Perl::Logging(3pm), Hardware::UPS::Perl::Utils(3pm)

NOTES

Hardware::UPS::Perl::PID was inspired by many Perl modules dealing with PID files. Alas, either those modules are not included in a standard SuSE 10.1 Linux distribution, or they did not quite fit to my needs.

Hardware::UPS::Perl::PID was developed using perl 5.8.8 on a SuSE 10.1 Linux distribution.

BUGS

There are plenty of them for sure. Maybe the embedded pod documentation has to be revised a little bit.

Suggestions to improve Hardware::UPS::Perl::PID are welcome, though due to the lack of time it might take a while to incorporate them.

AUTHOR

Copyright (c) 2007 by Christian Reile, <Christian.Reile@t-online.de>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. For further licensing details, please see the file COPYING in the distribution.