Added a bug fix, removed an unused var, and added a constant() with AUTOLOAD

CVS patchset: 4209
CVS date: 2000/10/12 05:09:16
This commit is contained in:
rjray 2000-10-12 05:09:16 +00:00
parent 8d85374707
commit ead6af89ab
2 changed files with 72 additions and 6 deletions

View File

@ -5,7 +5,7 @@
#
###############################################################################
#
# $Id: Header.pm,v 1.12 2000/10/05 04:48:59 rjray Exp $
# $Id: Header.pm,v 1.13 2000/10/12 05:09:16 rjray Exp $
#
# Description: The RPM::Header class provides access to the RPM Header
# structure as a tied hash, allowing direct access to the
@ -13,6 +13,8 @@
# as the values.
#
# Functions: new
# AUTOLOAD
# filenames
#
# Libraries: None.
#
@ -27,18 +29,40 @@ package RPM::Header;
require 5.005;
use strict;
use vars qw($VERSION $revision);
use subs qw(new);
use vars qw($VERSION $revision @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
use subs qw(new AUTOLOAD filenames);
require Exporter;
use RPM;
use RPM::Error;
use RPM::Constants ':rpmerr';
$VERSION = '0.29';
$revision = do { my @r=(q$Revision: 1.12 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
$revision = do { my @r=(q$Revision: 1.13 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = qw(RPM_HEADER_MASK RPM_HEADER_READONLY);
%EXPORT_TAGS = (all => \@EXPORT_OK);
1;
sub AUTOLOAD
{
my $constname;
($constname = $AUTOLOAD) =~ s/.*:://;
die "& not defined" if $constname eq 'constant';
my $val = constant($constname);
if ($! != 0)
{
die "Your vendor has not defined RPM macro $constname";
}
no strict 'refs';
*$AUTOLOAD = sub { $val };
goto &$AUTOLOAD;
}
sub new
{
my $class = shift;

View File

@ -4,7 +4,7 @@
#include "RPM.h"
static char * const rcsid = "$Id: Header.xs,v 1.18 2000/10/08 10:06:58 rjray Exp $";
static char * const rcsid = "$Id: Header.xs,v 1.19 2000/10/12 05:09:16 rjray Exp $";
static int scalar_tag(pTHX_ SV *, int);
/*
@ -23,6 +23,39 @@ static int scalar_tag(pTHX_ SV *, int);
(header) = ((s_ptr) && SvOK(*(s_ptr))) ? (RPM_Header *)SvIV(*(s_ptr)) : NULL;
/* Any constants that are specific to the RPM::Header class will be exported
from here, via this C-level constant() routine */
static int constant(pTHX_ char *name)
{
errno = 0;
if (strncmp((const char *)name, "RPM_HEADER_", 11))
{
errno = ENOENT;
return 0;
}
else
{
name += 11;
switch (*name)
{
case 'M':
if (strEQ(name, "MASK"))
#ifdef RPM_HEADER_MASK
return RPM_HEADER_MASK;
#endif
case 'R':
if (strEQ(name, "READONLY"))
#ifdef RPM_HEADER_READONLY
return RPM_HEADER_READONLY;
#endif
default:
errno = EINVAL;
return 0;
}
}
}
/* Some simple functions to manage key-to-SV* transactions, since these
gets used frequently. */
const char* sv2key(pTHX_ SV* key)
@ -434,7 +467,7 @@ int rpmhdr_STORE(pTHX_ RPM__Header self, SV* key, SV* value)
rpm_error(aTHX_ RPMERR_BADARG, errmsg);
return 0;
}
is_scalar = scalar_tag(Nullsv, num_ent);
is_scalar = scalar_tag(aTHX_ Nullsv, num_ent);
if (SvROK(value))
{
/*
@ -1369,3 +1402,12 @@ rpmhdr_source_name(self)
RETVAL = rpmhdr_source_name(self);
OUTPUT:
RETVAL
int
constant(name)
char* name;
PROTOTYPE: $
CODE:
RETVAL = constant(aTHX_ name);
OUTPUT:
RETVAL