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

  ViewVC Help
Powered by ViewVC 1.1.26