/[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 328 - (show annotations)
Thu Nov 6 21:14:09 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 944 byte(s)
re-introduce some clutter by wrapping arrays and hashes in () and {}
but it's really needed to transfer all information from structures
to user/developer
1 package Frey::Dumper;
2 use Moose;
3
4 with 'Frey::Escape';
5
6 use Data::Dump qw/dump/;
7
8 =head1 NAME
9
10 Frey::Dumper - dump perl data as tree
11
12 =cut
13
14 has data => (
15 is => 'rw',
16 required => 1,
17 );
18
19 sub markup {
20 my ($self) = @_;
21 qq|<div class="frey-dumper">| . $self->unroll( $self->data ) . qq|</div>|;
22 }
23
24 sub unroll {
25 my ($self,$data,$ref,$key) = @_;
26 my $out;
27 my $title = $ref ? qq| title="$ref"| : '';
28 if ( ref($data) eq 'ARRAY' ) {
29 $out .= "<li>$key &darr;</li>" if $key;
30 $out .= qq|<ol${title} start=0>(\n|;
31 $out .= $self->unroll($_,ref($_)) foreach @$data;
32 $out .= ")</ol>\n";
33 } elsif ( ref($data) ) {
34 $out .= "<li>$key &darr;</li>" if $key;
35 $out .= qq|<ul${title}>{\n|;
36 $out .= $self->unroll($data->{$_},ref($data->{$_}),$_) foreach keys %$data;
37 $out .= "}</ul>\n";
38 } else {
39 $out .= qq|<li${title}>|;
40 $out .= "$key &rarr; " if $key;
41 $out .= "<span>" . $self->html_dump( $data ) . "</span></li>";
42 }
43 return $out;
44 }
45
46 1;

  ViewVC Help
Powered by ViewVC 1.1.26