From: Anders S. Mortensen Date: Thu, 17 May 2001 13:43:04 +0000 (+0000) Subject: Added method Hash2grs into GRS1 module. X-Git-Tag: release.0.0.8.lau~59 X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=commitdiff_plain;h=38818d8a4802abcbcfa58294ec0ddd166d9cc2ce Added method Hash2grs into GRS1 module. --- diff --git a/GRS1.pm b/GRS1.pm index 89a8c9f..2f322ac 100644 --- a/GRS1.pm +++ b/GRS1.pm @@ -5,18 +5,50 @@ use IO::Handle; use Carp; + sub new { - my $class = shift; + my ($class, $href, $map) = @_; my $self = {}; $self->{ELEMENTS} = []; - $self->{FH} = *STDOUT; ## Default output handle is STDOUT + $self->{FH} = *STDOUT; ## Default output handle is STDOUT + $self->{MAP} = $map; bless $self, $class; + if (defined($href) && ref($href) eq 'HASH') { + if (!defined($map)) { + croak "Usage: new Net::Z3950::GRS1($href, $map);"; + } + $self->Hash2grs($href); + } return $self; } +sub Hash2grs { + my ($self, $href, $mapping) = @_; + my $key; + my $content; + my $aref; + + $mapping = defined($mapping) ? $mapping : $self->{MAP}; + foreach $key (keys %$href) { + $content = $href->{$key}; + if (!defined($aref = $mapping->{$key})) { + print STDERR "Hash2grs: Unmapped key: '$key'\n"; + next; + } + if (ref($content) eq 'HASH') { ## Subtree? + my $subtree = new Net::Z3950::GRS1($content); + $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $subtree); + } elsif (ref($content) eq '') { ## Regular string? + $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::String, $content); + } else { + print STDERR "Hash2grs: Unsupported content type\n"; + next; + } + } +} sub GetElementList { my $self = shift; @@ -290,7 +322,10 @@ Specification of the GRS-1 standard, for instance in the Z39.50 protocol specifi =cut #$Log: GRS1.pm,v $ -#Revision 1.2 2001-03-13 14:53:15 sondberg +#Revision 1.3 2001-05-17 13:43:04 sondberg +#Added method Hash2grs into GRS1 module. +# +#Revision 1.2 2001/03/13 14:53:15 sondberg #Added a few lines of documentation into GRS1.pm. # #Revision 1.1 2001/03/13 14:17:15 sondberg diff --git a/MANIFEST b/MANIFEST index 68c301d..bad6f72 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,3 +8,4 @@ ztest.pl OID.pm GRS1.pm INSTALL +grs_test.pl diff --git a/SimpleServer.c b/SimpleServer.c index 8114689..744501f 100644 --- a/SimpleServer.c +++ b/SimpleServer.c @@ -34,9 +34,8 @@ */ /*$Log: SimpleServer.c,v $ -/*Revision 1.8 2001-03-13 14:19:28 sondberg -/*Added a modified version of ztest.pl called grs_test.pl, which shows how to -/*implement support of GRS-1 record syntax. +/*Revision 1.9 2001-05-17 13:43:04 sondberg +/*Added method Hash2grs into GRS1 module. /* /*Revision 1.7 2001/03/13 14:17:15 sondberg /*Added support for GRS-1.