Mercurial > pub > Impl
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Web/Handler/RestController.pm Thu Apr 19 02:10:02 2012 +0400 @@ -0,0 +1,62 @@ +package IMPL::Web::Handler::RestController; +use strict; + +use IMPL::lang qw(:declare :constants); + +use IMPL::declare { + require => { + NotFoundException => 'IMPL::Web::NotFoundException' + }, + base => { + 'IMPL::Object' => undef, + } +}; + +BEGIN { + public property rootResource => PROP_GET | PROP_OWNERSET; + public property contract => PROP_GET | PROP_OWNERSET; +} + +sub Invoke { + my ($this,$action) = @_; + + my $query = $action->query; + + my $method = $query->request_method; + + #TODO: path_info is broken for IIS + my $pathInfo = $query->path_info; + + my @segments = split /\//, $pathInfo; + + my ($obj,$view) = (pop(@segments) =~ m/(.*?)(?:\.(\w+))?$/); + + $action->context->{view} = $view; + + my $res = $this->rootResource; + + while(@segments) { + $res = $res->InvokeHttpMethod('GET',shift @segments); + + die NotFoundException->new() unless $res; + } + + return $res->InvokeHttpMethod($method,$obj); +} + +1; + +__END__ + +=pod + +=head1 NAME + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +Использует C<$ENV{PATH_INFO}> для получения ресурса и вызова метода. + + +=cut \ No newline at end of file