File Coverage

blib/lib/Net/Dynect/REST/ZoneChanges.pm
Criterion Covered Total %
statement 15 71 21.1
branch 0 30 0.0
condition 0 3 0.0
subroutine 5 11 45.4
pod 3 5 60.0
total 23 120 19.1


line stmt bran cond sub pod time code
1             package Net::Dynect::REST::ZoneChanges;
2             # $Id: ZoneChanges.pm 177 2010-09-28 00:50:02Z james $
3 1     1   1650 use strict;
  1         2  
  1         39  
4 1     1   6 use warnings;
  1         2  
  1         43  
5 1     1   5 use overload '""' => \&_as_string;
  1         2  
  1         11  
6 1     1   73 use Carp;
  1         2  
  1         86  
7 1     1   629 use Net::Dynect::REST::RData;
  1         3  
  1         831  
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::Zone - List changes pending for a DNS zone
13              
14             =cut
15              
16             sub new {
17 0     0 1   my $proto = shift;
18 0   0       my $self = bless {}, ref($proto) || $proto;
19 0           my %args = @_;
20 0 0         $self->{connection} = $args{connection} if defined $args{connection};
21 0 0         $self->get( $args{zone} ) if defined $args{zone};
22 0           return $self;
23             }
24              
25             sub get {
26 0     0 1   my $self = shift;
27 0           my $zone = shift;
28 0 0         if ( not defined $zone ) {
29 0           carp "Need a zone to check changes for";
30 0           return;
31             }
32 0 0         if ( not defined $self->{connection} ) {
33 0           carp "Don't have a connection";
34 0           return;
35             }
36 0           my $request = Net::Dynect::REST::Request->new(
37             operation => 'read',
38             service => "ZoneChanges/$zone"
39             );
40 0           my $response = $self->{connection}->execute($request);
41 0 0         if ( $response->status !~ /^success$/i ) {
42 0           carp "" . $response;
43 0           return;
44             }
45 0           $self->zone($zone);
46 0 0         return 1 unless $response->data;
47 0           foreach ( @{ $response->data } ) {
  0            
48 0           push @{ $self->{changes} },
  0            
49             Net::Dynect::REST::RData->new( data => $_->{data}->{value} );
50             }
51 0           return 1;
52             }
53              
54             sub delete {
55 0     0 1   my $self = shift;
56 0 0         return unless defined $self->{connection};
57 0           my $request = Net::Dynect::REST::Request->new(
58             operation => 'delete',
59             service => 'ZoneChanges/' . $self->zone
60             );
61 0           my $response = $self->{connection}->execute($request);
62 0 0         if ( $response->status =~ /^success$/i ) {
63 0           $self = undef;
64 0           return 1;
65             }
66             else {
67 0           print $response->msg->[0]->info;
68             }
69             }
70              
71             sub zone {
72 0     0 0   my $self = shift;
73 0 0         if (@_) {
74 0           my $new = shift;
75 0 0         if ( defined $self->{zone} ) {
    0          
76 0           carp
77             "Cannot change name from what it has been set to. Create a new instance for a new zone, and delete the old one";
78 0           return;
79             }
80             elsif ( $new !~ /^\S+/ ) {
81 0           carp "Zone names must not have spaces in them";
82 0           return;
83             }
84 0           $self->{zone} = $new;
85             }
86 0           return $self->{zone};
87             }
88              
89             sub changes {
90 0     0 0   my $self = shift;
91 0 0         if (@_) {
92 0           my $new = shift;
93 0           my $self->{changes} = $new;
94             }
95 0           return $self->{changes};
96             }
97              
98             sub _as_string {
99 0     0     my $self = shift;
100 0           my @texts;
101 0 0         push @texts, sprintf "Zone '%s'", $self->name if defined $self->name;
102 0           push @texts, sprintf "Changes:\n", join( "\n", $self->changes );
103 0 0         push @texts, sprintf "Serial '%s'", $self->serial if defined $self->serial;
104 0 0         push @texts, sprintf "Serial Style '%s'", $self->serial_style
105             if defined $self->serial_style;
106 0           return join( ', ', @texts );
107             }
108              
109             1;
110              
111              
112             =head1 SYNOPSIS
113              
114             use Net::Dynect::REST;
115             use Net::Dynect::REST::Zone;
116             $dynect = Net::Dynect::REST->new(user_name => 'me', customer_name => 'myco', password => 'secret');
117             $zone = Net::Dynect::REST::Zone->new(connection => $dynect, zone => 'example.com');
118             print "Zone details: $zone\n";
119              
120             $zone->freeze;
121             $zone->thaw;
122             $zone->publish;
123             $zone->delete;
124              
125             $new_zone = Net::Dynect::REST::Zone->new(connection => $dynect);
126             $zone->name('new.example.com');
127             $zone->serial_style('increment');
128             $zone->zone_type('Primary');
129             $zone->save(rname => 'admin@example.com', ttl => 900);
130              
131             =head1 REQUIRES
132              
133             Net::Dynect::REST, Carp
134              
135             =head1 EXPORTS
136              
137             Nothing
138              
139             =head1 Description
140              
141             A Net::Dynect::REST::Zone is a representation of a DNS Zone in the Dynect REST interface. It permits the user to load zones that already exist, inspect their attributes (eg, serial number), freeze the zone from modification, thaw the zone, publish zone changes live, delete the zone, and create a new zone.
142              
143             =head1 METHODS
144              
145             =head2 Creation
146              
147             =over 4
148              
149             =item Net::Dynect::REST::Zone->new(connection => $dynect)
150              
151             Creates and returns a Net::Dynect::REST::Zone object. You should pass this method your connection object, which should have a valid session established, in order to do anything useful.
152              
153             =back
154              
155             =head2 Operations
156              
157             =over 4
158              
159             =item $zone->get('zone.to.get.com');
160              
161             This will attempt to get the details of the zone from Dynect.
162              
163             =item $zone->save(rname => 'admin@example.com', ttl => 900);
164              
165             This will try to save a new zone (which has already had its name and serial style set via the L below). You must supply the "I" parameter of the email address for the resposible person, and you may supply a I value.
166              
167              
168             =item $zone->delete();
169              
170             This will tryt o delete the zone that was previously loaded.
171              
172             =item $zone->freeze();
173              
174             This will freeze the zone from any changes.
175              
176             =item $zone->thaw();
177              
178             This will unfreeze the zone and permit changes.
179              
180             =item $zone->publish();
181              
182             This will commit changes to the zone to the live production environment.
183              
184             =back
185              
186             =head2 Attributes
187              
188             =over 4
189              
190             =item $zone->name();
191              
192             This will get (or set) the zone's name, eg: example.com.
193              
194             =item $zone->serial();
195              
196             This will get (or set) the zones serial number.
197              
198             =item $zone->zone_type();
199              
200             This will get (or set) the zone type, either:
201              
202             =over 4
203              
204             =item * Primary
205              
206             =item * Secondary
207              
208             =back
209              
210             =item $zone->serial_style();
211              
212             This will get or set the serial style for the zone, either
213              
214             =over 4
215              
216             =item * increment
217              
218             =item * epoch
219              
220             =item * day
221              
222             =item * minute
223              
224             =back
225              
226             =back
227              
228             =head1 AUTHOR
229              
230             James Bromberger, james@rcpt.to
231              
232             =head1 SEE ALSO
233              
234             L, L, L, L.
235              
236             =head1 COPYRIGHT AND LICENSE
237              
238             Copyright (C) 2010 by James Bromberger
239              
240             This library is free software; you can redistribute it and/or modify
241             it under the same terms as Perl itself, either Perl version 5.10.1 or,
242             at your option, any later version of Perl 5 you may have available.
243              
244              
245              
246              
247             =cut