@@ -14,6 +14,25 @@ sub new {
1414 }, $package );
1515}
1616
17+ sub new_for_tld {
18+ my ($package , $tld ) = @_ ;
19+
20+ foreach my $service (Net::RDAP::Registry-> load_registry(Net::RDAP::Registry::DNS_URL)-> services) {
21+ foreach my $zone ($service -> registries) {
22+ if (lc ($zone ) eq lc ($tld )) {
23+ return $package -> new(Net::RDAP::Registry-> get_best_url($service -> urls));
24+ }
25+ }
26+ }
27+
28+ return undef ;
29+ }
30+
31+ #
32+ # generate a URL given the params and fetch it. $type and $segments are used as
33+ # path segments ($segments must be an arrayref, and may be empty). %args is used
34+ # to construct query parameters.
35+ #
1736sub fetch {
1837 my ($self , $type , $segments , %params ) = @_ ;
1938
@@ -22,7 +41,7 @@ sub fetch {
2241 $uri -> path_segments(grep { defined && length > 0 } (
2342 $uri -> path_segments,
2443 $type ,
25- ' ARRAY ' eq ref ( $segments ) ? @{$segments } : $segments
44+ @{$segments },
2645 ));
2746
2847 $uri -> query_form(%params );
@@ -36,10 +55,10 @@ sub fetch {
3655sub search {
3756 my ($self , $type , %params ) = @_ ;
3857
39- if (exists ( $params { entity }) && ' HASH' eq ref ($params {entity })) {
58+ if (' HASH' eq ref ($params {entity })) {
4059 return $self -> reverse_search($type , %{$params {entity }});
4160
42- } elsif (' ips' eq $type && ($params { up } || $params {down } || $params { top } || $params { bottom } )) {
61+ } elsif (' ips' eq $type && (any { exists ( $params {$_ }) } qw( up down top bottom) )) {
4362 return $self -> rir_reverse_search($type , %params );
4463
4564 } else {
@@ -48,6 +67,12 @@ sub search {
4867 }
4968}
5069
70+ sub reverse_search {
71+ my ($self , $type , %params ) = @_ ;
72+
73+ return $self -> fetch($type , [qw( reverse_search entity) ], %params );
74+ }
75+
5176sub rir_reverse_search {
5277 my ($self , $type , %params ) = @_ ;
5378
@@ -65,27 +90,21 @@ sub rir_reverse_search {
6590 return undef ;
6691}
6792
68- sub reverse_search {
69- my ($self , $type , %params ) = @_ ;
70-
71- return $self -> fetch($type , [qw( reverse_search entity) ], %params );
72- }
73-
74- sub base { $_ [0]-> {' base' } }
75- sub client { $_ [0]-> {' client' } }
93+ sub base { shift -> {' base' } }
94+ sub client { shift -> {' client' } }
7695
77- sub help { $_ [0] -> fetch(' help' ) }
78- sub domain { $_ [0] -> fetch(' domain' , $_ [1] -> name ) }
79- sub ip { $_ [0] -> fetch(' ip' , $_ [1] -> prefix ) }
80- sub autnum { $_ [0] -> fetch(' autnum' , $_ [1] -> toasplain ) }
81- sub entity { $_ [0] -> fetch(' entity' , $_ [1] -> handle ) }
82- sub nameserver { $_ [0] -> fetch(' nameserver' , $_ [1] -> name ) }
96+ sub help { shift -> fetch(' help' , [] ) }
97+ sub domain { shift -> fetch(' domain' , [ pop -> name ] ) }
98+ sub ip { shift -> fetch(' ip' , [ pop -> prefix ] ) }
99+ sub autnum { shift -> fetch(' autnum' , [ pop -> toasplain ] ) }
100+ sub entity { shift -> fetch(' entity' , [ pop -> handle ] ) }
101+ sub nameserver { shift -> fetch(' nameserver' , [ pop -> name ] ) }
83102
84- sub domains { shift -> search(' domains' , @_ ) }
85- sub nameservers { shift -> search(' nameservers' , @_ ) }
86- sub entities { shift -> search(' entities' , @_ ) }
87- sub ips { shift -> search(' ips' , @_ ) }
88- sub autnums { shift -> search(' autnums' , @_ ) }
103+ sub domains { shift -> search(' domains' , @_ ) }
104+ sub nameservers { shift -> search(' nameservers' , @_ ) }
105+ sub entities { shift -> search(' entities' , @_ ) }
106+ sub ips { shift -> search(' ips' , @_ ) }
107+ sub autnums { shift -> search(' autnums' , @_ ) }
89108
90109sub implements {
91110 my ($self , $token ) = @_ ;
@@ -160,6 +179,13 @@ You can also provide a second argument which should be an existing
160179L<Net::RDAP> instance. This is used when fetching resources from the
161180server.
162181
182+ =head3 TLD Service Constructor
183+
184+ my $svc = Net::RDAP::Service->new_for_tld($tld);
185+
186+ This method searches the IANA registry for an entry for the TLD in C<$tld > and
187+ returns the corresponding L<Net::RDAP::Service> object.
188+
163189=head2 Lookup Methods
164190
165191You can do direct lookups of objects using the following methods:
0 commit comments