Mercurial > pub > Impl
comparison Lib/IMPL/Web/Handler/RestController.pm @ 197:6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
IMPL::Transform now admires object inheritance while searching for the transformation
Added HTTP some exceptions
IMPL::Web::Application::RestResource almost implemented
author | sergey |
---|---|
date | Thu, 19 Apr 2012 02:10:02 +0400 |
parents | |
children | 2ffe6f661605 |
comparison
equal
deleted
inserted
replaced
196:a705e848dcc7 | 197:6b1dda998839 |
---|---|
1 package IMPL::Web::Handler::RestController; | |
2 use strict; | |
3 | |
4 use IMPL::lang qw(:declare :constants); | |
5 | |
6 use IMPL::declare { | |
7 require => { | |
8 NotFoundException => 'IMPL::Web::NotFoundException' | |
9 }, | |
10 base => { | |
11 'IMPL::Object' => undef, | |
12 } | |
13 }; | |
14 | |
15 BEGIN { | |
16 public property rootResource => PROP_GET | PROP_OWNERSET; | |
17 public property contract => PROP_GET | PROP_OWNERSET; | |
18 } | |
19 | |
20 sub Invoke { | |
21 my ($this,$action) = @_; | |
22 | |
23 my $query = $action->query; | |
24 | |
25 my $method = $query->request_method; | |
26 | |
27 #TODO: path_info is broken for IIS | |
28 my $pathInfo = $query->path_info; | |
29 | |
30 my @segments = split /\//, $pathInfo; | |
31 | |
32 my ($obj,$view) = (pop(@segments) =~ m/(.*?)(?:\.(\w+))?$/); | |
33 | |
34 $action->context->{view} = $view; | |
35 | |
36 my $res = $this->rootResource; | |
37 | |
38 while(@segments) { | |
39 $res = $res->InvokeHttpMethod('GET',shift @segments); | |
40 | |
41 die NotFoundException->new() unless $res; | |
42 } | |
43 | |
44 return $res->InvokeHttpMethod($method,$obj); | |
45 } | |
46 | |
47 1; | |
48 | |
49 __END__ | |
50 | |
51 =pod | |
52 | |
53 =head1 NAME | |
54 | |
55 =head1 SYNOPSIS | |
56 | |
57 =head1 DESCRIPTION | |
58 | |
59 Использует C<$ENV{PATH_INFO}> для получения ресурса и вызова метода. | |
60 | |
61 | |
62 =cut |