use warnings;
use strict;
+use Carp qw/confess/;
+
=head1 NAME
WebPAC::Output - The great new WebPAC::Output!
=head1 SYNOPSIS
-Quick summary of what the module does.
+Common routines for output formats
-Perhaps a little code snippet.
+=head1 FUNCTIONS
- use WebPAC::Output;
+=head2 ds_to_hash
- my $foo = WebPAC::Output->new();
- ...
+ my $hash = $self->ds_to_hash( $ds, 'display' );
-=head1 EXPORT
+=cut
-A list of functions that can be exported. You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
+sub ds_to_hash {
+ my $self = shift;
-=head1 FUNCTIONS
+ my ( $ds, $type ) = @_;
-=head2 function1
+ confess "need ds" unless $ds;
+ confess "need type" unless $type;
-=cut
+ my $hash;
-sub function1 {
-}
+ foreach my $t ( keys %$ds ) {
+ my $name = lc($t);
+ $name =~ s/\W+/_/g;
-=head2 function2
+ # FIXME get rid of non hash values in data_structure for consistency?
+ next unless ref($ds->{$t}) eq 'HASH';
-=cut
+ if ( defined( $ds->{$t}->{$type} ) ) {
+ $hash->{$name} = $ds->{$t}->{$type};
+ }
+ }
-sub function2 {
+ return $hash;
}
=head1 AUTHOR
=head1 COPYRIGHT & LICENSE
-Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
+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.
use warnings;
use strict;
-use base qw/WebPAC::Common Class::Accessor/;
+use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
__PACKAGE__->mk_accessors(qw(path));
#use Encode qw/from_to/;
$log->debug("id: $id ds = ",dump($ds));
- my $item;
-
- foreach my $t ( keys %$ds ) {
- my $name = lc($t);
- $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}->{display} ) ) {
- $item->{$name} = $ds->{$t}->{display};
- }
- }
-
- push @{ $self->{_data} }, $item;
+ push @{ $self->{_data} }, $self->ds_to_hash( $ds, 'display' );
return 1;
}