DNS/RR/SRV.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 2 / 2 Conditioncond 88.8% 8 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 96.6% 86 / 89 CC 11 SCAR 7.7
CC
11
Cov
98%
priority
3.0
weight
3.0
port
3.0
CRAP 2.2
« DNS/RR/CERT.pm ↑ Summary DNS/RR/DSYNC.pm »
1 package Net::DNS::RR::SRV;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = (qw$Id: SRV.pm 2003 2025-01-21 12:06:06Z willem $)[2];
6  
7 2 ▶use base qw(Net::DNS::RR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 =head1 NAME
11  
12 Net::DNS::RR::SRV - DNS SRV resource record
13  
14 =cut
15  
16 2 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Net::DNS::DomainName;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 1 ▶sub _decode_rdata { ## decode rdata from wire-format octet string
Subroutine _decode_rdata: called CC=1 SCAR=0.0
22 1 my ( $self, $data, $offset, @opaque ) = @_;
23  
24 1 @{$self}{qw(priority weight port)} = unpack( "\@$offset n3", $$data );
25  
26 1 $self->{target} = Net::DNS::DomainName2535->decode( $data, $offset + 6, @opaque );
27 1 return;
28 }
29  
30  
31 61 ▶sub _encode_rdata { ## encode rdata as wire-format octet string
Subroutine _encode_rdata: called CC=1 SCAR=0.0
32 61 my ( $self, $offset, @opaque ) = @_;
33  
34 61 my $target = $self->{target};
35 61 my @nums = ( $self->priority, $self->weight, $self->port );
36 61 return pack 'n3 a*', @nums, $target->encode( $offset + 6, @opaque );
37 }
38  
39  
40 2 ▶sub _format_rdata { ## format rdata portion of RR string.
Subroutine _format_rdata: called CC=1 SCAR=0.0
41 2 my $self = shift;
42  
43 2 my $target = $self->{target};
44 2 my @rdata = ( $self->priority, $self->weight, $self->port, $target->string );
45 2 return @rdata;
46 }
47  
48  
49 9 ▶sub _parse_rdata { ## populate RR from rdata in argument list
Subroutine _parse_rdata: called CC=2 SCAR=6.9
50 9 my ( $self, @argument ) = @_;
51  
52 9 foreach my $attr (qw(priority weight port target)) {
53 36 $self->$attr( shift @argument );
54 }
55 9 return;
56 }
57  
58  
59 75 ▶sub priority {
Subroutine priority: called CC=3 SCAR=11.0
Pod documented
60 75 my ( $self, @value ) = @_;
61 75 for (@value) { $self->{priority} = 0 + $_ }
62 75 ▶ return $self->{priority} || 0;
Condition100%2/2
$self->{'priority'} || 0
l!l
678
MC/DC100%1/1
$self->{'priority'} || 0
$self->{'priority'}
Truth table100%2/2
A
A= $self->{'priority'}
Aresult
11
00
63 }
64  
65  
66 75 ▶sub weight {
Subroutine weight: called CC=3 SCAR=11.0
Pod documented
67 75 my ( $self, @value ) = @_;
68 75 for (@value) { $self->{weight} = 0 + $_ }
69 75 ▶ return $self->{weight} || 0;
Condition100%2/2
$self->{'weight'} || 0
l!l
4431
MC/DC100%1/1
$self->{'weight'} || 0
$self->{'weight'}
Truth table100%2/2
A
A= $self->{'weight'}
Aresult
11
00
70 }
71  
72  
73 75 ▶sub port {
Subroutine port: called CC=3 SCAR=11.0
Pod documented
74 75 my ( $self, @value ) = @_;
75 75 for (@value) { $self->{port} = 0 + $_ }
76 75 ▶ return $self->{port} || 0;
Condition100%2/2
$self->{'port'} || 0
l!l
741
MC/DC100%1/1
$self->{'port'} || 0
$self->{'port'}
Truth table100%2/2
A
A= $self->{'port'}
Aresult
11
00
77 }
78  
79  
80 12 ▶sub target {
Subroutine target: called CC=3 SCAR=11.0
Pod documented
81 12 my ( $self, @value ) = @_;
82 12 for (@value) { $self->{target} = Net::DNS::DomainName2535->new($_) }
83 12 ▶ return $self->{target} ? $self->{target}->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'target'} ? : 11 1 12
84 }
85  
86  
87 # order RRs by numerically increasing priority, decreasing weight
88 75 ▶my $function = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
89 75 my ( $a, $b ) = ( $Net::DNS::a, $Net::DNS::b );
90 return $a->{priority} <=> $b->{priority}
91 75 ▶ || $b->{weight} <=> $a->{weight};
Condition66%2/3
$a->{'priority'} <=> $b->{'priority'} || $b->{'weight'} <=> $a->{'weight'}
l!l&&r!l&&!r
45300
MC/DC0%0/2
$a->{'priority'} <=> $b->{'priority'} || $b->{'weight'} <=> $a->{'weight'}
$a->{'priority'} <=> $b->{'priority'} $b->{'weight'} <=> $a->{'weight'}
Truth table66%2/3
A || B
A= $a->{'priority'} <=> $b->{'priority'}B= $b->{'weight'} <=> $a->{'weight'}
ABresult
1X1
011
000
92 2 };
93  
94 2 __PACKAGE__->set_rrsort_func( 'priority', $function );
95  
96 2 __PACKAGE__->set_rrsort_func( 'default_sort', $function );
97  
98  
99 2 1;
100 __END__
« DNS/RR/CERT.pm ↑ Summary DNS/RR/DSYNC.pm »