Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Label.pm @ 381:ced5937ff21a
Custom getters/setters support method names in theirs definitions
Initial support for localizable labels in DOM schemas
author | cin |
---|---|
date | Wed, 22 Jan 2014 16:56:10 +0400 |
parents | |
children | 2f16f13b000c |
rev | line source |
---|---|
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
1 package IMPL::DOM::Schema::Label; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
2 use strict; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
3 use overload |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
4 '""' => 'ToString', |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
5 'bool' => sub { return 1; }, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
6 'fallback' => 1; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
7 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
8 use IMPL::Const qw(:prop); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
9 use IMPL::Exception(); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
10 use IMPL::declare { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
11 require => { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
12 ArgException => '-IMPL::InvalidArgumentException' |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
13 }, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
14 base => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
15 'IMPL::Object' => undef |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
16 ], |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
17 props => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
18 _map => PROP_RW, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
19 _id => PROP_RW |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
20 ] |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
21 }; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
22 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
23 sub CTOR { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
24 my ($this,$map,$id) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
25 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
26 die ArgException->new('map' => 'A strings map is required') |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
27 unless $map; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
28 die ArgException->new('id' => 'A lable identifier is required') |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
29 unless $id; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
30 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
31 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
32 our $AUTOLOAD; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
33 sub AUTOLOAD { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
34 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
35 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
36 my ($method) = ($AUTOLOAD =~ /(\w+)$/); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
37 return |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
38 if $method eq 'DESTROY'; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
39 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
40 return $this->new($this->_map,$method); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
41 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
42 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
43 sub ToString { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
44 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
45 return $this->_map->GetString($this->_id); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
46 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
47 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
48 1; |