File Coverage

blib/lib/Net/DNS/RR/URI.pm
Criterion Covered Total %
statement 46 46 100.0
branch 2 2 100.0
path n/a
condition 4 4 100.0
subroutine 12 12 100.0
pod 3 3 100.0
total 67 67 100.0


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