1 |
package WebPAC::Output; |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use Carp qw/confess/; |
7 |
use Data::Dump qw/dump/; |
8 |
|
9 |
=head1 NAME |
10 |
|
11 |
WebPAC::Output - The great new WebPAC::Output! |
12 |
|
13 |
=cut |
14 |
|
15 |
=head1 SYNOPSIS |
16 |
|
17 |
Common routines for output formats |
18 |
|
19 |
=head1 FUNCTIONS |
20 |
|
21 |
=head2 ds_to_hash |
22 |
|
23 |
my $hash = $self->ds_to_hash( $ds, 'display' |
24 |
disable_key_mungle => 0, |
25 |
singe_values = 0, |
26 |
); |
27 |
|
28 |
=cut |
29 |
|
30 |
sub ds_to_hash { |
31 |
my $self = shift; |
32 |
|
33 |
my $ds = shift || confess "need ds"; |
34 |
my $type = shift || confess "need type"; |
35 |
|
36 |
my $opt = {@_}; |
37 |
|
38 |
my $hash; |
39 |
|
40 |
foreach my $t ( keys %$ds ) { |
41 |
my $name = $t; |
42 |
if ( ! $opt->{disable_key_mungle} ) { |
43 |
$name = lc($name); |
44 |
$name =~ s/\W+/_/g; |
45 |
} |
46 |
|
47 |
my $v = $ds->{$t} || die "bug"; |
48 |
|
49 |
# FIXME get rid of non hash values in data_structure for consistency? |
50 |
next unless ref($v) eq 'HASH'; |
51 |
|
52 |
if ( defined( $v->{$type} ) ) { |
53 |
if ( $opt->{single_values} && ref($v->{$type}) eq 'ARRAY' ) { |
54 |
$hash->{$name} = join(' ', map { |
55 |
if(ref($_)) { |
56 |
dump($_); |
57 |
} else { |
58 |
$_; |
59 |
} |
60 |
} @{ $v->{$type} }); |
61 |
} else { |
62 |
$hash->{$name} = $v->{$type}; |
63 |
} |
64 |
} |
65 |
} |
66 |
|
67 |
return $hash; |
68 |
} |
69 |
|
70 |
|
71 |
=head1 AUTHOR |
72 |
|
73 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
74 |
|
75 |
=head1 COPYRIGHT & LICENSE |
76 |
|
77 |
Copyright 2005-2007 Dobrica Pavlinusic, All Rights Reserved. |
78 |
|
79 |
This program is free software; you can redistribute it and/or modify it |
80 |
under the same terms as Perl itself. |
81 |
|
82 |
=cut |
83 |
|
84 |
1; # End of WebPAC::Output |