File Coverage

blib/lib/Net/DNS/RR/LP.pm
Criterion Covered Total %
statement 36 36 100.0
branch 2 2 100.0
path n/a
condition 2 2 100.0
subroutine 12 12 100.0
pod 4 4 100.0
total 56 56 100.0


line stmt bran path cond sub pod time code
1               package Net::DNS::RR::LP;
2                
3 1       1   9 use strict;
  1           2  
  1           44  
4 1       1   5 use warnings;
  1           3  
  1           103  
5               our $VERSION = (qw$Id: LP.pm 2003 2025-01-21 12:06:06Z willem $)[2];
6                
7 1       1   7 use base qw(Net::DNS::RR);
  1           2  
  1           129  
8                
9                
10               =head1 NAME
11                
12               Net::DNS::RR::LP - DNS LP resource record
13                
14               =cut
15                
16 1       1   7 use integer;
  1           2  
  1           8  
17                
18                
19               sub _decode_rdata { ## decode rdata from wire-format octet string
20 1       1   4 my ( $self, $data, $offset ) = @_;
21                
22 1           6 $self->{preference} = unpack( "\@$offset n", $$data );
23 1           5 $self->{target} = Net::DNS::DomainName->decode( $data, $offset + 2 );
24 1           4 return;
25               }
26                
27                
28               sub _encode_rdata { ## encode rdata as wire-format octet string
29 5       5   11 my $self = shift;
30                
31 5           7 my $target = $self->{target};
32 5           31 return pack 'n a*', $self->preference, $target->encode();
33               }
34                
35                
36               sub _format_rdata { ## format rdata portion of RR string.
37 2       2   3 my $self = shift;
38                
39 2           5 my $target = $self->{target};
40 2           5 return join ' ', $self->preference, $target->string;
41               }
42                
43                
44               sub _parse_rdata { ## populate RR from rdata in argument list
45 1       1   4 my ( $self, @argument ) = @_;
46                
47 1           2 for (qw(preference target)) { $self->$_( shift @argument ) }
  2           7  
48 1           4 return;
49               }
50                
51                
52               sub preference {
53 11       11 1 31 my ( $self, @value ) = @_;
54 11           23 for (@value) { $self->{preference} = 0 + $_ }
  2           7  
55 11     100     69 return $self->{preference} || 0;
56               }
57                
58                
59               sub target {
60 4       4 1 1329 my ( $self, @value ) = @_;
61 4           8 for (@value) { $self->{target} = Net::DNS::DomainName->new($_) }
  2           10  
62 4 100         43 return $self->{target} ? $self->{target}->name : undef;
63               }
64                
65                
66 2       2 1 2323 sub FQDN { return shift->{target}->fqdn; }
67 2       2 1 1339 sub fqdn { return shift->{target}->fqdn; }
68                
69                
70               my $function = sub { ## sort RRs in numerically ascending order.
71               return $Net::DNS::a->{'preference'} <=> $Net::DNS::b->{'preference'};
72               };
73                
74               __PACKAGE__->set_rrsort_func( 'preference', $function );
75                
76               __PACKAGE__->set_rrsort_func( 'default_sort', $function );
77                
78                
79               1;
80               __END__