blib/lib/Net/Lookup/DotTel.pm

filter: Statementstmt 40.8% 47 / 115 Branchbran 12.5% 6 / 48 Conditioncond 1.6% 1 / 62 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 25.9% 70 / 270 CC 55 SCAR 53.0
CC
55
Cov
24%
get_services
398.9
get_postal_address
201.8
get_keywords
49.4
CRAP 201.3
↑ Summary
1 =head1 NAME
2  
3 Net::Lookup::DotTel - Look up information related to a .tel domain name (or
4 possible another domain name having .tel-style TXT and NAPTR records).
5  
6 =head1 DESCRIPTION
7  
8 This module offers an easy way to access the contact information that is
9 stored in DNS through NAPTR and TXT records under the .tel TLD.
10  
11 =head1 SYNOPSIS
12  
13 use Net::Lookup::DotTel;
14 my $lookup = Net::Lookup::DotTel->new;
15  
16 if ( $lookup->lookup ( 'smallco.tel' )) {
17  
18 my $service = $lookup->get_services ( 'email' );
19  
20 if ( $service->{uri} =~ /^mailto:(.+)/ ) {
21 my $email = $1;
22 print "SmallCo's email address is $email\n";
23 }
24  
25 }
26  
27 =head1 METHODS
28  
29 =cut
30  
31 package Net::Lookup::DotTel;
32  
33 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 3 our $VERSION = '0.04';
37  
38 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 =head2 new
42  
43 $lookup = Net::Lookup::DotTel->new;
44 $lookup = Net::Lookup::DotTel->new ( resolver_config => $resolver_settings );
45  
46 Constructor. The following optional named parameters can be specified:
47  
48 =over
49  
50 =item * resolver_config
51  
52 A reference to an array containing information be passed to
53 Net::DNS::Resolver->new. E.g., to specify your own resolving nameservers,
54 you can do:
55  
56 $lookup = Net::Lookup::DotTel->new (
57 resolver_config => [
58 nameservers => [ '192.168.1.1', '192.168.2.1' ]
59 ]
60 );
61  
62 =back
63  
64 =cut
65  
66 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
67  
68 3 my $class = shift;
69 3 my %param = @_;
70  
71 3 my $self = {};
72 3 ▶ $self->{resolver} = Net::DNS::Resolver->new ( @{$param{resolver_config} || []} );
Condition50%1/2
$param{'resolver_config'} || []
l!l
03
MC/DC0%0/1
$param{'resolver_config'} || []
$param{'resolver_config'}
Truth table50%1/2
A
A= $param{'resolver_config'}
Aresult
11
00
73  
74 3 bless $self, $class;
75  
76 }
77  
78 =head2 lookup
79  
80 $lookup->lookup ( 'smallco.tel' );
81  
82 Lookup the specified domain name. Returns 1 if the domain name exists or 0
83 otherwise. Note that the fact that a domain exists does not mean that it has
84 any meaningful TXT or NAPTR records associated with it.
85  
86 If the lookup was succesful, you can use the other methods to extract
87 information from this domain.
88  
89 =cut
90  
91 2 ▶sub lookup {
Subroutine lookup: called CC=3 SCAR=12.3
Pod documented
92  
93 2 my $self = shift;
94 2 my ( $domain ) = @_;
95  
96 2 ▶ croak "No domain specified" unless ( $domain );
Branch: 1 branch
BranchTrueFalseTotal
unless $domain 0 2 2
97  
98 2 ▶ if ( my $response = $self->{resolver}->query ( $domain, 'ANY' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $response = $self->{"resolver"}->query($domain, "ANY")) 0 2 2
99 0 $self->{current_domain} = ( $response->question )[0]->qname;
100 0 return 1;
101 }
102  
103 2 return 0;
104  
105 }
106  
107 =head2 get_keywords
108  
109 @keywords = $lookup->get_keywords;
110 @keywords = $lookup->get_keywords ( 'pa' );
111  
112 Return the keywords that are associated with the domain. Keywords contain
113 additional information related to the domain name that cannot be specified
114 using NAPTR records. Keywords are stored in TXT records using a
115 .tel-specific format.
116  
117 Keywords are ordered into groups. The returned list will contain a reference
118 to a list (which can be interpolated to a hash) containing the keywords of a
119 single group. If you specify one or more parameters, only keyword groups
120 containing a value for the specified keywords will be returned.
121  
122 E.g., to return only keyword groups that specify a Postal Address (pa) that
123 contains at least a ZIP code (pc) and a city (tc), you specify:
124  
125 @keywords = $lookup->get_keywords ( 'pa', 'pc', 'tc' );
126  
127 If only a single keyword group matches, @keywords would contain a single
128 array reference looking something like:
129  
130 [ 'pa', '', 'a1', 'Somestreet 1', 'pc', '12094', 'tc', 'Some city', 'c', 'US' ]
131  
132 Which can be interpolated into a hash so you get:
133  
134 {
135 'pa' => '',
136 'a1' => 'Somestreet 1',
137 'pc' => '12094',
138 'tc' => 'Some city',
139 'c' => 'US'
140 }
141  
142 When interpolating, the order of the elements (which was originally
143 preserved) will be lost. This may be relevant as .tel users can explicitly
144 specify the order of the fields for presentation purposes.
145  
146 For a description of available keywords and their shortened forms, please
147 refer to the Telnic website, specifically Appendix B of the Developer's
148 Manual.
149  
150 For retrieving a list of (business) postal addresses associated with a
151 domain name, you can also use the get_postal_address method. That methods
152 translates the keywords to nicer ;) names.
153  
154 =cut
155  
156 3 ▶sub get_keywords {
Subroutine get_keywords: called CC=9 SCAR=39.0
Pod documented
157  
158 3 my $self = shift;
159 3 my @must_contain = @_;
160  
161 3 ▶ unless ( $self->{current_domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"current_domain"}) 3 0 3
162 3 carp "Called get_text without succesful lookup";
163 3 return ();
164 }
165  
166 0 my @results = ();
167  
168 0 ▶ if ( my $response = $self->{resolver}->query ( $self->{current_domain}, 'TXT' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $response = $self->{"resolver"}->query($self->{"current_domain"}, "TXT")) 0 0 0
169  
170 0 RECORD: foreach my $t ( $response->answer ) {
171  
172 0 ▶ if ( $t->type eq 'TXT' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type eq "TXT") 0 0 0
173  
174 0 my @parts = $t->char_str_list;
175 0 ▶ if ( $parts[0] eq '.tkw' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parts[0] eq ".tkw") 0 0 0
176  
177 # Find out whether we have all the required keywords in this
178 # group.
179  
180 0 KEYWORD: foreach my $kw ( @must_contain ) {
181 0 ▶ for ( my $i = 2; $i <= $#parts; $i+= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#parts) 0 0 0
182 0 ▶ next KEYWORD if ( $parts[$i] eq $kw );
Branch: 1 branch
BranchTrueFalseTotal
if $parts[$i] eq $kw 0 0 0
183 }
184 0 next RECORD;
185 }
186  
187 0 push @results, [ @parts[2..$#parts] ];
188  
189 }
190 }
191 }
192 }
193  
194 0 return @results;
195  
196 }
197  
198 =head2 get_postal_address
199  
200 @postal_addresses = $lookup->get_postal_address;
201  
202 Return all postal addresses which are associated with the current domain. A
203 postal address is a keyword group containing at least one of the following
204 groups of keywords:
205  
206 =over
207  
208 =item * pa, a1, tc
209  
210 =item * bpa, a1, tc
211  
212 =back
213  
214 The returned list contains all addresses that could be found, ordered in the
215 following way:
216  
217 =over
218  
219 =item * addresses with more keyword (more complete addresses) before addresses with less keywords,
220  
221 =item * postal addresses (pa) before business postal addresses (bpa),
222  
223 =item * ordered by label alphabetically, listing addresses without a label before any other addresses,
224  
225 =item * ordered by keyword contents alphabetically.
226  
227 =back
228  
229 Note that the last of this order sequence does not make any particular
230 sense; it is used only to guarantee that the order in which the addresses
231 are returned stays the same if the data does not change.
232  
233 Every address in the list consists of a reference to a hash with the following keys:
234  
235 =over
236  
237 =item * order
238  
239 A reference to a list containing the field names in the order in which they
240 appeared in the original keyword group. The field names we use here are the
241 longer field names present in the rest of the hash.
242  
243 =item * label
244  
245 The label associated with this address.
246  
247 =item * type
248  
249 The type of address, either 'pa' or 'bpa'.
250  
251 =item * address1
252  
253 =item * address2
254  
255 =item * address3
256  
257 The street address, consisting of a maximum of three lines.
258  
259 =item * postcode
260  
261 =item * city
262  
263 =item * state
264  
265 =item * country
266  
267 These should speak for itself. Note that neither of these fields are in any
268 particular order; specifically, do not expect the country field to contain
269 an ISO country code.
270  
271 =back
272  
273 E.g., when a single address is returned with the current domain, the list
274 may contain the following result for a Dutch address:
275  
276 {
277 order => ['address1', 'postcode', 'city', 'country'],
278 address1 => 'Some street 1',
279 postcode => '1234 AB',
280 city => 'Amsterdam',
281 country => 'NL'
282 }
283  
284 In scalar context, returns only the first address (this is what you want to
285 do for a 'quick and dirty' .tel based address lookup).
286  
287 =cut
288  
289 1 ▶sub get_postal_address {
Subroutine get_postal_address: called CC=17 SCAR=53.1
Pod documented
290  
291 1 my $self = shift;
292  
293 1 my @keywords = $self->get_keywords ( 'pa', 'a1', 'tc' );
294 1 push @keywords, $self->get_keywords ( 'bpa', 'a1', 'tc' );
295  
296 # Sort the keywords
297 @keywords = sort {
298 0 ▶ ( @{$b} <=> @{$a} ) || # More descriptive before less descriptive.
Condition0%0/10
$Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1
!ll
00
$Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa"
!ll&&!rl&&r
000
$Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1
!ll
00
$Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa"
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1
$Net::Lookup::DotTel::a->[2] eq "pa" $Net::Lookup::DotTel::b->[2] eq "bpa"
MC/DC0%0/2
$Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1
$Net::Lookup::DotTel::b->[2] eq "pa" $Net::Lookup::DotTel::a->[2] eq "bpa"
Truth table0%0/3
A and B
A= $Net::Lookup::DotTel::a->[2] eq "pa"B= $Net::Lookup::DotTel::b->[2] eq "bpa"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $Net::Lookup::DotTel::b->[2] eq "pa"B= $Net::Lookup::DotTel::a->[2] eq "bpa"
ABresult
0X0
100
111
299 (( $a->[2] eq 'pa' ) && ( $b->[2] eq 'bpa' ) && -1 ) || # PA before BPA
300 (( $b->[2] eq 'pa' ) && ( $a->[2] eq 'bpa' ) && 1 ) || # BPA after PA
301 ( $a->[3] cmp $b->[3] ) || # Alphabetically by label
302 0 ▶ ( join ( ' ', @{$a} ) cmp join ( ' ', @{$b} )) # Alphabetically by keywords.
Condition0%0/12
@{$b;} <=> @{$a;} || $Net::Lookup::DotTel::a->[2] eq 'pa' && $Net::Lookup::DotTel::b->[2] eq 'bpa' && -1 || $Net::Lookup::DotTel::b->[2] eq 'pa' && $Net::Lookup::DotTel::a->[2] eq 'bpa' && 1 || $Net::Lookup::DotTel::a->[3] cmp $Net::Lookup::DotTel::b->[3] || join(' ', @{$a;}) cmp join(' ', @{$b;})
l!l&&r!l&&!r
000
@{$b;} <=> @{$a;} or $Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1 or $Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1 or $Net::Lookup::DotTel::a->[3] cmp $Net::Lookup::DotTel::b->[3]
l!l&&r!l&&!r
000
@{$b;} <=> @{$a;} or $Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1 or $Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1
l!l&&r!l&&!r
000
@{$b;} <=> @{$a;} or $Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1
l!l&&r!l&&!r
000
MC/DC0%0/5
@{$b;} <=> @{$a;} || $Net::Lookup::DotTel::a->[2] eq 'pa' && $Net::Lookup::DotTel::b->[2] eq 'bpa' && -1 || $Net::Lookup::DotTel::b->[2] eq 'pa' && $Net::Lookup::DotTel::a->[2] eq 'bpa' && 1 || $Net::Lookup::DotTel::a->[3] cmp $Net::Lookup::DotTel::b->[3] || join(' ', @{$a;}) cmp join(' ', @{$b;})
@{$b;} <=> @{$a;} $Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1 $Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1 $Net::Lookup::DotTel::a->[3] cmp $Net::Lookup::DotTel::b->[3] join(' ', @{$a;}) cmp join(' ', @{$b;})
Truth table0%0/6
A or B or C or D || E
A= @{$b;} <=> @{$a;}B= $Net::Lookup::DotTel::a->[2] eq "pa" and $Net::Lookup::DotTel::b->[2] eq "bpa" and -1C= $Net::Lookup::DotTel::b->[2] eq "pa" and $Net::Lookup::DotTel::a->[2] eq "bpa" and 1D= $Net::Lookup::DotTel::a->[3] cmp $Net::Lookup::DotTel::b->[3]E= join(' ', @{$a;}) cmp join(' ', @{$b;})
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
303 } @keywords;
304  
305 1 my @results;
306 1 foreach my $kw ( @keywords ) {
307  
308 0 my %address;
309 my @order;
310  
311 0 ▶ while ( my $n = shift @{$kw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = shift @{$kw;}) 0 0 0
312  
313 0 my $v = shift @{$kw};
314  
315 0 foreach (
316 { name => 'a1', nice => 'address1' },
317 { name => 'a2', nice => 'address2' },
318 { name => 'a3', nice => 'address3' },
319 { name => 'pc', nice => 'postcode' },
320 { name => 'tc', nice => 'city' },
321 { name => 'sp', nice => 'state' },
322 { name => 'c', nice => 'country' }
323 ) {
324  
325 0 ▶ if ( $n eq $_->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq $_->{"name"}) 0 0 0
326 0 $address{$_->{nice}} = $v;
327 0 push @order, $_->{nice};
328 }
329 }
330  
331 0 ▶ unless ( $address{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($address{"type"}) 0 0 0
332 0 ▶ if ( $n eq 'pa' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n eq 'pa') { } 0 0 0
elsif ($n eq 'bpa') { } 0 0 0
333 0 $address{type} = 'pa';
334 0 $address{label} = $v;
335 } elsif ( $n eq 'bpa' ) {
336 0 $address{type} = 'bpa';
337 0 $address{label} = $v;
338 }
339 }
340 }
341  
342 0 $address{order} = \@order;
343  
344 0 push @results, \%address;
345  
346 }
347  
348 1 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 1 0 1
349 1 return @results;
350 }
351  
352 0 return $results[0];
353  
354 }
355  
356 =head2 get_services
357  
358 @services = $lookup->get_services;
359 @services = $lookup->get_services ( 'email' );
360  
361 Return the services that are associated with the current domain. If an ENUM
362 service is specified, returns only services that match this service type.
363 The services are taken from the NAPTR records associated with the domain and
364 are ordered by the preference and order fields. The service can be specified
365 as specific as you want:
366  
367 =over
368  
369 =item * 'email' will return all email services,
370  
371 =item * 'email:mailto' will return only email services of subtype 'mailto',
372  
373 =item * 'x-lbl:Label' will return only services with label 'Label' (case insensitive).
374  
375 =back
376  
377 Every service in the list consists of a hash reference with the following keys:
378  
379 =over
380  
381 =item * services
382  
383 A reference to a list containing the ENUM services of this record.
384  
385 =item * uri
386  
387 The translated URI for the service, e.g. the email address as
388 'mailto:somebody@domain.invalid' or a phone number as 'tel:+12356890'.
389  
390 =item * label
391  
392 Contains the .tel label as specified by the non-standard ENUM service
393 'x-lbl'. This is a .tel-specific extension. If the x-lbl service is not
394 present then neither is this key.
395  
396 =item * order
397  
398 =item * preference
399  
400 =item * regexp
401  
402 =item * flags
403  
404 =item * replacement
405  
406 These keys contain the original values of the NAPTR record.
407  
408 =back
409  
410 For most uses, only 'label' and 'uri' will actually be interesting.
411  
412 If the method is called in a scalar context, only the first service found is
413 returned. For this service to always be the same we order the NAPTR records
414 not just on preference and order, but also alphabetically by services,
415 regexp, flags and replacement fields.
416  
417 The .tel registry supports a number of non-standard ENUM services, which are
418 described in the whitepaper 'NAPTR Records in .tel'.
419  
420 =cut
421  
422 1 ▶sub get_services {
Subroutine get_services: called CC=22 SCAR=59.9
Pod documented
423  
424 1 my $self = shift;
425 1 my ( $service ) = @_;
426  
427 1 ▶ unless ( $self->{current_domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"current_domain"}) 1 0 1
428 1 carp "Called get_text without succesful lookup";
429 1 return ();
430 }
431  
432 0 my @results;
433  
434 0 ▶ if ( my $response = $self->{resolver}->query ( $self->{current_domain}, 'NAPTR' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $response = $self->{"resolver"}->query($self->{"current_domain"}, "NAPTR")) 0 0 0
435  
436 0 foreach my $n ( $response->answer ) {
437  
438 0 ▶ if ( $n->type eq 'NAPTR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->type eq "NAPTR") 0 0 0
439  
440 0 my @services;
441 0 my $value = '';
442  
443 0 ▶ if ( $n->flags eq 'u' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->flags eq "u") 0 0 0
444  
445 # Terminal NAPTR
446  
447 0 @services = split ( /\+/, $n->service );
448 0 ▶ if ( (!$service) || (grep m/^$service(:.+)?$/, @services )) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $service or grep /^$service(:.+)?$/, @services) 0 0 0
Condition0%0/3
not $service or grep /^$service(:.+)?$/, @services
l!l&&r!l&&!r
000
MC/DC0%0/2
not $service or grep /^$service(:.+)?$/, @services
not $service grep /^$service(:.+)?$/, @services
Truth table0%0/3
not(A) or B
A= not $serviceB= grep /^$service(:.+)?$/, @services
ABresult
1X1
011
000
449  
450 # Service matches query. Determine the service URI.
451  
452 0 $value = $n->name;
453 0 my $regexp = $n->regexp;
454  
455 # Note that the following is not entirely correct; it does not
456 # allow for escaping the delim-char that is used.
457  
458 0 my ( $match, $replacement, $flags ) = split ( substr ( $regexp, 0, 1), substr ( $regexp, 1 ));
459 0 $value =~ s/$match/$replacement/e;
460 0 ▶ $value ||= $regexp; # For 'fixing' thoroughly broken regexps
Condition0%0/3
$value ||= $regexp
l!l&&r!l&&!r
000
MC/DC0%0/2
$value ||= $regexp
$value $regexp
Truth table0%0/3
A ||= B
A= $valueB= $regexp
ABresult
1X1
011
000
461 }
462  
463 } # end Terminal NAPTR
464  
465 0 ▶ push @results, {
Condition0%0/14
$value || ''
l!l
00
(grep /^x-lbl:(.+)$/, @services)[0] || ''
l!l
00
$n->order || 0
l!l
00
$n->preference || 0
l!l
00
$n->flags || ''
l!l
00
$n->regexp || ''
l!l
00
$n->replacement || ''
l!l
00
MC/DC0%0/1
$value || ''
$value
MC/DC0%0/1
(grep /^x-lbl:(.+)$/, @services)[0] || ''
(grep /^x-lbl:(.+)$/, @services)[0]
MC/DC0%0/1
$n->order || 0
$n->order
MC/DC0%0/1
$n->preference || 0
$n->preference
MC/DC0%0/1
$n->flags || ''
$n->flags
MC/DC0%0/1
$n->regexp || ''
$n->regexp
MC/DC0%0/1
$n->replacement || ''
$n->replacement
Truth table0%0/2
A
A= $value
Aresult
11
00
Truth table0%0/2
A
A= (grep /^x-lbl:(.+)$/, @services)[0]
Aresult
11
00
Truth table0%0/2
A
A= $n->order
Aresult
11
00
Truth table0%0/2
A
A= $n->preference
Aresult
11
00
Truth table0%0/2
A
A= $n->flags
Aresult
11
00
Truth table0%0/2
A
A= $n->regexp
Aresult
11
00
Truth table0%0/2
A
A= $n->replacement
Aresult
11
00
466 services => \@services,
467 uri => $value || '',
468 label => ( grep m/^x-lbl:(.+)$/, @services )[0] || '',
469 order => $n->order || 0,
470 preference => $n->preference || 0,
471 flags => $n->flags || '',
472 regexp => $n->regexp || '',
473 replacement => $n->replacement || ''
474 };
475 }
476 }
477 }
478  
479 @results = sort {
480 0 ( $a->{preference} <=> $b->{preference} ) || # By preference
481 ( $a->{order} <=> $b->{order} ) || # By order
482 0 ( join ( '+', @{$a->{services}} ) cmp join ( '+', @{$b->{services}} )) || # By service field
483 ( $a->{regexp} cmp $b->{regexp} ) || # By regexp
484 ( $a->{flags} cmp $b->{flags} ) || # By flags
485 ( $a->{replacement} cmp $b->{replacement} ) # By replacement
486 0 ▶ } @results;
Condition0%0/15
$Net::Lookup::DotTel::a->{'preference'} <=> $Net::Lookup::DotTel::b->{'preference'} || $Net::Lookup::DotTel::a->{'order'} <=> $Net::Lookup::DotTel::b->{'order'} || join('+', @{$Net::Lookup::DotTel::a->{'services'};}) cmp join('+', @{$Net::Lookup::DotTel::b->{'services'};}) || $Net::Lookup::DotTel::a->{'regexp'} cmp $Net::Lookup::DotTel::b->{'regexp'} || $Net::Lookup::DotTel::a->{'flags'} cmp $Net::Lookup::DotTel::b->{'flags'} || $Net::Lookup::DotTel::a->{'replacement'} cmp $Net::Lookup::DotTel::b->{'replacement'}
l!l&&r!l&&!r
000
$Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"} or $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"} or join("+", @{$Net::Lookup::DotTel::a->{"services"};}) cmp join("+", @{$Net::Lookup::DotTel::b->{"services"};}) or $Net::Lookup::DotTel::a->{"regexp"} cmp $Net::Lookup::DotTel::b->{"regexp"} or $Net::Lookup::DotTel::a->{"flags"} cmp $Net::Lookup::DotTel::b->{"flags"}
l!l&&r!l&&!r
000
$Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"} or $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"} or join("+", @{$Net::Lookup::DotTel::a->{"services"};}) cmp join("+", @{$Net::Lookup::DotTel::b->{"services"};}) or $Net::Lookup::DotTel::a->{"regexp"} cmp $Net::Lookup::DotTel::b->{"regexp"}
l!l&&r!l&&!r
000
$Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"} or $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"} or join("+", @{$Net::Lookup::DotTel::a->{"services"};}) cmp join("+", @{$Net::Lookup::DotTel::b->{"services"};})
l!l&&r!l&&!r
000
$Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"} or $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$Net::Lookup::DotTel::a->{'preference'} <=> $Net::Lookup::DotTel::b->{'preference'} || $Net::Lookup::DotTel::a->{'order'} <=> $Net::Lookup::DotTel::b->{'order'} || join('+', @{$Net::Lookup::DotTel::a->{'services'};}) cmp join('+', @{$Net::Lookup::DotTel::b->{'services'};}) || $Net::Lookup::DotTel::a->{'regexp'} cmp $Net::Lookup::DotTel::b->{'regexp'} || $Net::Lookup::DotTel::a->{'flags'} cmp $Net::Lookup::DotTel::b->{'flags'} || $Net::Lookup::DotTel::a->{'replacement'} cmp $Net::Lookup::DotTel::b->{'replacement'}
$Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"} $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"} join("+", @{$Net::Lookup::DotTel::a->{"services"};}) cmp join("+", @{$Net::Lookup::DotTel::b->{"services"};}) $Net::Lookup::DotTel::a->{"regexp"} cmp $Net::Lookup::DotTel::b->{"regexp"} $Net::Lookup::DotTel::a->{"flags"} cmp $Net::Lookup::DotTel::b->{"flags"} $Net::Lookup::DotTel::a->{'replacement'} cmp $Net::Lookup::DotTel::b->{'replacement'}
Truth table0%0/7
A or B or C or D or E || F
A= $Net::Lookup::DotTel::a->{"preference"} <=> $Net::Lookup::DotTel::b->{"preference"}B= $Net::Lookup::DotTel::a->{"order"} <=> $Net::Lookup::DotTel::b->{"order"}C= join("+", @{$Net::Lookup::DotTel::a->{"services"};}) cmp join("+", @{$Net::Lookup::DotTel::b->{"services"};})D= $Net::Lookup::DotTel::a->{"regexp"} cmp $Net::Lookup::DotTel::b->{"regexp"}E= $Net::Lookup::DotTel::a->{"flags"} cmp $Net::Lookup::DotTel::b->{"flags"}F= $Net::Lookup::DotTel::a->{'replacement'} cmp $Net::Lookup::DotTel::b->{'replacement'}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
487  
488 0 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 0 0
489 0 return @results;
490 }
491  
492 0 return $results[0];
493  
494 }
495  
496 =head2 get_text
497  
498 @text = $lookup->get_text;
499  
500 Return the TXT records that are associated with the current domain that are
501 not .tel keywords or system messages. This will retrieve any TXT record
502 associated with the domain which does not start with ".tkw" or ".tsm". Note
503 that the records are not returned in any particular order.
504  
505 If the query was not succesful, an empty list is returned.
506  
507 Note that all texts in a single TXT field are simply concatenated; this is
508 due to the fact that plain .tel TXT fields usually contain a descriptive
509 text only.
510  
511 =cut
512  
513 1 ▶sub get_text {
Subroutine get_text: called CC=7 SCAR=34.2
Pod documented
514  
515 1 my $self = shift;
516  
517 1 ▶ unless ( $self->{current_domain} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"current_domain"}) 1 0 1
518 1 carp "Called get_text without succesful lookup";
519 1 return ();
520 }
521  
522 0 my @results;
523  
524 0 ▶ if ( my $response = $self->{resolver}->query ( $self->{current_domain}, 'TXT' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $response = $self->{"resolver"}->query($self->{"current_domain"}, "TXT")) 0 0 0
525  
526 0 foreach my $t ( $response->answer ) {
527  
528 0 ▶ if ( $t->type eq 'TXT' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type eq "TXT") 0 0 0
529  
530 0 my @parts = $t->char_str_list;
531 0 ▶ unless (( $parts[0] eq '.tkw' ) || ( $parts[0] eq '.tsm' )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parts[0] eq ".tkw" or $parts[0] eq ".tsm") 0 0 0
Condition0%0/3
$parts[0] eq ".tkw" or $parts[0] eq ".tsm"
l!l&&r!l&&!r
000
MC/DC0%0/2
$parts[0] eq ".tkw" or $parts[0] eq ".tsm"
$parts[0] eq ".tkw" $parts[0] eq ".tsm"
Truth table0%0/3
A or B
A= $parts[0] eq ".tkw"B= $parts[0] eq ".tsm"
ABresult
1X1
011
000
532  
533 0 push @results, join ( ' ', @parts );
534  
535 }
536 }
537 }
538 }
539  
540 0 return @results;
541  
542 }
543  
544 =head1 AUTHOR
545  
546 Sebastiaan Hoogeveen, <pause-zebaz@nederhost.nl>
547  
548 =head1 SEE ALSO
549  
550 http://dev.telnic.org/pages/howtos.html for a link to the Developer's Manual
551 which, among others, contains a description of the .tel keywords.
552  
553 http://dev.telnic.org/pages/record_types.html for a link to the whitepaper
554 'NAPTR Records in .tel'.
555  
556 http://dev.telnic.org/pages/howtos.html for a description of keywords.
557  
558 If you are looking for a way to manipulate the DNS records in the Telnic
559 system take a look at WebService::Telnic.
560  
561 =head1 BUGS
562  
563 Since this is a very early release of what could become a pretty complex
564 module, there are probably several bugs in this code. Use at your own risk.
565 Bugs can be reported by email to the author.
566  
567 =head1 COPYRIGHT
568  
569 Copyright 2009 Sebastiaan Hoogeveen. All rights reserved. This program is
570 free software; you can redistribute it and/or modify it under the same terms
571 as Perl itself.
572  
573 See http://www.perl.com/perl/misc/Artistic.html
574  
575 =cut
576  
577 3 1;
↑ Summary