annotate Lib/IMPL/Web/AutoLocator.pm @ 212:292226770180

bugfixes
author sergey
date Fri, 29 Jun 2012 19:24:15 +0400
parents 2b9b55cfb79b
children 47f77e6409f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
1 package IMPL::Web::AutoLocator;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
2 use strict;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
3
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
4 use IMPL::lang qw(:declare :constants :hash);
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
5 use URI;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
6 use URI::Escape;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
7 use IMPL::declare {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
8 require => {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
9 Exception => 'IMPL::Exception',
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
10 ArgumentException => '-IMPL::InvalidArgumentException'
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
11 },
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
12 base => [
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
13 'IMPL::Object' => undef,
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
14 'IMPL::Object::Autofill' => '@_',
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
15 'IMPL::Object::Serializable' => '@_'
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
16 ]
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
17 };
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
18
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
19 BEGIN {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
20 public property base => PROP_GET | PROP_OWNERSET;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
21 public property view => PROP_ALL;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
22 public property query => PROP_ALL;
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
23 public property hash => PROP_ALL;
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
24 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
25
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
26 sub Fetch {
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
27 my $this = shift;
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
28 my $child = shift or die ArgumentException->new("a child resource identifier is required");
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
29 die ArgumentException->new("a child resource can't be a reference") if ref $child;
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
30
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
31 # safe
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
32 $child = uri_escape($child);
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
33
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
34 my %args;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
35
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
36 $args{base} = $this->base =~ /\/$/ ? $this->base . $child : $this->base . '/' . $child;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
37 $args{view} = $this->view if $this->view;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
38 $args{hash} = $this->hash if $this->hash;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
39
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
40 if (@_) {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
41 my $query = shift;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
42
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
43 $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
44 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
45
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
46 return $this->new(%args);
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
47 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
48
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
49 sub SetView {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
50 my ($this,$newView) = @_;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
51
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
52 $this->view($newView);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
53
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
54 return $this;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
55 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
56
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
57 sub url {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
58 my ($this) = @_;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
59
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
60 my $url = URI->new($this->view ? $this->base . "." . $this->view : $this->base);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
61 $url->query_form($this->query);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
62 $url->fragment($this->hash);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
63
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
64 return $url;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
65 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
66
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
67 sub AUTOLOAD {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
68 our $AUTOLOAD;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
69
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
70 (my $method) = ($AUTOLOAD =~ m/(\w+)$/);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
71
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
72 return if $method eq 'DESTROY';
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
73
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
74 my $this = shift;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
75 return $this->Fetch($method,@_);
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
76 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
77
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
78
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
79
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
80 1;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
81
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
82 __END__
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
83
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
84 =head1 NAME
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
85
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
86 =head1 SYNOPSIS
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
87
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
88 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса.
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
89
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
90 =begin code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
91
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
92 use IMPL::require {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
93 Locator => 'IMPL::Web::Locator'
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
94 };
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
95
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
96 my $bugTracker = Locator->new(base => "http://myhost.org/bugzilla")->SetView("cgi");
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
97
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
98 my $bug = $bugTracker->show_bug({id = 1});
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
99
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
100 my $wikiPages = Locator->new(base => "http://myhost.org/wiki/bin/view");
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
101
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
102 my $page = $wiki->Main->HowTo;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
103
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
104 =end code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
105
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
106 =head1 DESCRIPTION
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
107
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
108 Для удобстав навигации по ресурсам, полностью отражает классическую структуру иерархически
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
109 организованных ресурсов. позволяет гибко работать с параметрами запроса и хешем. Для постоты
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
110 чтения реализует метод C<AUTOLOAD> для доступа к дочерним ресурсам.
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
111
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
112 =head1 MEMBERS
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
113
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
114 =head2 C<CTOR(base => $url,view => $extension, query => $hashQuery, hash => $fragment)>
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
115
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
116 Создает новый объект расположение. Позволяет задать путь, расширение, параметры запроса и фрагмент ресурса.
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
117
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
118 =head2 C<Fetch($child[,$query])>
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
119
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
120 Получает расположение дочернего ресурса. При этом моздается новый объект адреса ресурса.
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
121
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
122 =head2 C<AUTLOAD>
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
123
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
124 Перенаправляет вызовы методов в метод C<Fetch> передавая первым параметром имя метода.
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
125
292226770180 bugfixes
sergey
parents: 211
diff changeset
126 =cut
292226770180 bugfixes
sergey
parents: 211
diff changeset
127