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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 946 - (show annotations)
Tue Jan 6 15:26:41 2009 UTC (15 years, 4 months ago) by dpavlin
File size: 777 byte(s)
Frey::View::Exhibit now has configurable Frey::Pipe source
split JSON encoder for exhibit into Frey::View::Exhibit::JSON
1 package Frey::View::Exhibit::JSON;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 #with 'Frey::Storage';
7
8 has sponge => (
9 is => 'rw',
10 isa => 'Sponge',
11 required => 1,
12 );
13
14 use JSON;
15
16 sub as_markup {
17 my ($self) = @_;
18
19 my $items;
20 my $names = $self->sponge->{NAME};
21
22 my $id = 0;
23 my $have_id = grep { m{^id$} } @$names;
24 my $have_label = grep { m{^label$} } @$names;
25
26 foreach my $row ( @{ $self->sponge->{rows} } ) {
27 my $item;
28 map { $item->{ $names->[$_] } = $row->[$_] } ( 0 .. $#{ $row } );
29 $item->{id} = $id unless $have_id;
30 $item->{label} = $id unless $have_label;
31 $id++;
32 push @{ $items->{items} }, $item;
33 }
34
35 $self->content_type('application/javascript');
36 # JSON->new->allow_nonref(1)->allow_blessed(1)->encode($items);
37 JSON->new->encode($items);
38 }
39
40 1;

  ViewVC Help
Powered by ViewVC 1.1.26