blib/lib/Net/DNS/ValueDomain/DDNS.pm

filter: Statementstmt 95.2% 60 / 63 Branchbran 67.8% 19 / 28 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 88.6% 101 / 114 CC 18 SCAR 17.9
CC
18
Cov
88%
update
10.1
protocol
6.0
new
5.2
CRAP 6.0
↑ Summary
1 package Net::DNS::ValueDomain::DDNS;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base qw/Class::Accessor::Fast Class::ErrorHandler/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '0.02';
13  
14 3 Readonly::Scalar my $URL => 'dyn.value-domain.com/cgi-bin/dyn.fcg';
15 3 Readonly::Scalar my $SSL_PREFIX => 'ss1.xrea.com';
16  
17 3 __PACKAGE__->mk_accessors(qw/ua/);
18  
19 =head1 NAME
20  
21 Net::DNS::ValueDomain::DDNS - Update your Value-Domain (https://www.value-domain.com/) DynamicDNS records.
22  
23 =head1 SYNOPSIS
24  
25 use Net::DNS::ValueDomain::DDNS;
26
27 # Normal usage
28 my $ddns = Net::DNS::ValueDomain::DDNS->new;
29
30 $ddns->update(
31 domain => 'example.com',
32 password => '1234',
33 host => 'www',
34 ip => '127.0.0.1',
35 );
36
37 # Update multiple hosts on same IP
38 my $ddns = Net::DNS::ValueDomain::DDNS->new(
39 domain => 'example.com',
40 password => '1234',
41 ip => '127.0.0.1',
42 );
43
44 for my $host (qw/www mail */) {
45 $ddns->update( host => $host ) or die $ddns->errstr;
46 }
47  
48 =head1 DESCRIPTION
49  
50 This module help you to update your Value-Domain (https://www.value-domain.com/) DynamicDNS record(s).
51  
52 =head1 METHODS
53  
54 =head2 new( %config | \%config )
55  
56 Create a new Object. All %config keys and values (except 'host' and 'domain') is kept and reused by update() function.
57  
58 =cut
59  
60 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.5
Pod documented
61 1 my $class = shift;
62 1 ▶ my $config = @_ > 1 ? {@_} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 1 1
63  
64 1 my $self = bless {}, $class;
65  
66 1 ▶ $self->config($config) if $config;
Branch: 1 branch
BranchTrueFalseTotal
if $config 0 1 1
67  
68 1 ▶ if ( !$self->config->{use_https} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->config->{"use_https"}) 1 0 1
69 1 eval { require Crypt::SSLeay; };
70 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 0 1
71 1 carp
72 "Require Crypt::SSLeay for ssl connection. If you don't want to do that, try new( use_https => 0 ).";
73 1 $self->config->{use_https} = 0;
74 }
75 }
76  
77 1 $self->ua( LWP::UserAgent->new );
78  
79 1 $self;
80 }
81  
82 =head2 config( %config | \%config )
83  
84 set config veriables
85  
86 =cut
87  
88 11 ▶sub config {
Subroutine config: called CC=4 SCAR=13.9
Pod documented
89 11 my $self = shift;
90 11 ▶ my $config = @_ > 1 ? {@_} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 11 11
91  
92 11 ▶ $self->{_config} ||= {};
Condition100%2/2
$self->{"_config"} ||= {}
l!l
101
MC/DC100%1/1
$self->{"_config"} ||= {}
$self->{"_config"}
Truth table100%2/2
A
A= $self->{"_config"}
Aresult
11
00
93  
94 11 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 5 6 11
95 5 map { $self->{_config}->{$_} = $config->{$_} } keys %$config;
96 }
97  
98 11 $self->{_config};
99 }
100  
101 =head2 protocol
102  
103 return used protocol name. 'http' or 'https'
104  
105 =cut
106  
107 0 ▶sub protocol {
Subroutine protocol: not called CC=2 SCAR=17.9
Pod documented
108 0 ▶ shift->config->{use_https} ? 'https' : 'http';
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->config->{'use_https'} ? : 0 0 0
109 }
110  
111 =head2 update( %config | \%config )
112  
113 Update your DynamicDNS record. %config parameters are:
114  
115 =over 4
116  
117 C<domain> - Domain name being updated. (Required)
118  
119 C<password> - Value-Domain Dynamic DNS Password. (Required)
120  
121 C<host> - Sub-domain name being updated. For example if your hostname is "www.example.com" you should set "www" here. (Optional)
122  
123 C<ip> - The IP address to be updated. if empty, your current ip is used. (Optional)
124  
125 =back
126  
127 If something error has be occurred, return undef. Use errstr() method to get error message.
128  
129 =cut
130  
131 6 ▶sub update {
Subroutine update: called CC=10 SCAR=23.1
Pod documented
132 6 my $self = shift;
133 6 ▶ my $args = @_ > 1 ? {@_} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 3 3 6
134  
135 6 my $config = $self->config($args);
136  
137 6 ▶ croak 'domain is required' unless $config->{domain};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"domain"} 1 5 6
138 5 ▶ croak 'password is required' unless $config->{password};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"password"} 1 4 5
139  
140 my $url =
141 ( $config->{use_https} )
142 4 ▶ ? "https://$SSL_PREFIX/$URL"
Branch: 1 branch
BranchTrueFalseTotal
$config->{'use_https'} ? : 0 4 4
143 : "http://$URL";
144  
145 my $parameters = {
146 d => $config->{domain},
147 p => $config->{password},
148 h => $config->{host} || q{},
149 4 ▶ i => $config->{ip} || q{},
Condition100%4/4
$config->{'host'} || ''
l!l
22
$config->{'ip'} || ''
l!l
22
MC/DC100%1/1
$config->{'host'} || ''
$config->{'host'}
MC/DC100%1/1
$config->{'ip'} || ''
$config->{'ip'}
Truth table100%2/2
A
A= $config->{'host'}
Aresult
11
00
Truth table100%2/2
A
A= $config->{'ip'}
Aresult
11
00
150 };
151 4 my $query = '?';
152 4 ▶ while ( my ( $k, $v ) = each %$parameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$parameters) 16 4 20
153 16 $query .= "$k=$v&",;
154 }
155  
156 4 my $res = $self->ua->get( $url . $query );
157  
158 4 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 4 4
159 0 $self->error( $res->status_line );
160 0 return;
161 }
162  
163 4 ▶ unless ( $res->content =~ /status=0/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->content =~ /status=0/) 1 3 4
164 1 my $error = $res->content;
165 1 chomp $error;
166 1 $self->error($error);
167 1 return;
168 }
169  
170 3 1;
171 }
172  
173 =head2 errstr()
174  
175 return last error.
176  
177 =head1 ACCESSORS
178  
179 =head2 ua
180  
181 L<LWP::UserAgent> object.
182  
183 =head1 AUTHOR
184  
185 Daisuke Murase, E<lt>typester@cpan.orgE<gt>
186  
187 =head1 LICENSE
188  
189 This library is free software; you can redistribute it and/or modify
190 it under the same terms as Perl itself.
191  
192 =cut
193  
194 3 1;
↑ Summary