annotate Lib/IMPL/Web/Application/ResourceContract.pm @ 227:70ad6bc20908

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