Added a bug fix, removed an unused var, and added a constant() with AUTOLOAD
authorrjray <devnull@localhost>
Thu, 12 Oct 2000 05:09:16 +0000 (05:09 +0000)
committerrjray <devnull@localhost>
Thu, 12 Oct 2000 05:09:16 +0000 (05:09 +0000)
CVS patchset: 4209
CVS date: 2000/10/12 05:09:16

Perl-RPM/RPM/Header.pm
Perl-RPM/RPM/Header.xs

index caf0d50..e879d42 100644 (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;
index 4af4499..fc6da1f 100644 (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