blib/lib/Net/DDDS.pm

filter: Statementstmt 62.0% 62 / 100 Branchbran 23.0% 6 / 26 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 68.0% 17 / 25 Podpod 0.0% 0 / 7 totaltotal 50.2% 87 / 173 CC 18 SCAR 25.0
CC
18
Cov
52%
apply_rule
56.0
lookup
9.8
is_terminal
6.0
CRAP 12.2
↑ Summary
1 package Net::DDDS;
2  
3 1 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw(Exporter);
11  
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15  
16 # This allows declaration use Net::DDDS ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw(
20
21 ) ] );
22  
23 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24  
25 1 our @EXPORT = qw(
26
27 );
28  
29 1 our $VERSION = '0.01';
30  
31 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
32 1 my $this = shift;
33 1 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
34 1 my $self = bless { @_ }, $class;
35 1 $self->init();
36 1 $self
37 }
38  
39 0 ▶sub init {}
Subroutine init: not called CC=1 SCAR=0.0
Pod undocumented
40  
41 0 ▶sub rules {
Subroutine rules: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my ($self,$key) = @_;
43
44 0 die "Must override: retrieve\n";
45 }
46  
47 1 ▶sub apply_first_rule {
Subroutine apply_first_rule: called CC=2 SCAR=7.2
Pod undocumented
48 1 my ($self,$str) = @_;
49
50 1 ▶ ref $self->{first_rule} eq 'CODE' ? $self->{first_rule}($str) : $str;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'first_rule'} eq 'CODE' ? : 1 0 1
51 }
52  
53 0 ▶sub accept_rule {
Subroutine accept_rule: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my ($self,$rule) = @_;
55
56 0 die "Must override: accept_rule\n";
57 }
58  
59 0 ▶sub apply_rule {
Subroutine apply_rule: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ($self,$rule) = @_;
61
62 0 die "Must override: apply_rule\n";
63
64 }
65  
66 2 ▶sub lookup {
Subroutine lookup: called CC=6 SCAR=22.8
Pod undocumented
67 2 my ($self,$str,$key) = @_;
68
69 2 ▶ return $self->lookup($str,$self->apply_first_rule($str)) unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 1 1 2
70 1 my $result;
71 1 foreach my $rule ($self->rules($key)) {
72 1 ▶ if ($self->accept_rule($rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->accept_rule($rule)) 0 1 1
73 0 ▶ $result = $self->apply_rule($rule,$str) or next;
Branch: 1 branch
BranchTrueFalseTotal
$result = $self->apply_rule($rule, $str) or next 0 0 0
74
75 0 ▶ return $result if $self->is_terminal($rule);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal($rule) 0 0 0
76 0 return $self->lookup($str,$result);
77 }
78 }
79
80 1 undef;
81 }
82  
83 package Net::DDDS::DNS;
84  
85 1 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 1 ▶use base qw/Net::DDDS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
89 1 my ($self) = @_;
90 1 $self->{_resolver} = Net::DNS::Resolver->new();
91 }
92  
93 1 ▶sub accept_rule {
Subroutine accept_rule: called CC=3 SCAR=14.2
94 1 my ($self,$rule) = @_;
95
96 1 ▶ return undef unless ref $rule && $rule->isa('Net::DNS::RR::NAPTR');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule and $rule->isa("Net::DNS::RR::NAPTR") 1 0 1
Condition33%1/3
ref $rule and $rule->isa("Net::DNS::RR::NAPTR")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $rule and $rule->isa("Net::DNS::RR::NAPTR")
ref $rule $rule->isa("Net::DNS::RR::NAPTR")
Truth table33%1/3
A and B
A= ref $ruleB= $rule->isa("Net::DNS::RR::NAPTR")
ABresult
0X0
100
111
97 0 $rule->service =~ m{\Q$self->{service}\E};
98 }
99  
100 0 ▶sub is_terminal {
Subroutine is_terminal: not called CC=2 SCAR=17.9
101 0 my ($self,$rule) = @_;
102
103 0 ▶ die "Bad rule" unless $rule->isa('Net::DNS::RR::NAPTR');
Branch: 1 branch
BranchTrueFalseTotal
unless $rule->isa("Net::DNS::RR::NAPTR") 0 0 0
104 0 $rule->flags =~ /$self->{terminal}/;
105 }
106  
107 1 ▶sub rules {
Subroutine rules: called CC=2 SCAR=8.1
108 1 my ($self,$key) = @_;
109 1 ▶ my $result = $self->{_resolver}->query($key,'NAPTR') or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $result = $self->{"_resolver"}->query($key, "NAPTR") or return undef 0 1 1
110 0 $result->answer;
111 }
112  
113 0 ▶sub apply_rule {
Subroutine apply_rule: not called CC=7 SCAR=40.3
114 0 my ($self,$rule,$key) = @_;
115  
116 0 ▶ die "Bad rule" unless $rule->isa('Net::DNS::RR::NAPTR');
Branch: 1 branch
BranchTrueFalseTotal
unless $rule->isa("Net::DNS::RR::NAPTR") 0 0 0
117
118 0 ▶ die "Regexp and replacement both null: $rule\n" unless $rule->regexp || $rule->replacement;
Branch: 1 branch
BranchTrueFalseTotal
unless $rule->regexp or $rule->replacement 0 0 0
Condition0%0/3
$rule->regexp or $rule->replacement
l!l&&r!l&&!r
000
MC/DC0%0/2
$rule->regexp or $rule->replacement
$rule->regexp $rule->replacement
Truth table0%0/3
A or B
A= $rule->regexpB= $rule->replacement
ABresult
1X1
011
000
119 0 ▶ if ($rule->regexp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->regexp) { } 0 0 0
120 0 my $delimc = substr($rule->regexp,0,1);
121 0 my $mi = index($rule->regexp,$delimc,1);
122 0 ▶ die "Bad regular expression: ".$rule->regexp."\n" if $mi == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $mi == -1 0 0 0
123 0 my $ri = index($rule->regexp,$delimc,$mi+1);
124 0 ▶ die "Bad regular expression: ".$rule->regexp."\n" if $ri == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $ri == -1 0 0 0
125 0 my $match = substr($rule->regexp,1,$mi-1);
126 0 my $repl = substr($rule->regexp,$mi+1,$ri-$mi-1);
127 0 my $flags = substr($rule->regexp,$ri+1);
128 0 $repl =~ s{\\([0-9]+)}{$$1}og;
129 0 $key =~ s{$match}{$repl};
130 0 return $key;
131 } else {
132 0 return $rule->replacement;
133 }
134 }
135  
136 package Net::DDDS::ENUM;
137 1 ▶use base qw/Net::DDDS::DNS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 1 ▶sub enum_first_rule {
Subroutine enum_first_rule: called CC=1 SCAR=0.0
140 1 my ($str) = @_;
141  
142 1 $str =~ s/[^0-9]//og;
143 1 my $x = sprintf "%s.e164.arpa",join('.',reverse(split '',$str));
144 1 $x;
145 }
146  
147 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
148 1 my ($self) = @_;
149
150 1 $self->SUPER::init();
151
152 1 $self->{terminal} = 'u';
153 1 $self->{service} = 'E2U+sip';
154 1 $self->{first_rule} = \&enum_first_rule;
155 }
156  
157 package Net::DDDS::SAMLMetadata;
158 1 ▶use base qw/Net::DDDS::DNS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 0 ▶sub samlmd_first_rule {
Subroutine samlmd_first_rule: not called CC=1 SCAR=6.9
162 0 my ($str) = @_;
163  
164 0 my $u = URI->new($str);
165 0 $u->host;
166 }
167  
168 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
169 0 my ($self) = @_;
170
171 0 $self->SUPER::init();
172 0 $self->{terminal} = "U";
173 0 $self->{service} = "PID2U+http";
174 0 $self->{first_rule} = \&samlmd_first_rule;
175 }
176  
177 package Net::DDDS;
178  
179 # Preloaded methods go here.
180  
181 # Autoload methods go after =cut, and are processed by the autosplit program.
182  
183 1 1;
184 __END__
↑ Summary