/[Frey]/trunk/lib/Frey/REST.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/Frey/REST.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Sun Jun 29 16:24:41 2008 UTC (14 years, 5 months ago) by dpavlin
File size: 656 byte(s)
another major refactor and version bump [0.01]

- return 404 errors for resources which doesn't exist
- move HTML page wrapper is now in Fray::HTML->page
- dispatch to defined Template::Declare templates
- display available templates on status screen
- NOTE very clean and unobfuscated mapping
- a bits of documentation all over the place
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 use Frey::HTML;
11
12 =head1 NAME
13
14 Frey::REST - dispatch REST like URLs into method calls
15
16 =cut
17
18 =head1 METHODS
19
20 =head2 user
21
22 =cut
23
24 template 'user' => sub {
25 my ( $self, $req ) = @_;
26
27 my $id = $req->param('id');
28 $id = 1 unless $id =~ m/^\d+$/;
29
30 use Strix::User;
31 my $user = Strix::User->new( id => $id );
32
33 if ( ! $user ) {
34 $req->conn->send_status_line( 404, "user $id" );
35 $req->print( "Can't find user with id $id" );
36 } else {
37 $req->print( Frey::HTML->page( 'show-user', $req, $user ) );
38 };
39 };
40

  ViewVC Help
Powered by ViewVC 1.1.26