1 |
package Frey::REST; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Template::Declare::Tags; # defaults to 'HTML' |
7 |
use base 'Template::Declare'; |
8 |
|
9 |
use Data::Dump qw/dump/; |
10 |
|
11 |
=head1 NAME |
12 |
|
13 |
Frey::REST - dispatch REST like URLs into method calls |
14 |
|
15 |
=cut |
16 |
|
17 |
=head1 METHODS |
18 |
|
19 |
=head2 user |
20 |
|
21 |
=cut |
22 |
|
23 |
template 'user' => sub { |
24 |
my ( $self, $req ) = @_; |
25 |
|
26 |
my $id = $req->param('id'); |
27 |
$id = 1 unless $id =~ m/^\d+$/; |
28 |
|
29 |
use Strix::User; |
30 |
my $user = Strix::User->new( id => $id ); |
31 |
|
32 |
if ( ! $user ) { |
33 |
$req->conn->send_status_line( 500, "user $id" ); |
34 |
|
35 |
$req->print( "Can't find user with id $id" ); |
36 |
} else { |
37 |
$req->print( HTML->view( 'user', $user ) ); |
38 |
} |
39 |
}; |
40 |
|