annotate lib/IMPL/DOM/Schema/Label.pm @ 418:3f38dabaf5cc ref20150831

sync
author cin
date Mon, 28 Dec 2015 15:11:35 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Schema::Label;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use overload
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 '""' => 'ToString',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 'bool' => sub { return 1; },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 'fallback' => 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 use IMPL::Exception();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 ArgException => '-IMPL::InvalidArgumentException'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 'IMPL::Object' => undef
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 _map => PROP_RW,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 _id => PROP_RW
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 my ($this,$map,$id) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 die ArgException->new('map' => 'A strings map is required')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 unless $map;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 die ArgException->new('id' => 'A lable identifier is required')
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 unless $id;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 $this->_map($map);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 $this->_id($id);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 our $AUTOLOAD;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 sub AUTOLOAD {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 my ($method) = ($AUTOLOAD =~ /(\w+)$/);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 return
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 if $method eq 'DESTROY';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 warn $this->_id . ".$method";
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 return $this->new($this->_map,$this->_id . ".$method");
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 sub ToString {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 return $this->_map->GetString($this->_id);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 sub Format {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 my ($this,$args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 return $this->_map->GetString($this->_id,$args);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 1;