package WebPAC::Output;

use warnings;
use strict;

use Carp qw/confess/;

=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

=head1 FUNCTIONS

=head2 ds_to_hash

  my $hash = $self->ds_to_hash( $ds, 'display'
  	disable_key_mungle => 1,
  );

=cut

sub ds_to_hash {
	my $self = shift;

	my $ds = shift || confess "need ds";
	my $type = shift || confess "need type";

	my $opt = {@_};

	my $hash;

	foreach my $t ( keys %$ds ) {
		my $name = $t;
		if ( ! $opt->{disable_key_mungle} ) {
			$name = lc($name);
			$name =~ s/\W+/_/g;
		}

		# FIXME get rid of non hash values in data_structure for consistency?
		next unless ref($ds->{$t}) eq 'HASH';

		if ( defined( $ds->{$t}->{$type} ) ) {
			$hash->{$name} = $ds->{$t}->{$type};
		}
	}

	return $hash;
}


=head1 AUTHOR

Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

=head1 COPYRIGHT & LICENSE

Copyright 2005-2007 Dobrica Pavlinusic, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1; # End of WebPAC::Output
