Mojo/SAML/Document/EntityDescriptor.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 6 SCAR 25.0
CC
6
Cov
0%
tag_attrs
20.0
before_render
12.0
BEGIN
2.0
CRAP 12.2
1 package Mojo::SAML::Document::EntityDescriptor;
2  
3 use Mojo::Base 'Mojo::SAML::Document';
4  
5 use Mojo::XMLSig;
6 use Mojo::SAML::Document::Signature;
7  
8 has template => sub { shift->build_template(<<'XML') };
9 %= tag EntityDescriptor => $self->tag_attrs, begin
10 % for my $desc (@{ $self->descriptors }) {
11 <%= $desc %>
12 % }
13 % for my $ext (@{ $self->extensions }) {
14 <%= $ext %>
15 % }
16 % end
17 XML
18  
19 has [qw/descriptors extensions/] => sub { [] };
20 has entity_id => sub { Carp::croak 'entity_id is required' };
21 has [qw/id valid_until cache_duration/];
22  
23 sub tag_attrs {
24 my $self = shift;
25 my @attrs = (
26 xmlns => 'urn:oasis:names:tc:SAML:2.0:metadata',
27 entityID => $self->entity_id,
28 );
29 if (defined(my $id = $self->id)) {
30 push @attrs, ID => $id;
31 }
32 if (defined(my $valid = $self->valid_until)) {
33 push @attrs, validUntil => $valid;
34 }
35 if (defined(my $cache = $self->cache_duration)) {
36 push @attrs, cacheDuration => $cache;
37 }
38  
39 return @attrs;
40 }
41  
42 sub before_render {
43 my $self = shift;
44 Carp::croak 'entity_id must be defined'
45 unless defined($self->entity_id);
46 for my $method (qw/descriptors/) {
47 Carp::croak "$method cannot be empty" unless @{$self->$method};
48 }
49 }
50  
51 1;
52  
53 =head1 NAME
54  
55 Mojo::SAML::Document::EntityDescriptor
56  
57 =head1 DESCRIPTION
58  
59 Represents an EntityDescriptor SAML metadata tag
60  
61 =head1 ATTRIBUTES
62  
63 L<Mojo::SAML::Document::EntityDescriptor> inherits all attributes from L<Mojo::SAML::Document> and implements the following new ones.
64  
65 =head2 cache_duration
66  
67 Optional.
68 The maximum length of time to cache the data.
69  
70 =head2 descriptors
71  
72 An array reference containing documents of service descriptors.
73 This may include L<Mojo::SAML::Document::SPSSODescriptor>.
74 Must not be empty at render time.
75  
76 =head2 entity_id
77  
78 Required.
79 This is the identifier for the entity.
80 It is often the same as the assertion consumer service location (url, see L<Mojo::SAML::Document::AssertionConsumerService/location>).
81  
82 =head2 extensions
83  
84 An array reference of strings or objects that stringify.
85 These are included directly into the body of the main tag.
86  
87 =head2 id
88  
89 Optional.
90 The ID of the XML element.
91  
92 =head2 template
93  
94 A template specific to the document type.
95  
96 =head2 valid_until
97  
98 Optional.
99 Speficies the time at which the document should no longer be considered valid.
100  
101 =head1 METHODS
102  
103 L<Mojo::SAML::Document::EntityDescriptor> inherits all methods from L<Mojo::SAML::Document> and implements the following new ones.
104  
105 =head2 before_render
106  
107 Enforces that L</descriptors> is not empty at render time.
108  
109 =head2 tag_attrs
110  
111 Generates a list of attributes for the tag.
112