r75902 - in /branches/upstream/libhttp-oai-perl/current: CHANGES META.yml lib/HTTP/OAI.pm lib/HTTP/OAI/Metadata/OAI_DC.pm t/01parse.t

fabreg-guest at users.alioth.debian.org fabreg-guest at users.alioth.debian.org
Fri Jun 17 16:37:53 UTC 2011


Author: fabreg-guest
Date: Fri Jun 17 16:37:49 2011
New Revision: 75902

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75902
Log:
[svn-upgrade] new version libhttp-oai-perl (3.25)

Modified:
    branches/upstream/libhttp-oai-perl/current/CHANGES
    branches/upstream/libhttp-oai-perl/current/META.yml
    branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI.pm
    branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI/Metadata/OAI_DC.pm
    branches/upstream/libhttp-oai-perl/current/t/01parse.t

Modified: branches/upstream/libhttp-oai-perl/current/CHANGES
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-oai-perl/current/CHANGES?rev=75902&op=diff
==============================================================================
--- branches/upstream/libhttp-oai-perl/current/CHANGES (original)
+++ branches/upstream/libhttp-oai-perl/current/CHANGES Fri Jun 17 16:37:49 2011
@@ -1,3 +1,10 @@
+3.25
+	- Added unit test for OAI_DC metadata() parsing
+	- Metadata::OAI_DC now parses dc when passed as a DOM to ->metadata
+
+3.24
+	- Fixed CPAN bugs #60760 and #60856
+
 3.23
 	- Changed license to BSD
 	- Added dependency for XML::SAX rt #43287

Modified: branches/upstream/libhttp-oai-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-oai-perl/current/META.yml?rev=75902&op=diff
==============================================================================
--- branches/upstream/libhttp-oai-perl/current/META.yml (original)
+++ branches/upstream/libhttp-oai-perl/current/META.yml Fri Jun 17 16:37:49 2011
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               HTTP-OAI
-version:            3.24
+version:            3.25
 abstract:           ~
 author:  []
 license:            unknown

Modified: branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI.pm?rev=75902&op=diff
==============================================================================
--- branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI.pm (original)
+++ branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI.pm Fri Jun 17 16:37:49 2011
@@ -2,7 +2,7 @@
 
 use strict;
 
-our $VERSION = '3.24';
+our $VERSION = '3.25';
 
 # perlcore
 use Carp;

Modified: branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI/Metadata/OAI_DC.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI/Metadata/OAI_DC.pm?rev=75902&op=diff
==============================================================================
--- branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI/Metadata/OAI_DC.pm (original)
+++ branches/upstream/libhttp-oai-perl/current/lib/HTTP/OAI/Metadata/OAI_DC.pm Fri Jun 17 16:37:49 2011
@@ -1,39 +1,72 @@
 package HTTP::OAI::Metadata::OAI_DC;
 
-use strict;
-use warnings;
-
+use XML::LibXML;
 use HTTP::OAI::Metadata;
-
-use vars qw(@ISA @DC_TERMS);
-
 @ISA = qw(HTTP::OAI::Metadata);
 
-use XML::LibXML;
+use strict;
 
- at DC_TERMS = qw( contributor coverage creator date description format identifier language publisher relation rights source subject title type );
+our $OAI_DC_SCHEMA = 'http://www.openarchives.org/OAI/2.0/oai_dc/';
+our $DC_SCHEMA = 'http://purl.org/dc/elements/1.1/';
+our @DC_TERMS = qw( contributor coverage creator date description format identifier language publisher relation rights source subject title type );
 
 sub new {
-	my $class = shift;
-	my $self = $class->SUPER::new(@_);
-	my %args = @_;
-	if( exists $args{dc} && ref($args{dc}) eq 'HASH' ) {
+	my( $class, %self ) = @_;
+
+	my $self = $class->SUPER::new( %self );
+
+	if( exists $self{dc} && ref($self{dc}) eq 'HASH' )
+	{
 		my ($dom,$dc) =_oai_dc_dom();
-		for(keys %{$args{dc}}) {
-			$self->{dc}->{lc($_)} = $args{dc}->{$_};
-			foreach my $value (@{$args{dc}->{$_}}) {
-				$dc->appendChild($dom->createElement("dc:".lc($_)))->appendChild($dom->createTextNode($value));
+		foreach my $term (@DC_TERMS)
+		{
+			foreach my $value (@{$self{dc}->{$term}||[]})
+			{
+				$dc->appendChild($dom->createElementNS($DC_SCHEMA, $term))->appendText( $value );
 			}
 		}
 		$self->dom($dom);
 	}
-	for(@DC_TERMS) {
-		$self->{dc}->{$_} ||= [];
-	}
+
 	$self;
 }
 
-sub dc { shift->{dc} }
+sub dc
+{
+	my( $self ) = @_;
+
+	my $dom = $self->dom;
+	my $metadata = $dom->documentElement;
+
+	return $self->{dc} if defined $self->{dc};
+
+	my %dc = map { $_ => [] } @DC_TERMS;
+
+	$self->_dc( $metadata, \%dc );
+
+	return \%dc;
+}
+
+sub _dc
+{
+	my( $self, $node, $dc ) = @_;
+
+	my $ns = $node->getNamespaceURI;
+	$ns =~ s/\/?$/\//;
+
+	if( $ns eq $DC_SCHEMA )
+	{
+		push @{$dc->{lc($node->localName)}}, $node->textContent;
+	}
+	elsif( $node->hasChildNodes )
+	{
+		for($node->childNodes)
+		{
+			next if $_->nodeType != XML_ELEMENT_NODE;
+			$self->_dc( $_, $dc );
+		}
+	}
+}
 
 sub _oai_dc_dom {
 	my $dom = XML::LibXML->createDocument();
@@ -46,34 +79,25 @@
 }
 
 sub metadata { 
-	my $self = shift;
-	return $self->dom() unless @_;
-	my $md = shift or return $self->dom(undef);
-#	unless(my @nodes = $md->findnodes("*/*[local-name()='oai_dc' and namespace:uri()='http://purl.org/dc/elements/1.1/']")) {
-	my $oai_dc;
-	foreach my $nameSpace (qw(
-		http://www.openarchives.org/OAI/2.0/oai_dc/
-		http://purl.org/dc/elements/1.1/
-	)) {
-		foreach my $tagName (qw(dc oai_dc)) {
-			($oai_dc) = $md->getElementsByTagNameNS($nameSpace,$tagName);
-			last if $oai_dc;
+	my( $self, $md ) = @_;
+
+	return $self->dom if @_ == 1;
+
+	delete $self->{dc};
+	$self->dom( $md );
+
+	return if !defined $md;
+
+	my $dc = $self->dc;
+
+	my ($dom,$metadata) = _oai_dc_dom();
+
+	foreach my $term (@DC_TERMS)
+	{
+		foreach my $value (@{$dc->{$term}})
+		{
+			$metadata->appendChild( $dom->createElementNS( $DC_SCHEMA, $term ) )->appendText( $value );
 		}
-		last if $oai_dc;
-	}
-	unless( defined($oai_dc) ) {
-		die "Unable to locate OAI Dublin Core in:\n".$md->toString;
-		return $self->dom(undef);
-	}
-	$md = $oai_dc;
-
-	my ($dom,$dc) = _oai_dc_dom();
-
-	for ($md->getChildNodes) {
-		next unless $_->nodeType == XML_ELEMENT_NODE;
-		next unless $_->hasChildNodes;
-		next unless ($_->getFirstChild->nodeType == XML_TEXT_NODE || $_->getFirstChild->nodeType == XML_CDATA_SECTION_NODE);
-		$dc->appendChild($dom->createElement("dc:".$_->localName))->appendChild($dom->createTextNode($_->getFirstChild->toString));
 	}
 
 	$self->dom($dom)

Modified: branches/upstream/libhttp-oai-perl/current/t/01parse.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-oai-perl/current/t/01parse.t?rev=75902&op=diff
==============================================================================
--- branches/upstream/libhttp-oai-perl/current/t/01parse.t (original)
+++ branches/upstream/libhttp-oai-perl/current/t/01parse.t Fri Jun 17 16:37:49 2011
@@ -1,4 +1,4 @@
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 use IO::File;
 use HTTP::OAI;
@@ -19,6 +19,11 @@
 ok($rec);
 ok($rec->metadata->dc->{creator}->[0] eq 'Aspinwall, Paul S.');
 
+my $dom = $rec->metadata->dom;
+my $md = HTTP::OAI::Metadata::OAI_DC->new;
+$md->metadata( $dom );
+ok($md->dc->{creator}->[0] eq 'Aspinwall, Paul S.');
+
 $r = HTTP::OAI::Identify->new();
 $fh = IO::File->new('examples/identify.xml','r')
 	or BAIL_OUT( "Failed to open examples/identify.xml: $!" );




More information about the Pkg-perl-cvs-commits mailing list