/[Frey]/trunk/lib/Frey/View/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/View/Dumper.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 535 - (show annotations)
Wed Nov 26 16:17:17 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1340 byte(s)
move Frey::Escape funcionality into Frey::Web and chop long warn lines
1 package Frey::View::Dumper;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 use Data::Dump qw/dump/;
8
9 =head1 DESCRIPTION
10
11 dump C<data> as html tree
12
13 =cut
14
15 has data => (
16 is => 'rw',
17 required => 1,
18 documentation => "input data",
19 );
20
21 sub as_markup {
22 my ($self) = @_;
23 qq|<div class="frey-dumper">| . $self->unroll( $self->data ) . qq|</div>|;
24 }
25
26 sub unroll {
27 my ($self,$data,$ref,$key) = @_;
28 my $out;
29 my $title = $ref ? qq| title="$ref"| : '';
30
31 $out .= qq|<li${title}>|;
32 my $mark = $key || '&diams;';
33 $out .= $ref && $ref !~ m{^(ARRAY|HASH)$} ? qq|<a href="/$ref" class="blessed" target="blessed" title="$ref">$mark</a>| : ( $key || '' );
34
35 if ( ref($data) eq 'ARRAY' ) {
36 $out .= " &darr;</li>" if $key;
37 $out .= qq|<ol${title} start=0>\n|;
38 $out .= $self->unroll($_,ref($_)) foreach @$data;
39 $out .= "</ol>\n";
40 } elsif ( ref($data) && eval { %$data } ) {
41 $out .= " &darr;</li>" if $key;
42 $out .= qq|<ul${title}>\n|;
43 $out .= $self->unroll($data->{$_},ref($data->{$_}),$_) foreach keys %$data;
44 $out .= "</ul>\n";
45 } else {
46 $out .= " &rarr; " if $key;
47 if ( defined $data && $data =~ m{<(\w+).*>.+</\1>} ) {
48 $out .= qq|<div style="background: #eee; color: #000" title="HTML">$data</div></li>|;
49 } else {
50 $out .= "<span>" . $self->html_dump( $data ) . "</span></li>";
51 }
52 }
53 $out .= "</li>";
54
55 return $out;
56 }
57
58 1;

  ViewVC Help
Powered by ViewVC 1.1.26