annotate Lib/DOM/Site.pm @ 11:75980091813b

DOM и навигация
author Sergey
date Wed, 02 Sep 2009 17:47:44 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package DOM::Site;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 our @ISA = qw(Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 our $Name;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 our @Providers;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 our $AUTOLOAD;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 DeclareProperty(Objects => ACCESS_READ);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 DeclareProperty(Providers => ACCESS_NONE);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 sub RegisterObject {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 my ($this,$name,$object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 $this->{$Objects}->{$name} = $object;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 sub RegisterProvider {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 my ($this,$provider) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 my $refInfo = $provider->GetProviderInfo();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 if ($refInfo->{'Host'} eq __PACKAGE__) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 die new Exception("Provider $refInfo->{'Name'} already registered") if exists $this->{$Providers}->{$refInfo->{'Name'}};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 while (my ($name,$method) = each %{$refInfo->{'Methods'}}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 no strict 'refs';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 no warnings 'redefine';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 *{__PACKAGE__ . '::' . $name} = sub {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 $method->($provider,$this,@_);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 while (my ($name,$object) = each %{$refInfo->{'Objects'}}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 $this->{$Objects}->{$refInfo->{'Name'}}->{$name} = $object;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 $this->{$Providers}->{$refInfo->{'Name'}} = 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 sub construct {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 my $self = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 my $site = $self->new();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 $site->RegisterObject(Site => { Name => $Name});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 foreach my $provider (@Providers) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 my $providerFile = $provider;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 $providerFile =~ s/::/\//g;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 $providerFile .= '.pm';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 eval {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 require $providerFile;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 if ($@) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 my $InnerErr = $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 die new Exception("Failed to load provider $provider", $InnerErr);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61 if ($provider->can('construct')) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 $site->RegisterProvider($provider->construct());
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64 $site->RegisterProvider($provider);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
67 return $site;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
68 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
69
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
70 sub Dispose {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
71 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
72
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
73 UNIVERSAL::can($_,'Dispose') and $_->Dispose foreach values %{$this->{$Objects} || {}};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75 undef %$this;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77 $this->SUPER::Dispose;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
78 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
79
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
80 1;