/[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

Annotation of /trunk/lib/Strix/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations)
Mon Jun 30 20:02:16 2008 UTC (14 years, 7 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 dpavlin 19 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 dpavlin 32 =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 dpavlin 39 use Frey::HTML;
24 dpavlin 32
25 dpavlin 38 my @callbacks;
26    
27     sub gen_link {
28     my ($text, $code) = @_;
29     push @callbacks, $code;
30 dpavlin 42 return qq{<a href="?cb=$#callbacks">$text</a>};
31 dpavlin 38 }
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 dpavlin 32 template 'user' => sub {
46     my ( $self, $req ) = @_;
47     my $id = $req->param('id');
48    
49 dpavlin 38 my $continue = 1;
50     while ( $continue ) {
51 dpavlin 32
52 dpavlin 38 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 dpavlin 42 $req->print( Frey::HTML->page( 'error', $req, "Can't find user with id $id\n$@" ) );
58 dpavlin 38 } else {
59 dpavlin 39 $req->print( Frey::HTML->page( 'show-user', $req, $user ) );
60     # $req->print( '<pre>' . dump( $user ) . '</pre>' );
61 dpavlin 38 };
62    
63     @callbacks = ();
64     $req->print('<tt>'.join('&nbsp;',
65 dpavlin 42 $id,
66 dpavlin 38 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 dpavlin 32 };
75    
76 dpavlin 23 template 'show-user' => sub {
77     my ( $self, $req, $user ) = @_;
78 dpavlin 32 table {
79     foreach my $f ( keys %$user ) {
80     row {
81     cell { $f }
82     cell { $user->{$f} }
83     }
84     }
85 dpavlin 19 }
86     };
87    
88     1;

  ViewVC Help
Powered by ViewVC 1.1.26