R53/HostedZone.pm

filter: Statementstmt 65.7% 73 / 111 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 65.5% 19 / 29 Podpod 100% 3 / 3 totaltotal 56.8% 95 / 167 CC 12 SCAR 28.1
CC
12
Cov
56%
submit_resource_records_change_request
72.0
apply_atomic_change
12.0
_build_resource_record_sets
6.0
CRAP 16.7
« R53/ResourceRecordSet.pm ↑ Summary R53.pm »
1 #
2 # This file is part of Net-Amazon-R53
3 #
4 # This software is Copyright (c) 2012 by Campus Explorer, Inc.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Net::Amazon::R53::HostedZone;
11 {
12 1 $Net::Amazon::R53::HostedZone::VERSION = '0.002'; # TRIAL
13 }
14  
15 # ABSTRACT: Representation of a Route53 HostedZone
16  
17 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use autobox::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Moose::Util::TypeConstraints qw{ class_type union };
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use MooseX::AlwaysCoerce;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use MooseX::AttributeShortcuts 0.017;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use MooseX::CascadeClearing;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use MooseX::Types::Moose ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use MooseX::Types::Common::Numeric ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use MooseX::Types::Common::String ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use List::AllUtils 'natatime';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use constant RRSChangeType => class_type 'Net::Amazon::R53::ResourceRecordSet::Change';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use constant RRSType => class_type 'Net::Amazon::R53::ResourceRecordSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant ArrayOfRRS => do { ArrayRef[RRSType] };
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 # debugging...
42 #use Smart::Comments '####';
43  
44 1 with 'MooseX::Traitor';
45 1 with
46 'Net::Amazon::R53::Role::NewFromRawData',
47 'Net::Amazon::R53::Role::ParentR53',
48 ;
49  
50  
51  
52 1 has caller_reference => (is => 'ro', isa => NonEmptySimpleStr, required => 1);
53 1 has comment => (is => 'ro', isa => 'Str');
54 0 ▶has config => (is => 'ro', isa => 'ArrayRef', builder => sub { [ ] });
Subroutine _build_config: not called CC=1 SCAR=1.2
55 1 has id => (is => 'ro', isa => NonEmptySimpleStr, required => 1);
56 1 has name => (is => 'ro', isa => NonEmptySimpleStr, required => 1);
57  
58 has resource_record_set_count => (
59 is => 'rwp',
60 isa => PositiveOrZeroInt,
61 lazy => 1,
62 required => 1,
63 clearer => -1,
64 predicate => -1,
65 clear_master => 'resource_record_sets',
66 # see CMOP::Attribute docs for initalizer
67 # initializer WILL FIRE on builders too (wtf?!)
68 0 ▶ initializer => sub { $_[2]->($_[1]-2) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 ▶ builder => sub { shift->_rrss_count },
Subroutine _build_resource_record_set_count: not called CC=1 SCAR=6.9
70 1 );
71  
72  
73 has plain_id => (
74 is => 'lazy',
75 isa => NonEmptySimpleStr,
76 0 ▶ builder => sub { shift->id->split(qr!/!)->pop },
Subroutine _build_plain_id: not called CC=1 SCAR=6.9
77 1 );
78  
79  
80 # Yes, the assumption here is that the first two RRS are always the
81 # amazon-immutable ones. I don't think this is a dangerous assumption to
82 # make, particularly with this level of the API.
83  
84 has immutable_record_sets => (
85 is => 'rwp',
86 isa => ArrayOfRRS,
87 lazy => 1,
88 clearer => -1,
89 clear_master => 'resource_record_sets',
90 0 ▶ builder => sub { [ $_[0]->_rrs(0), $_[0]->_rrs(1) ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 1 );
92  
93 has resource_record_sets => (
94 traits => ['Array'],
95 is => 'rwp',
96 isa => ArrayOfRRS,
97 lazy => 1,
98 clearer => 1,
99 is_clear_master => 1,
100 0 ▶ builder => sub { my @r = shift->_rrss; shift @r for 1..2; \@r },
Subroutine _build_resource_record_sets: not called CC=2 SCAR=17.9
101 1 handles => {
102 has_resource_record_sets => 'count',
103 resource_record_set => 'get',
104 is_pristine_zone => 'is_empty',
105 _add_resource_record_set => 'push',
106 _resource_record_set_count => 'count',
107 },
108 );
109  
110 # This is the "real" list of resource record sets. we're set up such that the
111 # two attributes above use this attribute to provide their data, so either
112 # one being built will trigger this one. Likewise, the only public clearer
113 # either three of these have is clear_resource_record_sets, but that's
114 # cascaded out to the other two attributes, so calling that clearer will
115 # actually clear all three of these attributes.
116  
117 1 has _all_rrs => (
118 traits => ['Array'],
119 is => 'lazy',
120 isa => ArrayOfRRS,
121 clearer => -1,
122 predicate => 'has_fetched_resource_record_sets',
123 clear_master => 'resource_record_sets',
124 handles => {
125 _rrss => 'elements',
126 _rrs => 'get',
127 _rrss_count => 'count',
128 },
129 );
130  
131 0 ▶sub _build__all_rrs {
Subroutine _build__all_rrs: not called CC=1 SCAR=6.9
132 0 my $self = shift @_;
133  
134 0 $self->_clear_resource_record_set_count;
135 0 return $self->r53->get_resource_record_sets($self->plain_id);
136 }
137  
138  
139 0 ▶sub apply_atomic_change {
Subroutine apply_atomic_change: not called CC=3 SCAR=24.8
Pod documented
140 0 my ($self, $ac) = @_;
141  
142 0 ▶ die 'an AtomicChange instance must be presented'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($ac) and $ac->isa("Net::Amazon::R53::AtomicChange") 0 0 0
Condition0%0/3
builtin::blessed($ac) and $ac->isa("Net::Amazon::R53::AtomicChange")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($ac) and $ac->isa("Net::Amazon::R53::AtomicChange")
builtin::blessed($ac) $ac->isa("Net::Amazon::R53::AtomicChange")
Truth table0%0/3
A and B
A= builtin::blessed($ac)B= $ac->isa("Net::Amazon::R53::AtomicChange")
ABresult
0X0
100
111
143 unless blessed $ac && $ac->isa('Net::Amazon::R53::AtomicChange');
144  
145 0 my $change = $self->submit_resource_records_change_request(
146 comment => 'Atomic changeset',
147 changes => $ac->changes,
148 multi_batch_ok => 0,
149 );
150  
151 0 return $change;
152 }
153  
154  
155 0 ▶sub submit_resource_records_change_request {
Subroutine submit_resource_records_change_request: not called CC=8 SCAR=42.8
Pod documented
156 0 my $self = shift @_;
157  
158 0 my ($comment, $changes, $multi_batch_ok) = validated_list \@_,
159 comment => { isa => 'Str', default => 'Batch change API initiated' },
160 changes => { isa => ArrayRef [ union [ RRSChangeType, HashRef ] ] },
161 multi_batch_ok => { isa => Bool, default => 0 },
162 ;
163  
164 0 ▶ confess 'Batch is > 100, but multi_batch_ok is not set!'
Branch: 1 branch
BranchTrueFalseTotal
if $changes->length > 100 and not $multi_batch_ok 0 0 0
Condition0%0/3
$changes->length > 100 and not $multi_batch_ok
!ll&&!rl&&r
000
MC/DC0%0/2
$changes->length > 100 and not $multi_batch_ok
$changes->length > 100 not $multi_batch_ok
Truth table0%0/3
A and not(B)
A= $changes->length > 100B= not $multi_batch_ok
ABresult
0X0
100
111
165 if $changes->length > 100 && !$multi_batch_ok;
166  
167 0 my $cclass = $self->resource_record_set__change_class;
168  
169 0 ▶ do { $_ = $cclass->new(%$_, r53 => $self->r53) unless blessed $_ }
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_) 0 0 0
170 0 for @$changes;
171  
172 0 my $part = 'hostedzone/' . $self->plain_id . '/rrset';
173 0 my $tmpl = 'batch_rrs_change.tt';
174 0 my @info = ();
175 0 my $it = natatime 100, @$changes;
176  
177 0 ▶ while (my @changes_chunk = $it->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@changes_chunk) = &$it()) 0 0 0
178  
179 ### issuing batch change command...
180 0 ▶ $self->r53->tt->process(
Branch: 1 branch
BranchTrueFalseTotal
$self->r53->tt->process($tmpl, {"comment", $comment, "changes", [@changes_chunk]}, \my $req_content) or confess($self->r53->tt->error) 0 0 0
181 $tmpl,
182 { comment => $comment, changes => [ @changes_chunk ] },
183 \(my $req_content),
184 ) || confess $self->r53->tt->error;
185  
186 ### $req_content
187 0 my $resp = $self->r53->post_request($part, $req_content);
188  
189 ### response: $resp->content
190 0 my $info_returned = XMLin($resp->content);
191 push @info, $self
192 ->change_info_class
193 ->new_from_raw_data($self->r53, $info_returned->{ChangeInfo})
194 0 ;
195 }
196  
197 ### remove existing and return the change record...
198 0 $self->clear_resource_record_sets;
199 0 ▶ return @info if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
200 0 return pop @info;
201 }
202  
203  
204 0 ▶sub purge {
Subroutine purge: not called CC=2 SCAR=17.9
Pod documented
205 0 my $self = shift @_;
206  
207 0 ▶ return unless $self->has_resource_record_sets;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_resource_record_sets 0 0 0
208  
209 my @changes =
210 0 map { { action => 'DELETE', record => $_ } }
211 $self->resource_record_sets->flatten
212 ;
213  
214 0 return $self->submit_resource_records_change_request(
215 comment => 'zone-purge requested',
216 changes => \@changes,
217 multi_batch_ok => 1,
218 );
219 }
220  
221 1 __PACKAGE__->meta->make_immutable;
222 1 !!42;
223  
224 __END__
« R53/ResourceRecordSet.pm ↑ Summary R53.pm »