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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (show annotations)
Mon Jun 30 20:02:16 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 1604 byte(s)
 r44@eeepy:  dpavlin | 2008-06-30 18:08:33 +0200
 Change logic of generating html page using Frey::HTML->page
 because Template::Declare around_template is doing it around
 *all* templates (including those used with show).

1 package Strix::View;
2
3 use strict;
4 use warnings;
5
6 use Template::Declare::Tags; # defaults to 'HTML'
7 use base 'Template::Declare';
8 use Data::Dump qw/dump/;
9
10 =head1 NAME
11
12 Strix::View - examine Strix data
13
14 =cut
15
16 =head1 METHODS
17
18 =head2 user
19
20 =cut
21
22 use Strix::User;
23 use Frey::HTML;
24
25 my @callbacks;
26
27 sub gen_link {
28 my ($text, $code) = @_;
29 push @callbacks, $code;
30 return qq{<a href="?cb=$#callbacks">$text</a>};
31 }
32
33 sub process_links {
34 my $request = shift;
35 my $cb = $request->param('cb');
36 if (exists $callbacks[$cb]) {
37 $callbacks[$cb]->($request);
38 delete $callbacks[$cb];
39 }
40 }
41
42 use Data::Dumper;
43 $Data::Dumper::Deparse = 1;
44
45 template 'user' => sub {
46 my ( $self, $req ) = @_;
47 my $id = $req->param('id');
48
49 my $continue = 1;
50 while ( $continue ) {
51
52 my $user = eval { Strix::User->new( id => $id ); };
53 warn "## user $id: $@", dump( $user );
54
55 if ( ! $user ) {
56 $req->conn->send_status_line( 404, "user $id" );
57 $req->print( Frey::HTML->page( 'error', $req, "Can't find user with id $id\n$@" ) );
58 } else {
59 $req->print( Frey::HTML->page( 'show-user', $req, $user ) );
60 # $req->print( '<pre>' . dump( $user ) . '</pre>' );
61 };
62
63 @callbacks = ();
64 $req->print('<tt>'.join('&nbsp;',
65 $id,
66 gen_link('+' => sub { $id++ }),
67 gen_link('-' => sub { $id-- }),
68 gen_link('X' => sub { $continue = 0 }),
69 ).'</tt>');
70 $req->print('<pre>'.Dumper( @callbacks ).'</pre>');
71 $req->next;
72 process_links($req);
73 }
74 };
75
76 template 'show-user' => sub {
77 my ( $self, $req, $user ) = @_;
78 table {
79 foreach my $f ( keys %$user ) {
80 row {
81 cell { $f }
82 cell { $user->{$f} }
83 }
84 }
85 }
86 };
87
88 1;

  ViewVC Help
Powered by ViewVC 1.1.26