/[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 39 - (show annotations)
Mon Jun 30 20:02:10 2008 UTC (14 years, 7 months ago) by dpavlin
File size: 1578 byte(s)
 r41@eeepy:  dpavlin | 2008-06-30 14:02:17 +0200
 fix Template::Declare invocation

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 my $out = qq{<a href="?cb=$#callbacks">$text</a>};
31 return $out;
32 }
33
34 sub process_links {
35 my $request = shift;
36 my $cb = $request->param('cb');
37 if (exists $callbacks[$cb]) {
38 $callbacks[$cb]->($request);
39 delete $callbacks[$cb];
40 }
41 }
42
43 use Data::Dumper;
44 $Data::Dumper::Deparse = 1;
45
46 template 'user' => sub {
47 my ( $self, $req ) = @_;
48 my $id = $req->param('id');
49
50 my $continue = 1;
51 while ( $continue ) {
52
53 my $user = eval { Strix::User->new( id => $id ); };
54 warn "## user $id: $@", dump( $user );
55
56 if ( ! $user ) {
57 $req->conn->send_status_line( 404, "user $id" );
58 $req->print( "Can't find user with id $id\n$@" );
59 } else {
60 $req->print( Frey::HTML->page( 'show-user', $req, $user ) );
61 # $req->print( '<pre>' . dump( $user ) . '</pre>' );
62 };
63
64 @callbacks = ();
65 $req->print('<tt>'.join('&nbsp;',
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