/[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 355 - (show annotations)
Sun Nov 16 15:19:54 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1080 byte(s)
fix dump of blessed objects
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) eq 'HASH' ) {
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 if ( $data =~ m{<(\w+)>.+</\1>} ) {
42 $out .= qq|<div style="background: #eee; color: #000">$data</div></li>|;
43 } else {
44 $out .= "<span>" . $self->html_dump( $data ) . "</span></li>";
45 }
46 }
47 return $out;
48 }
49
50 1;

  ViewVC Help
Powered by ViewVC 1.1.26