Hardware::UPS::Perl::PID - package for OO PID files.
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
Hardware::UPS::Perl::PID provides methods dealing with PID files.
new - creates a new PID file object
$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
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.
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.
"delete", "getPID", "getPIDFile", "getLogger", "setLogger"
setLogger - sets the logger to use
$Pid = Hardware::UPS::Perl::PID->new(); $Logger = Hardware::UPS::Perl::Logging->new(); $Pid->setLogger($logger);
setLogger sets the logger object used for logging. setLogger returns the previous logger used.
$logger
required; a Hardware::UPS::Perl:Logging object; defines the logger for logging.
"new", "getLogger"
getLogger - gets the current logger for logging
$Pid = Hardware::UPS::Perl::PID->new(); $logger = $Pid->getLogger();
getLogger returns the current logger, a Hardware::UPS::Perl::Logging object used for logging, if defined, undef otherwise.
"new", "setLogger"
delete - deletes the PID file currently used
$Pid = Hardware::UPS::Perl::PID->new(); $Pid->delete(); undef $Pid;
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.
"new", "getPID", "getPIDFile"
getErrorMessage - gets the internal error message
$Pid = Hardware::UPS::Perl::PID->new(); unless ( $Pid->delete() ) { print STDERR $Pid->getErrorMessage(), "\n"; exit 0; }
getErrorMessage returns the internal error message, if something went wrong.
getPID - gets the current PID file
$Pid = Hardware::UPS::Perl::PID->new(); $pid = $Pid->getPID();
getPID returns the current PID if available, undef otherwise.
"new", "getPIDFile"
getPIDFile - gets the current PID file
$Pid = Hardware::UPS::Perl::PID->new(); $pidFile = $Pid->getPIDFile();
getPIDFile returns the current PID file if available, undef otherwise.
"new", "getPID"
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)
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.
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.
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.
To install Hardware::UPS::Perl::PID, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hardware::UPS::Perl::PID
CPAN shell
perl -MCPAN -e shell install Hardware::UPS::Perl::PID
For more information on module installation, please visit the detailed CPAN module installation guide.