Data-Format-HTML-0.5.1/000755 000765 000000 00000000000 11705320756 014611 5ustar00davidwheel000000 000000 Data-Format-HTML-0.5.1/Changes000644 000765 000000 00000000223 11705320750 016073 0ustar00davidwheel000000 000000 0.3 Thu Oct 23 12:19:24 EDT 2008 Renaming due to name conflict on CPAN 0.2 Sat Mar 8 21:55:14 EST 2008 First unfinished release (as usual). Data-Format-HTML-0.5.1/lib/000755 000765 000000 00000000000 11705320750 015351 5ustar00davidwheel000000 000000 Data-Format-HTML-0.5.1/._Makefile.PL000644 000765 000024 00000000272 11705320750 017000 0ustar00davidstaff000000 000000 Mac OS X  2ˆºATTRº˜"˜"com.macromates.caret{ column = 46; line = 6; }Data-Format-HTML-0.5.1/Makefile.PL000644 000765 000000 00000000266 11705320750 016561 0ustar00davidwheel000000 000000 #!/usr/bin/perl use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Data::Format::HTML', VERSION_FROM => 'lib/Data/Format/HTML.pm', MIN_PERL_VERSION => '5.010000' ); Data-Format-HTML-0.5.1/MANIFEST000644 000765 000000 00000000074 11705320750 015735 0ustar00davidwheel000000 000000 lib/Data/Format/HTML.pm Changes Makefile.PL MANIFEST README Data-Format-HTML-0.5.1/._README000644 000765 000024 00000000271 11705320750 015705 0ustar00davidstaff000000 000000 Mac OS X  2‡¹ATTR¹˜!˜!com.macromates.caret{ column = 0; line = 1; }Data-Format-HTML-0.5.1/README000644 000765 000000 00000000116 11705320750 015461 0ustar00davidwheel000000 000000 Bushwick, Brooklyn, NY, and Mexico, together changing the freaking world. LOL Data-Format-HTML-0.5.1/lib/Data/000755 000765 000000 00000000000 11705320750 016222 5ustar00davidwheel000000 000000 Data-Format-HTML-0.5.1/lib/Data/Format/000755 000765 000000 00000000000 11705320750 017452 5ustar00davidwheel000000 000000 Data-Format-HTML-0.5.1/lib/Data/Format/._HTML.pm000644 000765 000024 00000000274 11705320750 021001 0ustar00davidstaff000000 000000 Mac OS X  2мATTR¼˜$˜$com.macromates.caret{ column = 18; line = 151; }Data-Format-HTML-0.5.1/lib/Data/Format/HTML.pm000644 000765 000000 00000011313 11705320750 020553 0ustar00davidwheel000000 000000 #!/usr/bin/perl package Data::Format::HTML; use strict; use warnings; our $VERSION = '0.5.1'; =head1 NAME Data::Format::HTML - Format Perl data structures into simple HTML =head1 SYNOPSIS use Data::Format::HTML; my $f = Data::Format::HTML->new; my %hash = (simple => 'hash'); # Of course it's very unlikely that you won't deal ever with this # kind of structure, but HTML is able to hand it all anyway :) my $struct = { foo => 'bar', 1 => 2, \'hello' => 'goodbye', array_ref => [qw/one two three/], nested_hash => \%hash, [qw/1 2/] => sub { die; }, even_more => { arr => { 1 => [2, 3, 4], this_is_insane => { a => { b => { c => { d => { e => 'z'}}}}} }, }, }; $struct->{'Data::Format::HTML handles it all'} = $f; print $f->format( $struct ); And that will output the following insane, but possible, for the sake of showing, HTML: =begin HTML
SCALAR(0x82a2be4)goodbye
ARRAY(0x8225570)

CODE(0x8370ac8)

12
array_ref
one
two
three
nested_hash
simplehash
foobar
Data::Format::HTML handles it all

Data::Format::HTML=HASH(0x82255c4)

even_more
arr
1
2
3
4
this_is_insane
a
b
c
d
ez
=end HTML In theory you can pass any kind of Perl data structure to C and you will get its data HTML-formatted. =head1 TODO =over =item * A LOT. ;) =item * Explain how CSS can prettify the tables (specification for everything) =item * Get CSS. =item * Better support for GLOB, CODE, REF and company. =item * Extend this documentation. =back =head1 SEE MORE The author keeps the versioned code at GitHub at: L. =head1 AUTHOR David Moreno, Edavid@axiombox.comE - L =head1 COPYRIGHT AND LICENSE Copyright (C) 2012 by David Moreno This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. The Do What The Fuck You Want To public license also applies. It's really up to you. =cut use feature "switch"; use Data::Dumper; use HTML::Entities; sub new { my($self, %opts) = shift; return bless { css => $opts{css} || '', var => undef, title => undef, }, $self; } sub format { my($self, $var, $title) = @_; my $output; if(defined $title) { $output .= qq{

$title

\n}; } $output .= $self->_format($var); } sub _format { my($self, $var) = @_; given (ref $var) { when ('SCALAR') { return $self->_format_scalar($var); } when ('ARRAY') { return $self->_format_array($var); } when ('HASH') { return $self->_format_hash($var); } when ('CODE') { return $self->_format_code($var); } # when 'REF' { return $self->_format_ref($var); } when ('') { return $self->_format_scalar(\$var); } default { return $self->_format_scalar(\$var); } } } sub _format_code { my($self, $code) = @_; qq{

}.scalar($code).qq{

\n}; } sub _format_hash { my($self, $hash) = @_; my $o = qq{\n}; while(my($k, $v) = each %{$hash}) { $k = $self->_format($k) if ref $k; $v = $self->_format($v) if ref $v; $v = '' unless defined $v; $o .= "\n"; } $o .= qq{
$k$v
\n\n}; } sub _format_array { my($self, $arr) = @_; my $output = qq{\n}; foreach my $v (@{$arr}) { $v = $self->_format($v) if ref $v; $output .= qq{\n}; } $output .= "
$v
\n\n\n"; } sub _format_scalar { my($self, $var) = @_; qq{

${$var}

\n\n}; } 1;