• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装


Commit MetaInfo

Revisionbd4448817d5eef5328d76c5ec06fe60ac5319f99 (tree)
Zeit2021-08-11 17:41:17
Autordyknon <dyknon@user...>
Commiterdyknon

Log Message

refactor

Ändern Zusammenfassung

Diff

--- a/Net/DHCP6/Option/DUID.pm
+++ b/Net/DHCP6/AbstractOption/DUID.pm
@@ -1,4 +1,4 @@
1-package Net::DHCP6::Option::DUID;
1+package Net::DHCP6::AbstractOption::DUID;
22 # base class for DUID options
33 # RFC8415 11.
44 # RFC8415 21.2.
--- a/Net/DHCP6/Option/FixedLength.pm
+++ b/Net/DHCP6/AbstractOption/FixedLength.pm
@@ -1,4 +1,4 @@
1-package Net::DHCP6::Option::FixedLength;
1+package Net::DHCP6::AbstractOption::FixedLength;
22 # base class for fixed length options
33
44 use strict;
--- a/Net/DHCP6/Message.pm
+++ b/Net/DHCP6/Message.pm
@@ -4,7 +4,11 @@ package Net::DHCP6::Message;
44 use strict;
55 use warnings;
66
7+use Net::DHCP6::Option;
8+use Net::DHCP6::OptionList;
9+
710 our $VERSION = "0.0.1";
11+our @ISA = qw/Net::DHCP6::OptionList/;
812
913 # TODO: should be crypto-safe RNG?
1014 our $RNG = sub{ int rand shift };
@@ -38,35 +42,9 @@ sub xid {
3842 $self->{xid};
3943 }
4044
41-sub option {
42- my $self = shift;
43- my $key = shift;
44- my @hit = $self->options($key);
45- if(@hit == 0){
46- undef;
47- }elsif(@hit == 1){
48- pop @hit;
49- }else{
50- die "multiple options";
51- }
52-}
53-
54-sub options {
45+sub all_options {
5546 my $self = shift;
56- return @{$self->{options}} if(@_ == 0);
57- my %index;
58- my @opts = $self->options;
59- return () unless(@opts);
60- for my $key(@_){
61- if($key =~ /^[0-9]+$/){
62- %index = (%index,
63- map{$_, 1}grep{$opts[$_]->code == $key}(0 .. $#opts));
64- }else{
65- %index = (%index,
66- map{$_, 1}grep{$opts[$_]->isa($key)}(0 .. $#opts));
67- }
68- }
69- @opts[keys %index];
47+ @{$self->{options}};
7048 }
7149
7250 sub serialize {
--- a/Net/DHCP6/Option/ClientId.pm
+++ b/Net/DHCP6/Option/ClientId.pm
@@ -3,11 +3,11 @@ package Net::DHCP6::Option::ClientId;
33
44 use strict;
55 use warnings;
6-use Net::DHCP6::Option::DUID;
6+use Net::DHCP6::AbstractOption::DUID;
77 use Net::DHCP6::Parameters qw/DHCP6_OPT_CLIENTID/;
88
99 our $VERSION = "0.0.1";
10-our @ISA = qw/Net::DHCP6::Option::DUID/;
10+our @ISA = qw/Net::DHCP6::AbstractOption::DUID/;
1111
1212 use constant code => DHCP6_OPT_CLIENTID;
1313 use constant name => "ClientId";
--- a/Net/DHCP6/Option/ElapsedTime.pm
+++ b/Net/DHCP6/Option/ElapsedTime.pm
@@ -3,11 +3,11 @@ package Net::DHCP6::Option::ElapsedTime;
33
44 use strict;
55 use warnings;
6-use Net::DHCP6::Option::FixedLength;
6+use Net::DHCP6::AbstractOption::FixedLength;
77 use Net::DHCP6::Parameters qw/DHCP6_OPT_ELAPSED_TIME/;
88
99 our $VERSION = "0.0.1";
10-our @ISA = qw/Net::DHCP6::Option::FixedLength/;
10+our @ISA = qw/Net::DHCP6::AbstractOption::FixedLength/;
1111
1212 use constant code => DHCP6_OPT_ELAPSED_TIME;
1313 use constant name => "ElapsedTime";
--- a/Net/DHCP6/Option/ServerId.pm
+++ b/Net/DHCP6/Option/ServerId.pm
@@ -3,11 +3,11 @@ package Net::DHCP6::Option::ServerId;
33
44 use strict;
55 use warnings;
6-use Net::DHCP6::Option::DUID;
6+use Net::DHCP6::AbstractOption::DUID;
77 use Net::DHCP6::Parameters qw/DHCP6_OPT_SERVERID/;
88
99 our $VERSION = "0.0.1";
10-our @ISA = qw/Net::DHCP6::Option::DUID/;
10+our @ISA = qw/Net::DHCP6::AbstractOption::DUID/;
1111
1212 use constant code => DHCP6_OPT_SERVERID;
1313 use constant name => "ServerId";
--- /dev/null
+++ b/Net/DHCP6/OptionList.pm
@@ -0,0 +1,36 @@
1+package Net::DHCP6::OptionList;
2+
3+use strict;
4+use warnings;
5+
6+our $VERSION = "0.0.1";
7+
8+sub option {
9+ my $self = shift;
10+ my $key = shift;
11+ my @hit = $self->options($key);
12+ if(@hit == 0){
13+ undef;
14+ }elsif(@hit == 1){
15+ pop @hit;
16+ }else{
17+ die "multiple options";
18+ }
19+}
20+
21+sub options {
22+ my $self = shift;
23+ return $self->all_options if(@_ == 0);
24+ my %index;
25+ my @opts = $self->all_options;
26+ for my $key(@_){
27+ if($key =~ /^[0-9]+$/){
28+ %index = (%index,
29+ map{$_, 1}grep{$opts[$_]->code == $key}(0 .. $#opts));
30+ }else{
31+ %index = (%index,
32+ map{$_, 1}grep{$opts[$_]->isa($key)}(0 .. $#opts));
33+ }
34+ }
35+ @opts[keys %index];
36+}