| 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::ResourceRecordSet::Stub; | ||||||||||||
| 11 | { | ||||||||||||
| 12 | 5 | $Net::Amazon::R53::ResourceRecordSet::Stub::VERSION = '0.002'; # TRIAL | |||||||||||
| 13 | } | ||||||||||||
| 14 | |||||||||||||
| 15 | # ABSTRACT: A representation of a ResourceRecordSet | ||||||||||||
| 16 | |||||||||||||
| 17 | 5 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 5 | ▶ | use MooseX::MarkAsMethods autoclean => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 5 | ▶ | use MooseX::StrictConstructor; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 5 | ▶ | use Moose::Util::TypeConstraints qw{ enum class_type }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 5 | ▶ | use MooseX::AlwaysCoerce; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 5 | ▶ | use MooseX::AttributeShortcuts 0.017; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 5 | ▶ | use MooseX::Params::Validate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 5 | ▶ | use MooseX::Types::Moose ':all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 5 | ▶ | use MooseX::Types::Common::Numeric ':all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 5 | ▶ | use MooseX::Types::Common::String ':all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | |||||||||||||
| 30 | 5 | ▶ | use aliased 'MooseX::CoercePerAttribute'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | 5 | ▶ | use Data::Compare; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | |||||||||||||
| 34 | use overload | ||||||||||||
| 35 | 41 | ▶ | '==' => sub { shift->is_equivalent_to(shift) }, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | 1 | ▶ | '!=' => sub { ! shift->is_equivalent_to(shift) }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 5 | fallback => 1, | |||||||||||
| 38 | 5 | ; | |||||||||||
| 39 | |||||||||||||
| 40 | 5 | with 'MooseX::Traitor'; | |||||||||||
| 41 | |||||||||||||
| 42 | # "anon" type constraint | ||||||||||||
| 43 | 5 | ▶ | use constant RecordType => enum [ qw{ A AAAA CNAME MX NS PTR SOA SPF SRV TXT } ]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | |||||||||||||
| 45 | # debugging... | ||||||||||||
| 46 | #use Smart::Comments '###'; | ||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | has name => ( | ||||||||||||
| 50 | traits => [ CoercePerAttribute ], | ||||||||||||
| 51 | is => 'ro', | ||||||||||||
| 52 | isa => NonEmptySimpleStr, | ||||||||||||
| 53 | required => 1, | ||||||||||||
| 54 | 66 | ▶ | constraint => sub { /\.$/ }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 55 | coerce => { | ||||||||||||
| 56 | 1 | ▶ | NonEmptySimpleStr() => sub { "$_." }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | }, | ||||||||||||
| 58 | 5 | ); | |||||||||||
| 59 | |||||||||||||
| 60 | 5 | has type => (is => 'ro', isa => RecordType, required => 1); | |||||||||||
| 61 | 5 | has ttl => (is => 'ro', isa => PositiveOrZeroInt, predicate => 1); | |||||||||||
| 62 | |||||||||||||
| 63 | 22 | ▶ | has resource_records => (is => 'ro', isa => 'ArrayRef[Str]', builder => sub { [ ] }); | ||||||||||
|
Subroutine
_build_resource_records: called CC=1 SCAR=0.0
| |||||||||||||
| 64 | |||||||||||||
| 65 | # alias sets only | ||||||||||||
| 66 | 5 | has alias_target => ( | |||||||||||
| 67 | traits => ['Hash'], | ||||||||||||
| 68 | is => 'ro', | ||||||||||||
| 69 | isa => HashRef[NonEmptySimpleStr], | ||||||||||||
| 70 | predicate => 1, | ||||||||||||
| 71 | handles => { | ||||||||||||
| 72 | alias_target_hosted_zone_id => [ get => 'HostedZoneId' ], | ||||||||||||
| 73 | alias_target_dns_name => [ get => 'DNSName' ], | ||||||||||||
| 74 | }, | ||||||||||||
| 75 | ); | ||||||||||||
| 76 | |||||||||||||
| 77 | # weighted + latency | ||||||||||||
| 78 | 5 | has set_identifier => (is => 'ro', isa => 'Str', predicate => 1); | |||||||||||
| 79 | |||||||||||||
| 80 | # weighted only | ||||||||||||
| 81 | has weight => ( | ||||||||||||
| 82 | is => 'ro', | ||||||||||||
| 83 | isa => PositiveOrZeroInt, | ||||||||||||
| 84 | 12 | ▶ | constraint => sub { $_ < 256 }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 85 | 5 | predicate => 1, | |||||||||||
| 86 | ); | ||||||||||||
| 87 | |||||||||||||
| 88 | # latency only | ||||||||||||
| 89 | 5 | has region => (is => 'ro', isa => 'Str', predicate => 1); | |||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | 11 | ▶ | sub new_from_net_dns_rr { | ||||||||||
|
Subroutine
new_from_net_dns_rr: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 93 | 11 | my $class = shift @_; | |||||||||||
| 94 | #my ($rr, $origin, $opts) = validated_list \@_, | ||||||||||||
| 95 | 11 | my ($rr, $opts) = validated_list \@_, | |||||||||||
| 96 | rr => { isa => class_type('Net::DNS::RR') }, | ||||||||||||
| 97 | #origin => { isa => NonEmptySimpleStr, default => '.' }, | ||||||||||||
| 98 | opts => { isa => 'HashRef', default => { } }, | ||||||||||||
| 99 | ; | ||||||||||||
| 100 | |||||||||||||
| 101 | # this is made significantly easier in that if we're using a Net::DNS::RR | ||||||||||||
| 102 | # to create a stub, there will be no Route53-specific functionality | ||||||||||||
| 103 | # involved; so we'll always have a ttl (even if just 0), no alias or | ||||||||||||
| 104 | # weighted records, etc... | ||||||||||||
| 105 | |||||||||||||
| 106 | 11 | ▶ | confess 'Cannot convert a Net::DNS::RR with class: ' . $rr->class | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | unless $rr->class eq 'IN'; | ||||||||||||
| 108 | |||||||||||||
| 109 | # fixup our origin; must start/stop with a . | ||||||||||||
| 110 | #$origin .= '.' unless $origin =~ /\.$/; | ||||||||||||
| 111 | #$origin = ".$origin" unless $origin =~ /^\./; | ||||||||||||
| 112 | |||||||||||||
| 113 | # fixup our name; append $origin unless already fully-qualified | ||||||||||||
| 114 | 11 | my $name = $rr->name; | |||||||||||
| 115 | # ## name and origin: "$name / $origin" | ||||||||||||
| 116 | #$name .= $origin unless $name =~ /\.$/; | ||||||||||||
| 117 | 11 | ▶ | $name .= '.' unless $name =~ /\.$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | |||||||||||||
| 119 | 11 | ▶ | my %params = ( | ||||||||||
|
Condition100%2/2
$rr->ttl || 0
MC/DC100%1/1
$rr->ttl || 0
$rr->ttl
Truth table100%2/2
A
A= $rr->ttl
| |||||||||||||
| 120 | type => $rr->type, | ||||||||||||
| 121 | name => $name, | ||||||||||||
| 122 | ttl => $rr->ttl || 0, | ||||||||||||
| 123 | |||||||||||||
| 124 | resource_records => [ | ||||||||||||
| 125 | $rr->rdatastr, | ||||||||||||
| 126 | ], | ||||||||||||
| 127 | ); | ||||||||||||
| 128 | |||||||||||||
| 129 | ### %params | ||||||||||||
| 130 | ### $opts | ||||||||||||
| 131 | |||||||||||||
| 132 | 11 | %params = (%params, %$opts); | |||||||||||
| 133 | 11 | return $class->new(%params); | |||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | |||||||||||||
| 137 | 67 | ▶ | sub is_equivalent_to { | ||||||||||
|
Subroutine
is_equivalent_to: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||
| 138 | 67 | my ($self, $other) = @_; | |||||||||||
| 139 | |||||||||||||
| 140 | 67 | ▶ | confess 'cannot compare with ' . ref $other | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 141 | unless $other->isa('Net::Amazon::R53::ResourceRecordSet::Stub'); | ||||||||||||
| 142 | |||||||||||||
| 143 | 67 | ▶ | my $_eq = sub { my $name = shift; $self->$name() eq $other->$name() }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 144 | 162 | ▶ | my $_peq = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||
| 145 | 162 | my $name = shift; | |||||||||||
| 146 | 162 | my $pred = "has_$name"; | |||||||||||
| 147 | |||||||||||||
| 148 | 162 | ▶ | my $self_has = $self->$pred() ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 149 | 162 | ▶ | my $other_has = $other->$pred() ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 150 | |||||||||||||
| 151 | 162 | ▶ | return 1 if $self_has + $other_has == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 152 | 73 | ▶ | return if $self_has + $other_has == 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 153 | |||||||||||||
| 154 | 38 | return $self->$name().q{} eq $other->$name().q{}; | |||||||||||
| 155 | 67 | }; | |||||||||||
| 156 | |||||||||||||
| 157 | # we could really do this in a nicer fashion by looking at the metaclasses | ||||||||||||
| 158 | # and using attribute tags to store how we should use them to compare. | ||||||||||||
| 159 | |||||||||||||
| 160 | 134 | ▶ | do { return unless $_eq->($_) } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 161 | 67 | for qw{ name type }; | |||||||||||
| 162 | |||||||||||||
| 163 | 162 | ▶ | do{ return unless $_peq->($_) } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 164 | 67 | for qw{ set_identifier weight region ttl }; | |||||||||||
| 165 | |||||||||||||
| 166 | 22 | ▶ | return unless Compare($self->alias_target, $other->alias_target); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 167 | }; | ||||||||||||
| 168 | |||||||||||||
| 169 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 170 | 5 | !!42; | |||||||||||
| 171 | |||||||||||||
| 172 | __END__ | ||||||||||||