From 66c9e61522bb5c653efc4f60843231167aa95895 Mon Sep 17 00:00:00 2001 From: rjray Date: Sat, 10 Jun 2000 22:27:30 +0000 Subject: [PATCH] Adding the NVR method, tests, and docs CVS patchset: 3826 CVS date: 2000/06/10 22:27:30 --- Perl-RPM/RPM/Header.pm | 11 +++++++++-- Perl-RPM/RPM/Header.xs | 21 ++++++++++++++++++++- Perl-RPM/t/02_headers.t | 15 ++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Perl-RPM/RPM/Header.pm b/Perl-RPM/RPM/Header.pm index 57c2787..10a83fc 100644 --- a/Perl-RPM/RPM/Header.pm +++ b/Perl-RPM/RPM/Header.pm @@ -5,7 +5,7 @@ # ############################################################################### # -# $Id: Header.pm,v 1.2 2000/06/05 08:11:43 rjray Exp $ +# $Id: Header.pm,v 1.3 2000/06/10 22:27:30 rjray Exp $ # # Description: The RPM::Header class provides access to the RPM Header # structure as a tied hash, allowing direct access to the @@ -33,7 +33,7 @@ use subs qw(new); require RPM; $VERSION = $RPM::VERSION; -$revision = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; +$revision = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; 1; @@ -130,6 +130,13 @@ Given a tag I, return the type as a numerical value. The valid types can be imported from the B package via the import-tag ":rpmtype", and are: +=item NVR + +The commonly-needed data triple of (B, B, B) may be +accessed more directly by means of this method. It returns the three values +on the stack, with no need to dereference list references, as would be the +case when fetching the three tags via the usual means. + =over =item RPM_NULL_TYPE diff --git a/Perl-RPM/RPM/Header.xs b/Perl-RPM/RPM/Header.xs index b40e319..6d90be3 100644 --- a/Perl-RPM/RPM/Header.xs +++ b/Perl-RPM/RPM/Header.xs @@ -4,7 +4,7 @@ #include "RPM.h" -static char * const rcsid = "$Id: Header.xs,v 1.4 2000/06/05 08:14:32 rjray Exp $"; +static char * const rcsid = "$Id: Header.xs,v 1.5 2000/06/10 22:32:08 rjray Exp $"; /* Use this define for deriving the saved Header struct, rather than coding @@ -1051,3 +1051,22 @@ rpmhdr_is_source(self) RETVAL = rpmhdr_is_source(aTHX_ self); OUTPUT: RETVAL + +void +rpmhdr_NVR(self) + RPM::Header self; + PROTOTYPE: $ + PPCODE: + { + SV** svp; + RPM_Header* hdr; + + header_from_object(svp, hdr, self); + + if (hdr->name) + { + XPUSHs(sv_2mortal(newSVpv((char *)hdr->name, 0))); + XPUSHs(sv_2mortal(newSVpv((char *)hdr->version, 0))); + XPUSHs(sv_2mortal(newSVpv((char *)hdr->release, 0))); + } + } diff --git a/Perl-RPM/t/02_headers.t b/Perl-RPM/t/02_headers.t index 01460be..1934bef 100755 --- a/Perl-RPM/t/02_headers.t +++ b/Perl-RPM/t/02_headers.t @@ -5,7 +5,7 @@ use RPM::Database; chomp($rpmstr = qx{rpm -q rpm}); -print "1..8\n"; +print "1..11\n"; tie %DB, "RPM::Database" or die "$RPM::err"; @@ -60,5 +60,18 @@ print "ok 7\n"; print "not " unless ($hdr->tagtype(q{dirnames}) == RPM_STRING_ARRAY_TYPE); print "ok 8\n"; +# Test the NVR method +print "not " unless ($rpmstr eq join('-', $hdr->NVR)); +print "ok 9\n"; + +# Some tests on empty RPM::Header objects +$hdr = new RPM::Header; + +print "not " unless (defined $hdr and (ref($hdr) eq 'RPM::Header')); +print "ok 10\n"; + +print "not " if (scalar($hdr->NVR)); +print "ok 11\n"; + exit 0; -- 2.7.4