210
|
1 package IMPL::Web::AutoLocator;
|
|
2 use strict;
|
|
3
|
|
4 use IMPL::lang qw(:declare :constants :hash);
|
|
5 use URI;
|
|
6 use URI::Escape;
|
|
7 use IMPL::declare {
|
|
8 require => {
|
|
9 Exception => 'IMPL::Exception',
|
|
10 ArgumentException => '-IMPL::InvalidArgumentException'
|
|
11 },
|
|
12 base => [
|
|
13 'IMPL::Object' => undef,
|
|
14 'IMPL::Object::Autofill' => '@_',
|
|
15 'IMPL::Object::Serializable' => '@_'
|
|
16 ]
|
|
17 };
|
|
18
|
|
19 BEGIN {
|
|
20 public property base => PROP_GET | PROP_OWNERSET;
|
|
21 public property view => PROP_ALL;
|
|
22 public property query => PROP_ALL;
|
|
23 public property hash => RPOP_ALL;
|
|
24 }
|
|
25
|
|
26 sub fetch {
|
|
27 my $this = shift;
|
|
28 my $child = shift or die ArgumentException->new(child => "a child resource identifier is required");
|
|
29 die ArgumentException->new(child => "a child resource can't be a reference");
|
|
30
|
|
31 # safe
|
|
32 $child = uri_escape($child);
|
|
33
|
|
34 my %args;
|
|
35
|
|
36 $args{base} = $this->base =~ /\/$/ ? $this->base . $child : $this->base . '/' . $child;
|
|
37 $args{view} = $this->view if $this->view;
|
|
38 $args{hash} = $this->hash if $this->hash;
|
|
39
|
|
40 if (@_) {
|
|
41 my $query = shift;
|
|
42
|
|
43 $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query;
|
|
44 }
|
|
45
|
|
46 return __PACKAGE__->new()
|
|
47 }
|
|
48
|
|
49
|
|
50
|
|
51 1;
|
|
52
|
|
53 __END__
|
|
54
|
|
55 =head1 NAME
|
|
56
|
|
57 =head1 SYNOPSIS
|
|
58
|
|
59 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса.
|
|
60
|
|
61 =begin code
|
|
62
|
|
63 use IMPL::require {
|
|
64 Locator => 'IMPL::Web::Locator'
|
|
65 };
|
|
66
|
|
67 my $bugTracker = Locator->new("http://myhost.org/bugzilla")->view("cgi");
|
|
68
|
|
69 my $bug = $bugTracker->show_bug({id = 1});
|
|
70
|
|
71 my $wikiPages = Locator->new("http://myhost.org/wiki/bin/view");
|
|
72
|
|
73 my $page = $wiki->Main->HowTo;
|
|
74
|
|
75 =end code
|
|
76
|
|
77 =head1 DESCRIPTION
|
|
78
|
|
79 Для удобстав навигации по ресурсам, полностью отражает классическую структуру иерархически
|
|
80 организованных ресурсов. позволяет гибко работать с параметрами запроса и хешем. Для постоты
|
|
81 чтения реализует метод C<AUTOLOAD> для доступа к дочерним ресурсам |