ee35e7d8a7074f0d8c35932cf04a493f9d6d5f2c
[webpac2] / lib / WebPAC / Output.pm
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
30 =cut
31
32 sub ds_to_hash {
33         my $self = shift;
34
35         my ( $ds, $type ) = @_;
36
37         confess "need ds" unless $ds;
38         confess "need type" unless $type;
39
40         my $hash;
41
42         foreach my $t ( keys %$ds ) {
43                 my $name = lc($t);
44                 $name =~ s/\W+/_/g;
45
46                 # FIXME get rid of non hash values in data_structure for consistency?
47                 next unless ref($ds->{$t}) eq 'HASH';
48
49                 if ( defined( $ds->{$t}->{$type} ) ) {
50                         $hash->{$name} = $ds->{$t}->{$type};
51                 }
52         }
53
54         return $hash;
55 }
56
57
58 =head1 AUTHOR
59
60 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
61
62 =head1 COPYRIGHT & LICENSE
63
64 Copyright 2005-2007 Dobrica Pavlinusic, All Rights Reserved.
65
66 This program is free software; you can redistribute it and/or modify it
67 under the same terms as Perl itself.
68
69 =cut
70
71 1; # End of WebPAC::Output