# HG changeset patch # User sergey # Date 1354885099 -14400 # Node ID 827cf96faa1c3a0759ac818651bc14006711618b # Parent fb52014f693131de32bfb4a26c69abce955eb40d refactoring (incomplete) diff -r fb52014f6931 -r 827cf96faa1c Lib/IMPL/Web/Application/Resource.pm --- a/Lib/IMPL/Web/Application/Resource.pm Thu Dec 06 19:58:42 2012 +0400 +++ b/Lib/IMPL/Web/Application/Resource.pm Fri Dec 07 16:58:19 2012 +0400 @@ -16,11 +16,12 @@ 'IMPL::Web::Application::ResourceInterface' => undef ], props => [ - parent => PROP_GET | PROP_OWNERSET, - model => PROP_GET | PROP_OWNERSET, - id => PROP_GET | PROP_OWNERSET, - contract => PROP_GET | PROP_OWNERSET, - location => PROP_GET | PROP_OWNERSET + parent => PROP_RO, + model => PROP_RO, + id => PROP_RO, + name => PROP_RO, + contract => PROP_RO, + location => PROP_RO, ] }; @@ -30,16 +31,19 @@ die ArgumentException->new( id => 'A resource identifier is required' ) unless $args{id}; die ArgumentException->new( contract => 'A contract is required' ) - unless $args{id}; + unless $args{contract}; + die ArgumentException->new( name => 'A name is required' ) + if $args{parent} && not(length $args{name}); $this->parent( $args{parent} ); $this->model( $args{model} ); $this->id( $args{id} ); $this->contract( $args{contract} ); + $this->name($args{name}); # если расположение явно не указано, то оно вычисляется автоматически, # либо остается не заданным - $this->location( $args{location} || eval { $this->parent->location->Child( $this->id ) } ); + $this->location( $args{location} || eval { $this->parent->location->Child( $this->name ) } ); } sub InvokeHttpVerb { @@ -168,6 +172,13 @@ Обязательное свойство ресурса, идентифицирует его в родительском контейнере, для корневого ресурса может иметь произвольное значение. +=head2 C<[get]name> + +Имя ресурса в адресной строке. При разборе адреса идентификаторы ресурсов могут +не всегда совпадать с именами, например C может иметь +идентификатор C, а его имя будет C. Однако за частую имя +совпадает с идентификатором. + =head2 C<[get]parent> Ссылка на родительский ресурс, для корневого ресурса не определена. diff -r fb52014f6931 -r 827cf96faa1c Lib/IMPL/Web/Handler/RestController.pm --- a/Lib/IMPL/Web/Handler/RestController.pm Thu Dec 06 19:58:42 2012 +0400 +++ b/Lib/IMPL/Web/Handler/RestController.pm Fri Dec 07 16:58:19 2012 +0400 @@ -44,8 +44,9 @@ shift @segments if @segments && length($segments[0]) == 0; if(@segments) { - my ($obj,$view) = (pop(@segments) =~ m/(.*?)(?:\.(\w+))?$/); - push @segments, $obj; + my $segment = pop(@segments); + my ($obj,$view) = ($segment =~ m/(.*?)(?:\.(\w+))?$/); + push @segments, { id => $obj, name => $segment, ext => $view }; } } @@ -63,13 +64,14 @@ my $res = $this->resourceFactory->new( id => 'root', + name => '', location => Locator->new(base => $action->application->baseUrl) ); while(@segments) { - my $id = shift @segments; + my $info = shift @segments; - $res = $res->FetchChildResource($id); + $res = $res->FetchChildResource($info->{id}); } $res = $res->InvokeHttpVerb($method,$action);