DJabberd/Util.pm

filter: Statementstmt 42.3% 22 / 52 Branchbran 37.5% 6 / 16 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 9 totaltotal 30.0% 33 / 110 CC 14 SCAR 23.4
CC
14
Cov
35%
numeric_entity_clean
30.0
as_abs_path
12.0
as_bind_addr
7.2
CRAP 10.4
« DJabberd/Agent.pm ↑ Summary DJabberd/Bot.pm »
1 package DJabberd::Util;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 require Exporter;
4 20 our @ISA = qw(Exporter);
5 20 our @EXPORT_OK = qw(exml tsub lbsub as_bool as_num as_abs_path as_bind_addr);
6  
7 7 ▶sub as_bool {
Subroutine as_bool: called CC=3 SCAR=11.4
Pod undocumented
8 7 my $val = shift;
9 7 ▶ return 1 if $val =~ /^1|y|yes|true|t|on|enabled?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^1|y|yes|true|t|on|enabled?$/i 4 3 7
10 3 ▶ return 0 if $val =~ /^0|n|no|false|f|off|disabled?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^0|n|no|false|f|off|disabled?$/i 3 0 3
11 0 die "Can't determine booleanness of '$val'\n";
12 }
13  
14 0 ▶sub as_num {
Subroutine as_num: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my $val = shift;
16 0 ▶ return $val if $val =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^\d+$/ 0 0 0
17 0 die "'$val' is not a number\n";
18 }
19  
20 85 ▶sub as_bind_addr {
Subroutine as_bind_addr: called CC=4 SCAR=19.7
Pod undocumented
21 85 my $val = shift;
22 # Must either be like 127.0.0.1:1234, a bare port number or an absolute path to a unix domain socket
23 85 ▶ if ($val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ || ($val =~ m!^/! && -e $val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ or $val =~ m[^/] and -e $val) 85 0 85
Condition16%1/6
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ or $val =~ m[^/] and -e $val
l!l&&r!l&&!r
8500
$val =~ m[^/] and -e $val
!ll&&!rl&&r
000
MC/DC0%0/3
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ or $val =~ m[^/] and -e $val
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ $val =~ m[^/] -e $val
Truth table25%1/4
A or B and C
A= $val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/B= $val =~ m[^/]C= -e $val
ABCresult
1XX1
0111
00X0
0100
24 85 return $val;
25 }
26 0 die "'$val' is not a valid bind address or port\n";
27 }
28  
29 0 ▶sub as_abs_path {
Subroutine as_abs_path: not called CC=3 SCAR=24.8
Pod undocumented
30 0 my $val = shift;
31 0 ▶ die "Path '$val' isn't absolute" unless $val =~ m!^/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ m[^/] 0 0 0
32 0 ▶ die "File '$val' doesn't exist" unless -f $val;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $val 0 0 0
33 0 return $val;
34 }
35  
36 sub exml
37 1130 ▶{
Subroutine exml: called CC=2 SCAR=6.9
Pod undocumented
38 # fast path for the commmon case:
39 1130 ▶ return $_[0] unless $_[0] =~ /[&\"\'<>\x00-\x08\x0B\x0C\x0E-\x1F]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /[&\"\'<>\x00-\x08\x0B\x0C\x0E-\x1F]/ 891 239 1130
40 # what are those character ranges? XML 1.0 allows:
41 # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
42  
43 239 my $a = shift;
44 239 $a =~ s/\&/&amp;/g;
45 239 $a =~ s/\"/&quot;/g;
46 239 $a =~ s/\'/&apos;/g;
47 239 $a =~ s/</&lt;/g;
48 239 $a =~ s/>/&gt;/g;
49 239 $a =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F]//g;
50 239 return $a;
51 }
52  
53 0 ▶sub durl {
Subroutine durl: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my ($a) = @_;
55 0 $a =~ tr/+/ /;
56 0 $a =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
57 0 return $a;
58 }
59  
60 # tracked sub
61 0 ▶sub tsub (&) {
Subroutine tsub: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $subref = shift;
63 0 bless $subref, 'DJabberd::TrackedSub';
64 0 DJabberd->track_new_obj($subref);
65 0 return $subref;
66 }
67  
68 # line-blessed sub
69 0 ▶sub lbsub (&) {
Subroutine lbsub: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my $subref = shift;
71 0 my ($pkg, $file, $line) = caller;
72 0 my $bpkg = $file . "_" . $line;
73 0 $bpkg =~ s/[^\w]/_/g;
74 0 return bless $subref, "DJabberd::AnonSubFrom::$bpkg";
75 }
76  
77 0 ▶sub numeric_entity_clean {
Subroutine numeric_entity_clean: not called CC=5 SCAR=34.0
Pod undocumented
78 0 my $hex = $_[0];
79 0 my $val = hex $hex;
80  
81 # under a space, only \n, \r, and \t are allowed.
82 0 ▶ if ($val < 32 && ($val != 13 && $val != 10 && $val != 9)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val < 32 and ($val != 13 and $val != 10 and $val != 9)) 0 0 0
Condition0%0/9
$val < 32 and ($val != 13 and $val != 10 and $val != 9)
!ll&&!rl&&r
000
$val != 13 and $val != 10 and $val != 9
!ll&&!rl&&r
000
$val != 13 and $val != 10
!ll&&!rl&&r
000
MC/DC0%0/4
$val < 32 and ($val != 13 and $val != 10 and $val != 9)
$val < 32 $val != 13 $val != 10 $val != 9
Truth table0%0/5
A and B and C and D
A= $val < 32B= $val != 13C= $val != 10D= $val != 9
ABCDresult
0XXX0
10XX0
110X0
11100
11111
83 0 return "";
84 }
85  
86 0 return "&#$hex;";
87 }
88  
89 package DJabberd::TrackedSub;
90  
91 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
92 0 my $self = shift;
93 0 DJabberd->track_destroyed_obj($self);
94 }
95  
96 20 1;
« DJabberd/Agent.pm ↑ Summary DJabberd/Bot.pm »