File Coverage

blib/lib/Net/Amazon/Route53/ResourceRecordSet.pm
Criterion Covered Total %
statement 21 56 37.5
branch 0 10 0.0
condition n/a
subroutine 7 9 77.7
pod 2 2 100.0
total 30 77 38.9


line stmt bran cond sub pod time code
1 2     2   11 use strict;
  2         3  
  2         49  
2 2     2   9 use warnings;
  2         4  
  2         72  
3              
4             package Net::Amazon::Route53::ResourceRecordSet;
5             $Net::Amazon::Route53::ResourceRecordSet::VERSION = '0.173450';
6 2     2   8 use Moo;
  2         4  
  2         10  
7 2     2   560 use Types::Standard qw(InstanceOf Str Int ArrayRef);
  2         10  
  2         14  
8 2     2   1447 use XML::Bare;
  2         4  
  2         78  
9 2     2   18 use HTML::Entities;
  2         4  
  2         1154  
10              
11             =head2 SYNOPSIS
12              
13             my $resource = Net::Amazon::Route53::ResourceRecordSet->new(...);
14             # use methods on $resource
15              
16             =cut
17              
18             =head2 ATTRIBUTES
19              
20             =cut
21              
22             =head3 route53
23              
24             A L object, needed and used to perform requests
25             to Amazon's Route 53 service
26              
27             =head3 hostedzone
28              
29             The L object this hosted zone refers to
30              
31             =cut
32              
33             has 'route53' => ( is => 'rw', isa => InstanceOf['Net::Amazon::Route53'], required => 1, weak_ref => 1 );
34             has 'hostedzone' => ( is => 'rw', isa => InstanceOf['Net::Amazon::Route53::HostedZone'], required => 1, weak_ref => 1 );
35              
36             =head3 name
37              
38             The name for this resource record
39              
40             =head3 ttl
41              
42             The TTL associated with this resource record
43              
44             =head3 type
45              
46             The type of this resource record (C, C, C, etc)
47              
48             =head3 values
49              
50             The values associated with this resource record.
51              
52             =cut
53              
54             has 'name' => ( is => 'rw', isa => Str, required => 1 );
55             has 'ttl' => ( is => 'rw', isa => Int, required => 1 );
56             has 'type' => ( is => 'rw', isa => Str, required => 1 );
57             has 'values' => ( is => 'rw', isa => ArrayRef, required => 1, default => sub { [] } );
58              
59             =head2 METHODS
60              
61             =cut
62              
63             =head3 create
64              
65             my $record = Net::Amazon::Route53::ResourceRecordSet->new( ... );
66             $record->create;
67              
68             Creates a new record. Needs all the attributes (name, ttl, type and values).
69              
70             Takes an optional boolean parameter, C, to indicate whether the request should
71             return straightaway (default, or when C is C<0>) or it should wait until the
72             request is C according to the Change's status.
73              
74             Returns a L object representing the change requested.
75              
76             =cut
77              
78             sub create
79             {
80 0     0 1   my $self = shift;
81 0           my $wait = shift;
82 0 0         $wait = 0 if !defined $wait;
83 0 0         $self->name =~ /\.$/ or die "Zone name needs to end in a dot, to be created\n";
84 0           my $request_xml_str = <<'ENDXML';
85            
86            
87            
88             This change batch creates the %s record for %s
89            
90            
91             CREATE
92            
93             %s
94             %s
95             %s
96            
97             %s
98            
99            
100            
101            
102            
103            
104             ENDXML
105             my $request_xml = sprintf( $request_xml_str,
106 0           map { $_ }
107             $self->type, $self->name, $self->name, $self->type, $self->ttl,
108 0           join( "\n", map { "$_" } @{ $self->values } ) );
  0            
  0            
109 0           my $resp = $self->route53->request(
110             'post',
111             'https://route53.amazonaws.com/2010-10-01/' . $self->hostedzone->id . '/rrset',
112             Content => $request_xml
113             );
114             my $change = Net::Amazon::Route53::Change->new(
115             route53 => $self->route53,
116 0           ( map { lc($_) => decode_entities($resp->{ChangeInfo}{$_}) } qw/Id Status SubmittedAt/ ),
  0            
117             );
118 0           $change->refresh();
119 0 0         return $change if !$wait;
120 0           while ( lc( $change->status ) ne 'insync' ) {
121 0           sleep 2;
122 0           $change->refresh();
123             }
124 0           return $change;
125             }
126              
127              
128             =head3 delete
129              
130             $rrs->delete();
131              
132             Asks Route 53 to delete the associated record. This should be used only when
133             you want to delete the resource, not when changing a resource. In that case,
134             use the C method instead, which takes care of creating a unique change
135             in which the record is first deleted with the current details and then created
136             with the new details.
137              
138             Takes an optional boolean parameter, C, to indicate whether the request should
139             return straightaway (default, or when C is C<0>) or it should wait until the
140             request is C according to the Change's status.
141              
142             Returns a L object representing the change requested.
143              
144             =cut
145              
146             sub delete
147             {
148 0     0 1   my $self = shift;
149 0           my $wait = shift;
150 0 0         $wait = 0 if !defined $wait;
151 0           my $request_xml_str = <<'ENDXML';
152            
153            
154            
155             This change batch deletes the %s record for %s
156            
157            
158             DELETE
159            
160             %s
161             %s
162             %s
163            
164             %s
165            
166            
167            
168            
169            
170            
171             ENDXML
172             my $request_xml = sprintf( $request_xml_str,
173 0           (map { $_ } ( $self->type, $self->name, $self->name, $self->type, $self->ttl )),
174 0           join( "\n", map { "" . $_ . "" } @{ $self->values } ) );
  0            
  0            
175 0           my $resp = $self->route53->request(
176             'post',
177             'https://route53.amazonaws.com/2010-10-01/' . $self->hostedzone->id . '/rrset',
178             Content => $request_xml
179             );
180             my $change = Net::Amazon::Route53::Change->new(
181             route53 => $self->route53,
182 0           ( map { lc($_) => decode_entities($resp->{ChangeInfo}{$_}) } qw/Id Status SubmittedAt/ ),
  0            
183             );
184 0           $change->refresh();
185 0 0         return $change if !$wait;
186 0           while ( lc( $change->status ) ne 'insync' ) {
187 0           sleep 2;
188 0           $change->refresh();
189             }
190 0           return $change;
191             }
192              
193 2     2   15 no Moo;
  2         3  
  2         7  
194              
195             =head1 AUTHOR
196              
197             Marco FONTANI
198              
199             =head1 COPYRIGHT AND LICENSE
200              
201             This software is copyright (c) 2011 by Marco FONTANI.
202              
203             This is free software; you can redistribute it and/or modify it under
204             the same terms as the Perl 5 programming language system itself.
205              
206             =cut
207              
208             1;