Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/SimpleType.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 | 4ddb27ff4a0b |
children | 5aff94ba842f |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::SimpleType; |
2 use strict; | |
3 use warnings; | |
4 | |
165 | 5 use parent qw(IMPL::DOM::Schema::SimpleNode); |
49 | 6 use IMPL::Class::Property; |
152 | 7 use IMPL::DOM::Property qw(_dom); |
49 | 8 |
9 BEGIN { | |
152 | 10 public _dom _direct property nativeType => prop_get; |
11 public _dom _direct property messageWrongType => prop_get; | |
49 | 12 } |
13 | |
14 our %CTOR = ( | |
15 'IMPL::DOM::Schema::SimpleNode' => sub { | |
16 my %args = @_; | |
17 $args{nodeName} = 'SimpleType'; | |
18 $args{minOccur} = 0; | |
19 $args{maxOccur} = 'unbounded'; | |
20 $args{name} ||= 'SimpleType'; | |
124 | 21 delete @args{qw(nativeType messageWrongType)}; |
49 | 22 %args |
23 } | |
24 ); | |
25 | |
26 sub CTOR { | |
27 my ($this,%args) = @_; | |
28 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
29 $this->{$nativeType} = $args{nativeType} if $args{nativeType}; |
238 | 30 $this->{$messageWrongType} = $args{messageWrongType} || "A simple node '%node.path%' is expected to be %schema.nativeType%"; |
103 | 31 } |
32 | |
33 sub Validate { | |
194 | 34 my ($this, $node, $ctx) = @_; |
35 | |
36 if ($this->{$nativeType}) { | |
37 return new IMPL::DOM::Schema::ValidationError( | |
236 | 38 node => $node, |
39 source => $ctx && $ctx->{Source} || $this, | |
40 schema => $this, | |
41 message => $this->messageWrongType | |
194 | 42 ) unless $node->isa($this->{$nativeType}); |
43 } | |
44 return $this->SUPER::Validate($node,$ctx); | |
49 | 45 } |
46 | |
102 | 47 sub qname { |
194 | 48 $_[0]->nodeName.'[type='.$_[0]->type.']'; |
102 | 49 } |
50 | |
103 | 51 1; |
49 | 52 |
103 | 53 __END__ |
54 | |
55 =pod | |
56 | |
57 =head1 NAME | |
58 | |
180 | 59 C<IMPL::DOM::Schema::SimpleType> - тип для простых узлов. |
103 | 60 |
61 =head1 DESCRIPTION | |
62 | |
180 | 63 Используется для описания простых узлов, которые можно отобразить в узлы |
64 определенного типа при построении DOM документа. | |
103 | 65 |
66 =head1 MEMBERS | |
67 | |
68 =over | |
69 | |
70 =item C<nativeType> | |
71 | |
180 | 72 Имя класса который будет представлять узел в DOM модели. |
103 | 73 |
74 =item C<messageWrongType> | |
75 | |
180 | 76 Формат сообщения которое будет выдано, если узел в дом модели не будет |
77 соответствовать свойству C<nativeType>. | |
103 | 78 |
79 =back | |
80 | |
81 =cut |