r1673@llin: dpavlin | 2007-11-28 00:46:28 +0100
[webpac2] / lib / WebPAC / Output.pm
index e0d4812..e46cec5 100644 (file)
@@ -4,19 +4,14 @@ use warnings;
 use strict;
 
 use Carp qw/confess/;
+use Data::Dump qw/dump/;
 
 =head1 NAME
 
 WebPAC::Output - The great new WebPAC::Output!
 
-=head1 VERSION
-
-Version 0.01
-
 =cut
 
-our $VERSION = '0.01';
-
 =head1 SYNOPSIS
 
 Common routines for output formats
@@ -26,7 +21,8 @@ Common routines for output formats
 =head2 ds_to_hash
 
   my $hash = $self->ds_to_hash( $ds, 'display'
-       disable_key_mungle => 1,
+       disable_key_mungle => 0,
+       singe_values = 0,
   );
 
 =cut
@@ -48,11 +44,23 @@ sub ds_to_hash {
                        $name =~ s/\W+/_/g;
                }
 
-               # FIXME get rid of non hash values in data_structure for consistency?
-               next unless ref($ds->{$t}) eq 'HASH';
+               my $v = $ds->{$t} || die "bug";
 
-               if ( defined( $ds->{$t}->{$type} ) ) {
-                       $hash->{$name} = $ds->{$t}->{$type};
+               # FIXME get rid of non hash values in data_structure for consistency?
+               next unless ref($v) eq 'HASH';
+
+               if ( defined( $v->{$type} ) ) {
+                       if ( $opt->{single_values} && ref($v->{$type}) eq 'ARRAY' ) {
+                               $hash->{$name} = join(' ', map {
+                                       if(ref($_)) {
+                                               dump($_);
+                                       } else {
+                                               $_;
+                                       }
+                               } @{ $v->{$type} });
+                       } else {
+                               $hash->{$name} = $v->{$type};
+                       }
                }
        }