Hardware::UPS::Perl::Utils - utility functions for packages dealing with an UPS


perl-Hardware-UPS-Perl documentation Contained in the perl-Hardware-UPS-Perl distribution.

Index


Code Index:

NAME

Top

Hardware::UPS::Perl::Utils - utility functions for packages dealing with an UPS

SYNOPSIS

Top

    use Hardware::UPS::Perl::Utils qw(
       configure error warning
    );

DESCRIPTION

Top

Hardware::UPS::Perl::Utils provides functions for packages dealing with an UPS.

LIST OF FUNCTIONS

Top

configure

Name:

configure - processes arguments

Synopsis:
	&configure($actions, \@arguments);

Description:

configure processes arguments @arguments using the action table $actions being an anonymous hash of anonymous subroutines.

Arguments:

$actions

the action table; supplies a set of anonymous subroutines to process the options.

$arguments

anonymous array of arguments.

error

Name:

error - displays internal error messages and dies

Synopsis:
	&error($errorMessage);

Description:

error displays the error message $errorMessage with respect to the calling method and dies using Carp::croak().

Arguments:

$errorMessage

string; the error message.

See Also:

"warning"

warning

Name:

warning - displays internal error messages

Synopsis:
	&warning($warningMessage);

Description:

warning displays the error message $warningMessage with respect to the calling method using Carp::carp().

Arguments:

$warningMessage

string; the warning message.

See Also:

"error"

SEE ALSO

Top

Carp(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::PID(3pm),

NOTES

Top

Hardware::UPS::Perl::Utils was inspired by the usv.pl program by Bernd Holzhauer, <www.cc-c.de>. The latest version of this program can be obtained from

    http://www.cc-c.de/german/linux/linux_usv.php

Another great resource was the Network UPS Tools site, which can be found at

    http://www.networkupstools.org

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

BUGS

Top

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::Utils are welcome, though due to the lack of time it might take a while to incorporate them.

AUTHOR

Top

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.


perl-Hardware-UPS-Perl documentation Contained in the perl-Hardware-UPS-Perl distribution.

package Hardware::UPS::Perl::Utils;

#==============================================================================
# package description:
#==============================================================================
# This package supplies a set of usefull functions used in packages dealing
# with an UPS. For a detailed description see the pod documentation
# included at the end of this file.
#
# List of functions:
# ------------------
#   configure               - configures options
#   error                   - dealing with errors
#   warning                 - dealing with warnings
#
#==============================================================================

#==============================================================================
# Copyright:
#==============================================================================
# Copyright (c) 2007 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.
#==============================================================================

#==============================================================================
# Entries for Revision Control:
#==============================================================================
# Revision        : $Revision: 1.8 $
# Author          : $Author: creile $
# Last Modified On: $Date: 2007/04/14 09:37:26 $
# Status          : $State: Exp $
#------------------------------------------------------------------------------
# Modifications   :
#------------------------------------------------------------------------------
#
#   $Log: Utils.pm,v $
#   Revision 1.8  2007/04/14 09:37:26  creile
#   documentation update.
#
#   Revision 1.7  2007/04/07 15:14:45  creile
#   adaptations to "best practices" style;
#   update of documentation.
#
#   Revision 1.6  2007/03/03 21:15:53  creile
#   typing error removed.
#
#   Revision 1.5  2007/02/05 20:37:31  creile
#   pod documentation revised.
#
#   Revision 1.4  2007/02/04 14:01:32  creile
#   bug fix in pod documentation.
#
#   Revision 1.3  2007/02/03 15:36:03  creile
#   package Hardware::UPS::Perl::General removed, as we
#   use OO PID files now;
#   update of pod documentation.
#
#   Revision 1.2  2007/01/28 05:24:05  creile
#   bug fix concerning pod documentation.
#
#   Revision 1.1  2007/01/28 04:17:41  creile
#   initial version.
#
#
#==============================================================================

#==============================================================================
# module preamble:
#==============================================================================

use strict;

BEGIN {

    use Exporter ();
    use vars     qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

    $VERSION     = sprintf( "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/ );

    @ISA         = qw(Exporter);
    @EXPORT      = qw();
    @EXPORT_OK   = qw(
        &configure
        &error
        &warning
    );
    %EXPORT_TAGS = qw();

}

#==============================================================================
# end of module preamble
#==============================================================================

#==============================================================================
# packages required:
#------------------------------------------------------------------------------
#
#   Carp                            - warn of errors (from perspective of
#                                     caller)
#
#==============================================================================

use Carp;

#==============================================================================
# public functions:
#==============================================================================

sub configure {

    # subroutine to configure the connection
    #
    # parameters: $actions   (input) - anonymous hash; the action table
    #             $arguments (input) - anonymous array; arguments supplied

    # input as hidden local variables
    my ($actions, $arguments) = @_ ;

    # hidden local variables
    my $opt;                # current option
    my $arg;                # current argument
    my @return;             # return list of  of builtin Perl function `grep'
    my @options;            # the option list

    # processing options
    @options = keys %{$actions};

    PROCESS_OPTIONS:
    while (@{$arguments}) {

        $opt    = shift(@{$arguments});
        @return = grep(/^$opt/, @options);

        if (1 != @return) {
            error("unknown or ambiguous option -- $opt");
        }

        $arg    = shift(@{$arguments});
        $actions->{$return[0]}->($arg);
    }

} # end of subroutine "configure"

sub error {

    # subroutine to display internal error messages
    #
    # parameters: $errorMessage (input) - error message to be displayed

    # input as hidden local variable
    my $errorMessage = shift;

    # hidden local variables
    my $i = 1;                      # calling level
    my $method = (caller($i))[3];   # calling public method

    # determine calling subroutine
    METHOD:
    while ($method =~ /::_/) {
        $method = (caller(++$i))[3];
    }

    # displaying error message and die
    croak("$method: $errorMessage");

} # end of subroutine "error"

sub warning {

    # subroutine to display internal warning messages
    #
    # parameters: $warningMessage (input) - warning message to be displayed

    # input as hidden local variable
    my $warningMessage = shift;

    # hidden local variables
    my $i      = 1;                 # calling level
    my $method = (caller($i))[3];   # calling public method

    # determine calling subroutine
    METHOD:
    while ($method =~ /::_/) {
        $method = (caller(++$i))[3];
    }

    # displaying error message and continue
    carp("$method: $warningMessage");

} # end of subroutine "warning"

#==============================================================================
# package return:
#==============================================================================
1;

__END__

#==============================================================================
# embedded pod documentation:
#==============================================================================