Object-oriented protocol definitions
This improves readability and will make it easier to refactor to fix issues or add features.
This commit is contained in:
parent
2da08cceb9
commit
1e3bebc60d
7 changed files with 312 additions and 188 deletions
465
ddclient.in
465
ddclient.in
File diff suppressed because it is too large
Load diff
|
@ -155,7 +155,7 @@ for my $tc (@test_cases) {
|
|||
local %ddclient::recap;
|
||||
{
|
||||
local $ddclient::_l = $l;
|
||||
ddclient::nic_directnic_update(sort(keys(%{$tc->{cfg}})));
|
||||
ddclient::nic_directnic_update(undef, sort(keys(%{$tc->{cfg}})));
|
||||
}
|
||||
is_deeply(\%ddclient::recap, $tc->{wantrecap}, "$tc->{desc}: recap")
|
||||
or diag(ddclient::repr(Values => [\%ddclient::recap, $tc->{wantrecap}],
|
||||
|
|
|
@ -41,7 +41,7 @@ my $ua = LWP::UserAgent->new;
|
|||
sub test_nic_dnsexit2_update {
|
||||
my ($config, @hostnames) = @_;
|
||||
%ddclient::config = %$config;
|
||||
ddclient::nic_dnsexit2_update(@hostnames);
|
||||
ddclient::nic_dnsexit2_update(undef, @hostnames);
|
||||
}
|
||||
|
||||
sub decode_and_sort_array {
|
||||
|
|
|
@ -266,7 +266,7 @@ for my $tc (@test_cases) {
|
|||
map("line: $_", @{$tc->{resp}}),
|
||||
);
|
||||
local $ddclient::_l = $l;
|
||||
ddclient::nic_dyndns2_update(sort(keys(%{$tc->{cfg}})));
|
||||
ddclient::nic_dyndns2_update(undef, sort(keys(%{$tc->{cfg}})));
|
||||
}
|
||||
is_deeply(\%ddclient::recap, $tc->{wantrecap}, "$tc->{desc}: recap")
|
||||
or diag(ddclient::repr(Values => [\%ddclient::recap, $tc->{wantrecap}],
|
||||
|
|
|
@ -6,19 +6,19 @@ eval { require 'ddclient'; } or BAIL_OUT($@);
|
|||
local $ddclient::globals{debug} = 1;
|
||||
local $ddclient::globals{verbose} = 1;
|
||||
local %ddclient::protocols = (
|
||||
protocol_a => {
|
||||
protocol_a => ddclient::Protocol->new(
|
||||
variables => {
|
||||
host => {type => ddclient::T_STRING(), recap => 1},
|
||||
var_a => {type => ddclient::T_BOOL(), recap => 1},
|
||||
},
|
||||
},
|
||||
protocol_b => {
|
||||
),
|
||||
protocol_b => ddclient::Protocol->new(
|
||||
variables => {
|
||||
host => {type => ddclient::T_STRING(), recap => 1},
|
||||
var_b => {type => ddclient::T_NUMBER(), recap => 1},
|
||||
var_b_non_recap => {type => ddclient::T_ANY()},
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
local %ddclient::variables =
|
||||
(merged => {map({ %{$ddclient::protocols{$_}{variables}}; } sort(keys(%ddclient::protocols)))});
|
||||
|
|
|
@ -47,8 +47,9 @@ local %ddclient::protocols = (
|
|||
# The `legacy` protocol reads the legacy `wantip` property and sets the legacy `ip` and `status`
|
||||
# properties. (Modern protocol implementations read `wantipv4` and `wantipv6` and set `ipv4`,
|
||||
# `ipv6`, `status-ipv4`, and `status-ipv6`.) It always succeeds.
|
||||
legacy => {
|
||||
update => ddclient::adapt_legacy_update(sub {
|
||||
legacy => ddclient::LegacyProtocol->new(
|
||||
update => sub {
|
||||
my $self = shift;
|
||||
ddclient::debug('in update');
|
||||
for my $h (@_) {
|
||||
local $ddclient::_l = ddclient::pushlogctx($h);
|
||||
|
@ -59,11 +60,8 @@ local %ddclient::protocols = (
|
|||
$ddclient::recap{$h}{mtime} = $ddclient::now;
|
||||
}
|
||||
ddclient::debug('returning from update');
|
||||
}),
|
||||
variables => {
|
||||
%{$ddclient::variables{'protocol-common-defaults'}},
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
my @test_cases = (
|
||||
|
|
|
@ -77,8 +77,7 @@ my @use_test_cases = (
|
|||
);
|
||||
for my $tc (@use_test_cases) {
|
||||
my $desc = "'use' dynamic default: $tc->{desc}";
|
||||
local %ddclient::protocols =
|
||||
(protocol => {variables => $ddclient::variables{'protocol-common-defaults'}});
|
||||
local %ddclient::protocols = (protocol => ddclient::Protocol->new());
|
||||
local %ddclient::variables = (merged => {
|
||||
'protocol' => $ddclient::variables{'merged'}{'protocol'},
|
||||
'use' => $ddclient::variables{'protocol-common-defaults'}{'use'},
|
||||
|
|
Loading…
Reference in a new issue