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 |
|
24 |
template 'user' => sub { |
25 |
my ( $self, $req ) = @_; |
26 |
my $id = $req->param('id'); |
27 |
|
28 |
my $user = eval { Strix::User->new( id => $id ); }; |
29 |
warn "## user $id: $@"; |
30 |
|
31 |
if ( ! $user ) { |
32 |
$req->conn->send_status_line( 404, "user $id" ); |
33 |
$req->print( "Can't find user with id $id\n$@" ); |
34 |
} else { |
35 |
$req->print( show( 'show-user', $req, $user ) ); |
36 |
}; |
37 |
}; |
38 |
|
39 |
template 'show-user' => sub { |
40 |
my ( $self, $req, $user ) = @_; |
41 |
table { |
42 |
foreach my $f ( keys %$user ) { |
43 |
row { |
44 |
cell { $f } |
45 |
cell { $user->{$f} } |
46 |
} |
47 |
} |
48 |
} |
49 |
}; |
50 |
|
51 |
1; |