line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Dynect::REST::RData; |
2
|
|
|
|
|
|
|
# $Id: RData.pm 177 2010-09-28 00:50:02Z james $ |
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
6
|
use overload '""' => \&_as_string; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
56
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
906
|
|
7
|
|
|
|
|
|
|
our $AUTOLOAD; |
8
|
|
|
|
|
|
|
our $VERSION = do { my @r = (q$Revision: 177 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Net::Dynect::REST::RData - Record Data returned as a result of querying Dynect |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Net::Dynect::REST::ARecord; |
17
|
|
|
|
|
|
|
my @records = Net::Dynect::REST::ARecord->find(connection => $dynect, zone => $zone, fqdn => $fqdn); |
18
|
|
|
|
|
|
|
foreach (@arecords) { |
19
|
|
|
|
|
|
|
print $_->rdata; |
20
|
|
|
|
|
|
|
my @fields = $_->rdata->data_keys; |
21
|
|
|
|
|
|
|
my $address = $_->rdata->address; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 Creating |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over 4 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item new |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This constructor takes the data as decoded from the response. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=back |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
40
|
0
|
|
0
|
|
|
|
my $self = bless {}, ref($proto) || $proto; |
41
|
0
|
|
|
|
|
|
my %args = @_; |
42
|
0
|
0
|
|
|
|
|
$self->rdata( $args{data} ) if defined $args{data}; |
43
|
0
|
|
|
|
|
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub rdata { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
0
|
|
|
|
|
if (@_) { |
49
|
0
|
|
|
|
|
|
my $new = shift; |
50
|
0
|
|
|
|
|
|
$self->{data} = $new; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
return $self->{data}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 Attributes |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over 4 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item data_keys |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This returns the names of the keys of the data returned. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item other, random, names |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
As the data varies depending on the request given, so does the value returned in the response. Hence the data may have a key of B, or B, or anthing else. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub data_keys { |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
return keys %{ $self->{data} }; |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub AUTOLOAD { |
75
|
0
|
|
|
0
|
|
|
my $self = shift; |
76
|
0
|
0
|
|
|
|
|
if ( ref($self) ne "Net::Dynect::REST::RData" ) { |
77
|
0
|
|
|
|
|
|
carp "This should be a Net::Dynect::REST::RData"; |
78
|
0
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
my $name = $AUTOLOAD; |
81
|
0
|
0
|
|
|
|
|
return unless defined $self->{data}; |
82
|
0
|
|
|
|
|
|
$name =~ s/.*://; # strip fully-qualified portion |
83
|
0
|
0
|
|
|
|
|
if (@_) { |
84
|
0
|
|
|
|
|
|
my $new = shift; |
85
|
0
|
|
|
|
|
|
warn "Trying to set $name = $new"; |
86
|
0
|
0
|
|
|
|
|
if ($name eq "address") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
return unless __PACKAGE__->_is_valid_ipv4($new) || __PACKAGE__->_is_valid_ipv6($new); |
88
|
|
|
|
|
|
|
} elsif ($name eq "txtdata") { |
89
|
0
|
0
|
|
|
|
|
return unless __PACKAGE__->_is_valid_txtdata($new); |
90
|
|
|
|
|
|
|
} elsif ($name eq "cname") { |
91
|
0
|
0
|
|
|
|
|
return unless __PACKAGE__->_is_valid_fqdn($new); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
$self->{data}->{$name} = $new; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
0
|
|
|
|
|
return $self->{data}->{$name} if defined $self->{data}->{$name}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _is_valid_ipv4 { |
99
|
0
|
|
|
0
|
|
|
my $address = shift; |
100
|
0
|
|
|
|
|
|
require "Net::IP"; |
101
|
0
|
|
|
|
|
|
my $ip = Net::IP->new($address); |
102
|
0
|
|
|
|
|
|
return $ip->ip_is_ipv4; |
103
|
0
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _is_valid_ipv6 { |
107
|
0
|
|
|
0
|
|
|
my $address = shift; |
108
|
0
|
|
|
|
|
|
require "Net::IP"; |
109
|
0
|
|
|
|
|
|
my $ip = Net::IP->new($address); |
110
|
0
|
|
|
|
|
|
return $ip->ip_is_ipv6; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _is_valid_txtdata { |
114
|
0
|
|
|
0
|
|
|
my $text = shift; |
115
|
0
|
|
|
|
|
|
return length($text) <= 255; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _is_valid_fqdn { |
119
|
0
|
|
|
0
|
|
|
my $fqdn = shift; |
120
|
0
|
0
|
|
|
|
|
return 1 if $fqdn =~ /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _as_string { |
124
|
0
|
|
|
0
|
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
my @texts; |
126
|
0
|
|
|
|
|
|
foreach ( $self->data_keys ) { |
127
|
0
|
|
|
|
|
|
push @texts, sprintf "%s: %s", $_, $self->$_; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
return join( ', ', @texts ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SEE ALSO |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L, L. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
James bromberger, james@rcpt.to |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright (C) 2010 by James Bromberger |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
147
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.1 or, |
148
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |