PRANG/XMLSchema/Whatever.pm

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 19 / 19 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 7 $PRANG::XMLSchema::Whatever::VERSION = '0.21';
61 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 7 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 7 ▶use PRANG::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 7 has_element 'contents' =>
66 is => "rw",
67 isa => "ArrayRef[PRANG::XMLSchema::Whatever|Str]",
68 xml_nodeName =>
69 { "" => "Str", "*" => "PRANG::XMLSchema::Whatever" },
70 xml_nodeName_attr => "nodenames",
71 xmlns => "*",
72 xmlns_attr => "nodenames_ns",
73 xml_min => 0,
74 ;
75  
76 7 has 'nodenames' =>
77 is => "rw",
78 isa => "ArrayRef[Maybe[Str]]",
79 ;
80  
81 7 has 'nodenames_ns' =>
82 is => "rw",
83 isa => "ArrayRef[Maybe[Str]]",
84 ;
85  
86 7 has_attr 'attributes' =>
87 is => "rw",
88 isa => "HashRef[Str|ArrayRef[Str]]",
89 xmlns => "*",
90 xml_name => "*",
91 xmlns_attr => "attributes_ns",
92 predicate => 'has_attributes',
93 ;
94  
95 7 has 'attributes_ns' =>
96 is => "rw",
97 isa => "HashRef[Str|ArrayRef[Str]]",
98 ;
99  
100 7 1;
101  
102 =head1 NAME
103  
104 PRANG::XMLSchema::Whatever - node type for nested anything
105  
106 =head1 SYNOPSIS
107  
108 package My::XML::Element::Type;
109 use Moose;
110 use PRANG::Graph;
111  
112 has 'error_fragment' =>
113 is => "rw",
114 isa => "PRANG::XMLSchema::Whatever",
115 ;
116  
117 =head1 DESCRIPTION
118  
119 Some schema allow sections of responses to be schema-free; typically
120 this is used for error responses which are allowed to include the
121 errant section of XML.
122  
123 Fortunately, PRANG is flexible enough that this is quite easy to do.
124 The result of the operation is a nested set of
125 PRANG::XMLSchema::Whatever objects, which have two properties
126 C<contents> and C<attributes>, which store the sub-elements and
127 attributes of the element at that point. There is also the attribute
128 C<nodenames> which stores the node names of nodes. Once it is
129 supported, there will also be an attribute indicating the XML
130 namespaces of attributes and elements (currently they will not
131 round-trip successfully).
132  
133 This API is somewhat experimental, and may be broken down into various
134 versions of 'whatever' - see the source for more.
135  
136 =head1 SEE ALSO
137  
138 L<PRANG>, L<PRANG::Graph::Meta::Attr>, L<PRANG::Graph::Meta::Element>
139  
140 =head1 AUTHOR AND LICENCE
141  
142 Development commissioned by NZ Registry Services, and carried out by
143 Catalyst IT - L<http://www.catalyst.net.nz/>
144  
145 Copyright 2009, 2010, NZ Registry Services. This module is licensed
146 under the Artistic License v2.0, which permits relicensing under other
147 Free Software licenses.
148  
149 =cut
150  
« PRANG/Graph/Meta/Attr.pm ↑ Summary