comparison Lib/Engine/Action.pm @ 0:03e58a454b20

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