From: rjray Date: Sat, 27 May 2000 03:53:56 +0000 (+0000) Subject: Perl side of the error management module X-Git-Tag: tznext/4.11.0.1.tizen20130304~8402 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8b0bb0bb10bcd821256967e78738f8d20ea6bb2;p=tools%2Flibrpm-tizen.git Perl side of the error management module CVS patchset: 3756 CVS date: 2000/05/27 03:53:56 --- diff --git a/Perl-RPM/RPM/Error.pm b/Perl-RPM/RPM/Error.pm new file mode 100644 index 0000000..5372e21 --- /dev/null +++ b/Perl-RPM/RPM/Error.pm @@ -0,0 +1,126 @@ +############################################################################### +# +# This file copyright (c) 2000 by Randy J. Ray, all rights reserved +# +# Copying and distribution are permitted under the terms of the Artistic +# License as distributed with Perl versions 5.002 and later. +# +############################################################################### +# +# $Id: Error.pm,v 1.1 2000/05/27 03:53:56 rjray Exp $ +# +# Description: Error-management support that cooperates with the primary +# Perl/C error glue. +# +# Functions: None (all XS) +# +# Libraries: RPM +# +# Global Consts: None. +# +# Environment: None. +# +############################################################################### + +package RPM::Error; + +use 5.005; +use strict; +use vars qw(@ISA $VERSION $revision @EXPORT @EXPORT_OK); + +require Exporter; +require RPM; + +@ISA = qw(Exporter); + +$VERSION = $RPM::VERSION; +$revision = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; + +@EXPORT = qw(clear_errors set_error_callback rpm_error); +@EXPORT_OK = @EXPORT; + +1; + +__END__ + +=head1 NAME + +RPM::Error - Functions to supplement the internal error management of RPM + +=head1 SYNOPSIS + + use RPM::Error; + use RPM::Constants ':rpmerr'; + + set_error_callback(sub { ... }); + + rpm_error(RPMERR_DBOPEN, "Error opening RPM DB: $!"); + +=head1 DESCRIPTION + +The B package provides access to some functions that work with +(but do not replace) the special C<$RPM::err> variable. These routines allow +for reporting errors through the B facility, clearing the error variable, +and registering a callback function to be invoked whenever a new error is +raised. + +None of these routines are required for normal use of the special variable +C<$RPM::err> (see L). + +=head1 USAGE + +The following routines are exported by B: + +=over + +=item rpm_error($code, $message) + +Report an error through the internal facility used by B. By using this +function, the special error variable is set up to have a dual-nature: When +evaluated in a numeric context, it returns the numerical code C<$code>. When +evaluated as a string, it will return C<$message>. The value of C<$code> +should be (but is not required to be) one of the values exported from the +B package via the B<:rpmerr> tag. C<$message> may be any +string value. + +=item clear_errors() + +Clears both the numeric and string values of C<$RPM::err>. + +=item $old_cb = set_error_callback($subr) + +Set a (new) callback to be invoked whenever a new error is flagged. Returns +the old (existing) callback value if there was one. + +The parameter to this call should be either a subroutine reference or a +closure. A subroutine name may be passed; if so, it should either be given +a package qualification or exist in the C namespace. The routine, +when invoked, will be passed the numeric code and the message string being +raised as the error. Note that the callback may be invoked by internal error +flagging in the core B library, as well as by calls to B +above. + +=back + +=head1 DIAGNOSTICS + +If the value passed to B is not valid, the current +callback is set to a null value. + +=head1 CAVEATS + +The code value passed to B is not checked against the list of +valid constants before assignment. + +The B should return the current callback, which could then +be restored. This does not currently work correctly, and should not be used. + +=head1 SEE ALSO + +L, L, L + +=head1 AUTHOR + +Randy J. Ray + +=cut