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