Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Label.pm @ 387:4cc6cc370fb2
DOM refactoring
author | sergey |
---|---|
date | Tue, 11 Feb 2014 01:13:47 +0400 |
parents | 2f16f13b000c |
children | 5aff94ba842f |
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; |
383 | 30 |
31 $this->_map($map); | |
32 $this->_id($id); | |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
33 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
34 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
35 our $AUTOLOAD; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
36 sub AUTOLOAD { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
37 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
38 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
39 my ($method) = ($AUTOLOAD =~ /(\w+)$/); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
40 return |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
41 if $method eq 'DESTROY'; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
42 |
383 | 43 warn $this->_id . ".$method"; |
44 | |
45 return $this->new($this->_map,$this->_id . ".$method"); | |
381
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 sub ToString { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
49 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
50 return $this->_map->GetString($this->_id); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
51 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
52 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
diff
changeset
|
53 1; |