Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application/ResourceContract.pm @ 226:b6cde007a175
Added resource contract
| author | sergey |
|---|---|
| date | Wed, 05 Sep 2012 15:10:26 +0400 |
| parents | |
| children | 70ad6bc20908 |
comparison
equal
deleted
inserted
replaced
| 225:a1e868b0fba9 | 226:b6cde007a175 |
|---|---|
| 1 package IMPL::Web::Application::ResourceContract; | |
| 2 use strict; | |
| 3 use IMPL::lang qw(:declare); | |
| 4 use IMPL::declare { | |
| 5 base => [ | |
| 6 'IMPL::Object' => undef | |
| 7 ] | |
| 8 }; | |
| 9 | |
| 10 BEGIN { | |
| 11 public property operations => PROP_ALL; | |
| 12 private property _namedResources => PROP_ALL; | |
| 13 private property _regexpResources => PROP_ALL; | |
| 14 } | |
| 15 | |
| 16 1; | |
| 17 | |
| 18 __END__ | |
| 19 | |
| 20 =pod | |
| 21 | |
| 22 =head1 NAME | |
| 23 | |
| 24 C<IMPL::Web::Application::ResourceContract> - описание ресурса | |
| 25 | |
| 26 =head1 SYNIOSIS | |
| 27 | |
| 28 =begin code | |
| 29 | |
| 30 use IMPL::require { | |
| 31 ResourceContract => 'IMPL::Web::Application::ResourceContract', | |
| 32 OperationContract => 'IMPL::Web::Application::OperationContract' | |
| 33 }; | |
| 34 | |
| 35 my $contract = ResourceContract->new( | |
| 36 operations => { | |
| 37 get => OperationContract->new( | |
| 38 bind => sub { | |
| 39 return "Hello!"; | |
| 40 } | |
| 41 ) | |
| 42 }, | |
| 43 resources => [ | |
| 44 { | |
| 45 name => 'info', | |
| 46 bind => sub { | |
| 47 return $_[0]->model->info; | |
| 48 }, | |
| 49 contract => ResourceContract->new( | |
| 50 get => OperationContract->new( | |
| 51 bind => sub { | |
| 52 my ($resource,$model) = @_; | |
| 53 return $model; # or the same: $resource->model; | |
| 54 } | |
| 55 ) | |
| 56 ) | |
| 57 } | |
| 58 ] | |
| 59 ) | |
| 60 | |
| 61 =end code | |
| 62 | |
| 63 =head1 DESCRIPTION | |
| 64 | |
| 65 =cut |
