PRANG/XMLSchema/Whatever.pm

filter: Statementstmt 100% 15 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« PRANG/Graph/Meta/Attr.pm ↑ Summary
1  
2 # Here is the offending definition for this:
3  
4 # <complexType name="mixedMsgType" mixed="true">
5 # <sequence>
6 # <any processContents="skip"
7 # minOccurs="0" maxOccurs="unbounded"/>
8 # </sequence>
9 # <attribute name="lang" type="language"
10 # default="en"/>
11 # </complexType>
12  
13 # The mixed="true" part means that we can have character data (the
14 # validation of which cannot be specified AFAIK). See
15 # http://www.w3.org/TR/xmlschema11-1/#Complex_Type_Definition_details
16 #
17 # Then we get an unbounded "any", with processContents="skip"; this
18 # means that everything under this point - including XML namespace
19 # definitions, etc - should be completely ignored. The only
20 # requirement is that the contents are valid XML. See
21 # http://www.w3.org/TR/xmlschema11-1/#Wildcard_details
22  
23 # XXX - should really make roles for these different conditions:
24  
25 # PRANG::XMLSchema::Wildcard::Skip;
26 #
27 # 'skip' specifically means that no validation is required; if
28 # the input document specifies a schema etc, that information is
29 # to be ignored. In this instance, we may as well be returning
30 # the raw LibXML nodes.
31  
32 # PRANG::XMLSchema::Wildcard::Lax;
33 #
34 # processContents="lax" means to validate if the appropriate xsi:
35 # etc attributes are present; otherwise to treat as if it were
36 # 'skip'
37  
38 # PRANG::XMLSchema::Wildcard::Strict;
39  
40 # Actually this one may not be required; just specifying the
41 # 'Node' role should be enough. As 'Node' is not a concrete
42 # type, the rest of the namespace and validation mechanism should
43 # be able to check that the nodes are valid.
44  
45 # In addition to these different classifications of the <any>
46 # wildcard, the enclosing complexType may specify mixed="true";
47 # so, potentially there are two more roles;
48  
49 # PRANG::XMLSchema::Any; (cannot mix data and elements)
50 # PRANG::XMLSchema::Any::Mixed; (can mix them)
51  
52 # however dealing with all of these different conditions is currently
53 # probably premature; the schema we have only contains 'strict' (which
54 # as noted above potentially needs no explicit support other than
55 # correct XMLNS / XSI implementation) and 'Mixed' + 'Skip'; so I'll
56 # make this "Whatever" class to represent this most lax of lax
57 # specifications.
58  
59 package PRANG::XMLSchema::Whatever;
60  
61 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 2 ▶use MooseX::Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 2 ▶use PRANG::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 2 has_element 'contents' =>
66 is => "rw",
67 isa => "ArrayRef[PRANG::XMLSchema::Whatever|Str]",
68 xml_nodeName => { "" => "Str", "*" => "PRANG::XMLSchema::Whatever" },
69 xml_nodeName_attr => "nodenames",
70 xmlns => "*",
71 xmlns_attr => "nodenames_ns",
72 xml_min => 0,
73 ;
74  
75 2 has 'nodenames' =>
76 is => "rw",
77 isa => "ArrayRef[Maybe[Str]]",
78 ;
79  
80 2 has 'nodenames_ns' =>
81 is => "rw",
82 isa => "ArrayRef[Maybe[Str]]",
83 ;
84  
85 2 has_attr 'attributes' =>
86 is => "rw",
87 isa => "HashRef[Str|ArrayRef[Str]]",
88 xmlns => "*",
89 xml_name => "*",
90 xmlns_attr => "attributes_ns",
91 predicate => 'has_attributes',
92 ;
93  
94 2 has 'attributes_ns' =>
95 is => "rw",
96 isa => "HashRef[Str|ArrayRef[Str]]",
97 ;
98  
99 2 1;
100  
101 =head1 NAME
102  
103 PRANG::XMLSchema::Whatever - node type for nested anything
104  
105 =head1 SYNOPSIS
106  
107 package My::XML::Element::Type;
108 use Moose;
109 use PRANG::Graph;
110  
111 has 'error_fragment' =>
112 is => "rw",
113 isa => "PRANG::XMLSchema::Whatever",
114 ;
115  
116 =head1 DESCRIPTION
117  
118 Some schema allow sections of responses to be schema-free; typically
119 this is used for error responses which are allowed to include the
120 errant section of XML.
121  
122 Fortunately, PRANG is flexible enough that this is quite easy to do.
123 The result of the operation is a nested set of
124 PRANG::XMLSchema::Whatever objects, which have two properties
125 C<contents> and C<attributes>, which store the sub-elements and
126 attributes of the element at that point. There is also the attribute
127 C<nodenames> which stores the node names of nodes. Once it is
128 supported, there will also be an attribute indicating the XML
129 namespaces of attributes and elements (currently they will not
130 round-trip successfully).
131  
132 This API is somewhat experimental, and may be broken down into various
133 versions of 'whatever' - see the source for more.
134  
135 =head1 SEE ALSO
136  
137 L<PRANG>, L<PRANG::Graph::Meta::Attr>, L<PRANG::Graph::Meta::Element>
138  
139 =head1 AUTHOR AND LICENCE
140  
141 Development commissioned by NZ Registry Services, and carried out by
142 Catalyst IT - L<http://www.catalyst.net.nz/>
143  
144 Copyright 2009, 2010, NZ Registry Services. This module is licensed
145 under the Artistic License v2.0, which permits relicensing under other
146 Free Software licenses.
147  
148 =cut
149  
« PRANG/Graph/Meta/Attr.pm ↑ Summary