DNS.pm

filter: Statementstmt 68.2% 28 / 41 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 100% 4 / 4 totaltotal 62.1% 41 / 66 CC 4 SCAR 17.8
CC
4
Cov
60%
new
20.0
zones
2.0
records
2.0
CRAP 5.9
« DNS/Records.pm ↑ Summary DNS/Owner.pm »
1 package Net::Duowan::DNS;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Net::Duowan::DNS::Zones;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Net::Duowan::DNS::Records;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Net::Duowan::DNS::Owner;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $VERSION = '1.2.0';
14  
15 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
16 0 my $class = shift;
17 0 my %arg = @_;
18
19 0 ▶ my $psp = $arg{passport} || croak "no passport provided";
Condition0%0/2
$arg{'passport'} || croak('no passport provided')
l!l
00
MC/DC0%0/1
$arg{'passport'} || croak('no passport provided')
$arg{'passport'}
Truth table0%0/2
A
A= $arg{'passport'}
Aresult
11
00
20 0 ▶ my $token = $arg{token} || croak "no token provided";
Condition0%0/2
$arg{'token'} || croak('no token provided')
l!l
00
MC/DC0%0/1
$arg{'token'} || croak('no token provided')
$arg{'token'}
Truth table0%0/2
A
A= $arg{'token'}
Aresult
11
00
21  
22 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require LWP::Protocol::https } } or croak("LWP::Protocol::https along with LWP::UserAgent is required") 0 0 0
23 0 require LWP::Protocol::https;
24 } or croak "LWP::Protocol::https along with LWP::UserAgent is required";
25  
26 0 bless { psp => $psp, token => $token }, $class;
27 }
28  
29 0 ▶sub zones {
Subroutine zones: not called CC=1 SCAR=6.9
Pod documented
30 0 my $self = shift;
31 0 return Net::Duowan::DNS::Zones->new($self->{psp},$self->{token} );
32 }
33  
34 0 ▶sub records {
Subroutine records: not called CC=1 SCAR=6.9
Pod documented
35 0 my $self = shift;
36 0 return Net::Duowan::DNS::Records->new($self->{psp},$self->{token} );
37 }
38  
39 0 ▶sub owner {
Subroutine owner: not called CC=1 SCAR=6.9
Pod documented
40 0 my $self = shift;
41 0 return Net::Duowan::DNS::Owner->new($self->{psp},$self->{token} );
42 }
43  
44 2 1;
45  
46 =head1 NAME
47  
48 Net::Duowan::DNS - Perl client for YY ClouDNS API
49  
50 =head1 VERSION
51  
52 Version 1.2.0
53  
54 =head1 SYNOPSIS
55  
56 use Net::Duowan::DNS;
57  
58 my $dwdns = Net::Duowan::DNS->new(passport => 'YY_Passport',
59 token => 'Token_to_verify');
60  
61 # the object for the owner
62 my $o = $dwdns->owner;
63  
64 # the object for zones management
65 my $z = $dwdns->zones;
66  
67 # the object for records management
68 my $r = $dwdns->records;
69  
70 ##########################
71 # owner operation methods
72 ###########################
73
74 # re-generate the token, the new token is included in the returned hashref
75 $re = $o->reGenerateToken;
76  
77 # fetch the operation logs, the default offset and number are 0 and 100
78 # the log items are utf-8 encoded, you may want to encode_utf8(item) before printing them
79 $re = $o->fetchOpsLog(number=>10,offset=>0);
80  
81 # fetch the history for zone applying, the default offset and number are 0 and 100
82 $re = $o->fetchZoneApplyHistory(number=>10,offset=>0);
83  
84 ##########################
85 # zones management methods
86 ###########################
87
88 # fetch all zones under an user
89 # you can also use offset and number to limit the returned items
90 $re = $z->fetch;
91  
92 # check the information for special zones
93 $re = $z->check('zone1.com','zone2.com');
94  
95 # create a zone
96 # for both zone create and remove, you should be able to notice from the returned message that,
97 # they don't become effective at once, but wait for the administrator to approve them
98 # about zone status:
99 # 0 - prepare to be activated
100 # 1 - activated
101 # 2 - prepare to be deleted
102 $re = $z->create('zone.com');
103  
104 # remove a zone
105 $re = $z->remove('zone.com');
106  
107 ##########################
108 # records management methods
109 ###########################
110  
111 # fetch the records from a zone, the default offset and number are 0 and 100
112 # you may specify offset=>0, number=>-1 to get all the records for this zone
113 $re = $r->fetchMulti('zone.com',offset=>0,number=>10);
114  
115 # fetch records' size within a zone
116 $re = $r->fetchSize('zone.com');
117  
118 # fetch a record, you should specify the record id
119 # the record's options are included in the returned hashref
120 $r->fetchOne('zone.com',rid=>123);
121  
122 # create a record
123 # name - the hostname for a record
124 # content - the record value
125 # isp - with either tel or uni from China ISP
126 # type - A, CNAME, MX, TXT, NS, AAAA
127 # ttl - time to live, in seconds
128 # about the record status:
129 # 0 - prepare to be activated
130 # 1 - activated
131 # 2 - prepare to be deleted
132 $re = $r->create('zone.com',name=>'www',content=>'11.22.33.44',isp=>'tel',type=>'A',ttl=>300);
133  
134 # modify a record, you must specify the rid to be modified
135 $re = $r->modify('zone.com',rid=>123,name=>'www',content=>'5.6.7.8',isp=>'uni',type=>'A',ttl=>300);
136  
137 # remove a record, you must specify the rid to be removed
138 $re = $r->remove('zone.com',rid=>123);
139  
140 # bulk remove records, all records included in the rids list are removed
141 $re = $r->bulkRemove('zone.com',rids=>[123,456]);
142  
143 # remove records by hostname
144 $re = $r->removebyHost('zone.com',name=>'www');
145  
146 # bulk create records, the value for records is a list
147 # each element in the list must be the record options
148 my $rec =
149 [ { type => "A",
150 name => "test1",
151 content => "1.2.3.4",
152 isp => "tel",
153 ttl => 300
154 },
155 { type => "A",
156 name => "test1",
157 content => "5.6.7.8",
158 isp => "uni",
159 ttl => 300
160 }
161 ];
162  
163 $re = $r->bulkCreate('zone.com',records=>$rec);
164  
165 # search records with the keyword
166 # it will search from the name and content fields with the keyword
167 # you can also use offset,number to limit the returned items
168 $r->search('zone.com',keyword=>'test');
169  
170 # fetch records by hostname
171 # all records with the specified hostname will be included in the hashref
172 # you can also use offset,number to limit the returned items
173 $re = $r->fetchbyHost('zone.com',name=>'www');
174  
175 # fetch records by wild matching within the hostname string
176 # the example below gets the records of test1.zone.com, test2.zone.com, ...
177 $re = $r->fetchbyPrefix('zone.com',prefix=>'test*');
178  
179 ##########################
180 # print out the results
181 ###########################
182
183 # the result returned is a hash reference, just dump it
184 # you should get the wanted data from the hashref
185 # in the future version I may decode the hashref, return all options as methods
186 # but in the current release you should be able to parse the hash by your end
187 use Data::Dumper;
188 print Dumper $re;
189  
190  
191 =head1 METHODS
192  
193 =head2 new(passport=>'string', token=>'string')
194  
195 The class method for initializing the object.
196  
197 To use the API, you firstly should sign up an account on YY.com, that's your passport.
198  
199 The token is obtained from YY ClouDNS's user management panel.
200  
201 For more details please check the API document from their official website:
202  
203 http://dnscp.duowan.com/
204  
205 =head2 owner()
206  
207 Got an object for the owner, who has several methods for the user management
208  
209 =head2 zones()
210  
211 Got an object which has all methods for zones management
212  
213 =head2 records()
214  
215 Got an object which has all methods for records management
216  
217 =head1 AUTHOR
218  
219 Ken Peng <yhpeng@cpan.org>
220  
221 =head1 BUGS/LIMITATIONS
222  
223 If you have found bugs, please send email to <yhpeng@cpan.org>
224  
225 =head1 SUPPORT
226  
227 You can find documentation for this module with the perldoc command.
228  
229 perldoc Net::Duowan::DNS
230  
231 =head1 COPYRIGHT & LICENSE
232  
233 Copyright 2013 Ken Peng, all rights reserved.
234  
235 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« DNS/Records.pm ↑ Summary DNS/Owner.pm »