annotate Lib/IMPL/Web/AutoLocator.pm @ 210:6adaeb86945d

added IMPL::Web::AutoLocator
author sergey
date Tue, 29 May 2012 20:07:22 +0400
parents
children 2b9b55cfb79b
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;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
23 public property hash => RPOP_ALL;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
24 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
25
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
26 sub fetch {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
27 my $this = shift;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
28 my $child = shift or die ArgumentException->new(child => "a child resource identifier is required");
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
29 die ArgumentException->new(child => "a child resource can't be a reference");
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
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
46 return __PACKAGE__->new()
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
47 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
48
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
49
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
50
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
51 1;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
52
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
53 __END__
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
54
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
55 =head1 NAME
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
56
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
57 =head1 SYNOPSIS
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
58
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
59 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса.
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
60
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
61 =begin code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
62
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
63 use IMPL::require {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
64 Locator => 'IMPL::Web::Locator'
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
65 };
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
66
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
67 my $bugTracker = Locator->new("http://myhost.org/bugzilla")->view("cgi");
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
68
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
69 my $bug = $bugTracker->show_bug({id = 1});
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
70
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
71 my $wikiPages = Locator->new("http://myhost.org/wiki/bin/view");
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
72
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
73 my $page = $wiki->Main->HowTo;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
74
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
75 =end code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
76
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
77 =head1 DESCRIPTION
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 организованных ресурсов. позволяет гибко работать с параметрами запроса и хешем. Для постоты
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
81 чтения реализует метод C<AUTOLOAD> для доступа к дочерним ресурсам