# HG changeset patch # User sergey # Date 1369835925 -14400 # Node ID 793cc7f0a7e78025263463c1000c8e2176f6c6be # Parent 34a110d1f06c7b5fdfb0b3a9b67b03b04d4e8e47 IMPL::Web::AutoLocator added Sibling method for locating sibling resources diff -r 34a110d1f06c -r 793cc7f0a7e7 Lib/IMPL/Web/AutoLocator.pm --- 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) = @_;