changeset 326:793cc7f0a7e7

IMPL::Web::AutoLocator added Sibling method for locating sibling resources
author sergey
date Wed, 29 May 2013 17:58:45 +0400
parents 34a110d1f06c
children 6cb0d4d325d7
files Lib/IMPL/Web/AutoLocator.pm
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
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) = @_;