Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application/OperationContract.pm @ 230:6d8092d8ce1b
*reworked IMPL::Security
*reworked IMPL::Web::Security
*refactoring
author | sergey |
---|---|
date | Mon, 08 Oct 2012 03:37:37 +0400 |
parents | 47f77e6409f7 |
children | 4abda21186cd |
comparison
equal
deleted
inserted
replaced
229:47f77e6409f7 | 230:6d8092d8ce1b |
---|---|
2 use strict; | 2 use strict; |
3 | 3 |
4 use IMPL::lang qw(:declare); | 4 use IMPL::lang qw(:declare); |
5 use IMPL::declare { | 5 use IMPL::declare { |
6 require => { | 6 require => { |
7 'Exception' => 'IMPL::Exception', | 7 Exception => 'IMPL::Exception', |
8 'ArgumentException' => '-IMPL::ArgumentException', | 8 ArgumentException => '-IMPL::InvalidArgumentException', |
9 'ResourceBaseClass' => 'IMPL::Web::Application::ResourceBase' | 9 ResourceInterface => 'IMPL::Web::Application::ResourceInterface' |
10 }, | 10 }, |
11 base => [ | 11 base => [ |
12 'IMPL::Object' => undef, | 12 'IMPL::Object' => undef, |
13 'IMPL::Object::Autofill' => '@_' | 13 'IMPL::Object::Autofill' => '@_' |
14 ], | 14 ], |
20 }; | 20 }; |
21 | 21 |
22 sub Invoke { | 22 sub Invoke { |
23 my ( $this, $resource, $request ) = @_; | 23 my ( $this, $resource, $request ) = @_; |
24 | 24 |
25 die ArgumentException( resource => 'A valid resource is required' ) | 25 die ArgumentException->new( resource => 'A valid resource is required' ) |
26 unless eval { $resource->isa(ResourceBaseClass) }; | 26 unless eval { $resource->isa(ResourceInterface) }; |
27 | 27 |
28 my $result = eval { | 28 my $result = eval { |
29 _InvokeDelegate($this->binding, $resource, $request) | 29 _InvokeDelegate($this->binding, $resource, $request) |
30 }; | 30 }; |
31 | 31 |
32 if (my $e = $@) { | 32 if (my $e = $@) { |
33 $result = _InvokeDelegate($this->error, $resource, $request, $e); | 33 if ($this->error) { |
34 $result = _InvokeDelegate($this->error, $resource, $request, $e) ; | |
35 } else { | |
36 die $e; | |
37 } | |
38 | |
34 } else { | 39 } else { |
35 $result = _InvokeDelegate($this->success, $resource, $request, $result); | 40 $result = _InvokeDelegate($this->success, $resource, $request, $result) |
41 if ($this->success); | |
36 } | 42 } |
37 | 43 |
38 return $result; | 44 return $result; |
39 } | 45 } |
40 | 46 |
41 sub _InvokeDelegate { | 47 sub _InvokeDelegate { |
42 my $delegate = shift; | 48 my $delegate = shift; |
43 | 49 |
44 return $delegete->(@_) if ref $delegate eq 'CODE'; | 50 return $delegate->(@_) if ref $delegate eq 'CODE'; |
45 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke')}; | 51 return $delegate->Invoke(@_) if eval { $delegate->can('Invoke')}; |
46 } | 52 } |
47 | 53 |
48 1; | 54 1; |
49 | 55 |