File Coverage

blib/lib/PRANG/Graph/Meta/Attr.pm
Criterion Covered Total %
statement 3 4 75.0
branch n/a
condition n/a
subroutine 1 2 50.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1              
2             package PRANG::Graph::Meta::Attr;
3             $PRANG::Graph::Meta::Attr::VERSION = '0.19';
4 1     1   1624 use Moose::Role;
  1         2  
  1         8  
5              
6             has 'xmlns' =>
7             is => "rw",
8             isa => "Str",
9             predicate => "has_xmlns",
10             ;
11              
12             has 'xml_isa' =>
13             is => "rw",
14             isa => "Str|Moose::Meta::TypeConstraint",
15             predicate => "has_xml_isa",
16             ;
17              
18             has 'xml_name' =>
19             is => "rw",
20             isa => "Str",
21             predicate => "has_xml_name",
22             ;
23              
24             has 'xml_required' =>
25             is => "rw",
26             isa => "Bool",
27             predicate => "has_xml_required",
28             ;
29              
30             has 'xmlns_attr' =>
31             is => "rw",
32             isa => "Str",
33             predicate => "has_xmlns_attr",
34             ;
35              
36             package Moose::Meta::Attribute::Custom::Trait::PRANG::Attr;
37             $Moose::Meta::Attribute::Custom::Trait::PRANG::Attr::VERSION = '0.19';
38             sub register_implementation {
39 0     0     "PRANG::Graph::Meta::Attr";
40             }
41              
42             1;
43              
44             =head1 NAME
45              
46             PRANG::Graph::Meta::Attr - metaclass metarole for XML attributes
47              
48             =head1 SYNOPSIS
49              
50             package My::XML::Language::Node;
51              
52             use Moose;
53             use PRANG::Graph;
54              
55             has_attr 'someattr' =>
56             is => "rw",
57             isa => $str_subtype,
58             predicate => "has_someattr",
59             ;
60              
61             =head1 DESCRIPTION
62              
63             When defining a class, you mark attributes which correspond to XML
64             attributes. To do this in a way that the PRANG marshalling machinery
65             can use when converting to XML and back, make the attributes have this
66             metaclass.
67              
68             You could do this in principle with:
69              
70             has 'someattr' =>
71             traits => ['PRANG::Attr'],
72             ...
73              
74             But L<PRANG::Graph> exports a convenient shorthand for you to use.
75              
76             If you like, you can also set the C<xmlns> and C<xml_name> attribute
77             property, to override the default behaviour, which is to assume that
78             the XML attribute name matches the Moose attribute name, and that the
79             XML namespace of the attribute is empty. Note if you specify the
80             C<xmlns> for an attribute, it I<must> have that namespace set, or it
81             is not the same attribute.
82              
83             If you set the C<xml_required> property, then it is an error for the
84             property not to be set when parsing or emitting.
85              
86             Setting the C<xmlns> attribute to C<*> will allow any XML namespace to
87             be set for that attribute. In this case, you should also set the
88             C<xmlns_attr> property, which should refer to another attribute which
89             will record which XML namespace URI was passed in. This introduces a
90             potential ambiguity; the same attribute may be passed in multiple
91             times, with different XML namespaces.
92              
93             You can also set C<xml_isa>, which currently if set will not check the
94             type constraint against the input on marshall in. In the future it
95             will specify the type constraint to apply at marshall in time, instead
96             of waiting for the constructor to apply one.
97              
98             =head1 SEE ALSO
99              
100             L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>
101              
102             =head1 AUTHOR AND LICENCE
103              
104             Development commissioned by NZ Registry Services, and carried out by
105             Catalyst IT - L<http://www.catalyst.net.nz/>
106              
107             Copyright 2009, 2010, NZ Registry Services. This module is licensed
108             under the Artistic License v2.0, which permits relicensing under other
109             Free Software licenses.
110              
111             =cut