226
|
1 package IMPL::Web::Application::ResourceContract;
|
|
2 use strict;
|
|
3 use IMPL::lang qw(:declare);
|
|
4 use IMPL::declare {
|
227
|
5 require => {
|
|
6 'ResourceClass' => 'IMPL::Web::Application::Resource'
|
|
7 },
|
226
|
8 base => [
|
|
9 'IMPL::Object' => undef
|
|
10 ]
|
|
11 };
|
|
12
|
|
13 BEGIN {
|
227
|
14 public property resourceFactory => PROP_ALL;
|
226
|
15 public property operations => PROP_ALL;
|
|
16 private property _namedResources => PROP_ALL;
|
|
17 private property _regexpResources => PROP_ALL;
|
|
18 }
|
|
19
|
227
|
20 sub CTOR {
|
|
21 my $this = shift;
|
|
22 my %args = @_;
|
|
23
|
|
24 $this->resourceFactory( $args{resourceFactory} || ResourceClass );
|
|
25 }
|
|
26
|
|
27 sub CreateResource {
|
|
28 my ($this,)
|
|
29 }
|
|
30
|
226
|
31 1;
|
|
32
|
|
33 __END__
|
|
34
|
|
35 =pod
|
|
36
|
|
37 =head1 NAME
|
|
38
|
|
39 C<IMPL::Web::Application::ResourceContract> - описание ресурса
|
|
40
|
|
41 =head1 SYNIOSIS
|
|
42
|
|
43 =begin code
|
|
44
|
|
45 use IMPL::require {
|
|
46 ResourceContract => 'IMPL::Web::Application::ResourceContract',
|
|
47 OperationContract => 'IMPL::Web::Application::OperationContract'
|
|
48 };
|
|
49
|
|
50 my $contract = ResourceContract->new(
|
|
51 operations => {
|
|
52 get => OperationContract->new(
|
|
53 bind => sub {
|
|
54 return "Hello!";
|
|
55 }
|
|
56 )
|
|
57 },
|
|
58 resources => [
|
|
59 {
|
|
60 name => 'info',
|
|
61 bind => sub {
|
|
62 return $_[0]->model->info;
|
|
63 },
|
|
64 contract => ResourceContract->new(
|
|
65 get => OperationContract->new(
|
|
66 bind => sub {
|
|
67 my ($resource,$model) = @_;
|
|
68 return $model; # or the same: $resource->model;
|
|
69 }
|
|
70 )
|
|
71 )
|
|
72 }
|
|
73 ]
|
|
74 )
|
|
75
|
227
|
76 my $obj = My::App::Data->fetch('something');
|
|
77
|
|
78 my $resource = $contract->CreateResource(
|
|
79 model => $obj,
|
|
80 parent => $prentResource,
|
|
81 id => 'item-something'
|
|
82 );
|
|
83
|
226
|
84 =end code
|
|
85
|
|
86 =head1 DESCRIPTION
|
|
87
|
|
88 =cut |