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 |
|
|
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 |
dpavlin |
32 |
template 'user' => sub { |
47 |
|
|
my ( $self, $req ) = @_; |
48 |
|
|
my $id = $req->param('id'); |
49 |
|
|
|
50 |
dpavlin |
38 |
my $continue = 1; |
51 |
|
|
while ( $continue ) { |
52 |
dpavlin |
32 |
|
53 |
dpavlin |
38 |
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 |
dpavlin |
39 |
$req->print( Frey::HTML->page( 'show-user', $req, $user ) ); |
61 |
|
|
# $req->print( '<pre>' . dump( $user ) . '</pre>' ); |
62 |
dpavlin |
38 |
}; |
63 |
|
|
|
64 |
|
|
@callbacks = (); |
65 |
|
|
$req->print('<tt>'.join(' ', |
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 |
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; |