+sub Hash2grs {
+ my ($self, $href, $mapping) = @_;
+ my $key;
+ my $content;
+ my $aref;
+ my $issue;
+
+ $mapping = defined($mapping) ? $mapping : $self->{MAP};
+ $self->{MAP} = $mapping;
+ foreach $key (keys %$href) {
+ $content = $href->{$key};
+ next unless defined($content);
+ 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, $mapping);
+ $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $subtree);
+ } elsif (!ref($content)) { ## Regular string?
+ $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::String, $content);
+ } elsif (ref($content) eq 'ARRAY') {
+ my $issues = new Net::Z3950::GRS1;
+ foreach $issue (@$content) {
+ my $entry = new Net::Z3950::GRS1($issue, $mapping);
+ $issues->AddElement(5, 1, &Net::Z3950::GRS1::ElementData::Subtree, $entry);
+ }
+ $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $issues);
+ } else {
+ print STDERR "Hash2grs: Unsupported content type\n";
+ next;
+ }
+ }
+}
+
+