Mercurial > pub > Impl
diff Lib/IMPL/Web/AutoLocator.pm @ 326:793cc7f0a7e7
IMPL::Web::AutoLocator added Sibling method for locating sibling resources
author | sergey |
---|---|
date | Wed, 29 May 2013 17:58:45 +0400 |
parents | 6dc1c369eb71 |
children | 7171a8e2e2ba |
line wrap: on
line diff
--- a/Lib/IMPL/Web/AutoLocator.pm Mon May 27 02:49:58 2013 +0400 +++ b/Lib/IMPL/Web/AutoLocator.pm Wed May 29 17:58:45 2013 +0400 @@ -55,6 +55,35 @@ return $this->new(%args); } +sub Sibling { + my $this = shift; + my $child = shift or die ArgumentException->new("a child resource identifier is required"); + die ArgumentException->new("a child resource can't be a reference") if ref $child; + + # safe + $child = uri_escape($child); + + my %args; + + if($this->base =~ /(.*?)(\/[^\/]*)?$/) { + $args{base} = join('/',$1,$child); + } else { + $args{base} = $child; + } + + $args{view} = $this->view if $this->view; + $args{hash} = $this->hash if $this->hash; + + if (@_) { + my $query = shift; + + $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query; + } + + return $this->new(%args); + +} + sub Query { my ($this,$query) = @_;