/[Frey]/trunk/lib/Frey/Dumper.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/Dumper.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 325 - (show annotations)
Thu Nov 6 20:25:04 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 816 byte(s)
implement own tree dumper and drop Data::Dumper::HTML
1 package Frey::Dumper;
2 use Moose;
3
4 use Data::Dump qw/dump/;
5
6 =head1 NAME
7
8 Frey::Dumper - dump perl data as tree
9
10 =cut
11
12 has data => (
13 is => 'rw',
14 required => 1,
15 );
16
17 sub markup {
18 my ($self) = @_;
19
20 sub unroll {
21 my ($data,$ref,$key) = @_;
22 my $out;
23 my $title = $ref ? qq| title="$ref"| : '';
24 if ( ref($data) eq 'ARRAY' ) {
25 $out .= "<li>$key</li>" if $key;
26 $out .= qq|<ol${title}>\n|;
27 $out .= unroll($_,ref($_)) foreach @$data;
28 $out .= "</ol>\n";
29 } elsif ( ref($data) ) {
30 $out .= "<li>$key</li>" if $key;
31 $out .= qq|<ul${title}>\n|;
32 $out .= unroll($data->{$_},ref($data->{$_}),$_) foreach keys %$data;
33 $out .= "</ul>\n";
34 } else {
35 $out .= qq|<li${title}>|;
36 $out .= "$key &rarr; " if $key;
37 $out .= dump( $data ) . "</li>";
38 }
39 return $out;
40 }
41
42 unroll( $self->data );
43 }
44
45 1;

  ViewVC Help
Powered by ViewVC 1.1.26