X-Git-Url: http://git.indexdata.com/?p=simpleserver-moved-to-github.git;a=blobdiff_plain;f=GRS1.pm;h=2f322ac5bf4a30e289ba1c491969dbe9dcf77be8;hp=89a8c9f87ec4430b72a0e15cfca801b742f1e0fd;hb=38818d8a4802abcbcfa58294ec0ddd166d9cc2ce;hpb=0a5124de095e40fad0b3774df8562386b98cefcb 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