annotate Lib/Engine/Action.pm @ 30:dd4d72600c69

ORM in works
author Sergey
date Tue, 03 Nov 2009 16:31:47 +0300
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 package Engine::Action;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 use Engine::CGI;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 use URI;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use base qw(IMPL::Object IMPL::Object::Disposable IMPL::Object::Autofill IMPL::Object::EventSource);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 our %Fallout;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 public _direct property Package => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 public _direct property Method => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 public _direct property Output => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 public _direct property RequestURI => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 public _direct property Result => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 __PACKAGE__->CreateEvent('OnPreInvoke');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 __PACKAGE__->CreateEvent('OnPastInvoke');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 sub Invoke {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 my ($this,$query) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 eval {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 die new Exception('A package isn\'t specified for the action',$this->RequestURI->as_string) if not $this->{$Package};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 no strict 'refs';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 eval "require ".$this->{$Package}.";" or die $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 $this->OnPreInvoke();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 $this->{$Package}->can($this->{$Method}) or
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 die new Exception("The method doesn't exists", $this->{$Method}, $this->{$Package})
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 if not ref $this->{$Method} eq 'CODE';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 my $instance = $this->{$Package}->can('revive') ? $this->{$Package}->revive : $this->{$Package};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 my $method = $this->{$Method};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 $this->{$Result} = $instance->$method($query,$this);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 $this->OnPastInvoke();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 if($@) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 my $err = $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 my $module = ref $this->{$Output} || $this->{$Output};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 if(my $uri = $module ? ($Fallout{$module}->{ref $err} || $Fallout{$module}->{Default}) : undef) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 $this->{$RequestURI} = URI->new($uri,'http');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 $this->{$Result} = $Common::Debug ? $err : undef;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 die $err;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 sub Dispose {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 my ($this) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 undef %$this;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 $this->SUPER::Dispose;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 1;