blib/lib/Amon2/Util.pm

filter: Statementstmt 84.0% 37 / 44 Branchbran 50.0% 2 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 75.3% 49 / 65 CC 4 SCAR 12.5
CC
4
Cov
78%
base_dir
12.0
random_string
2.0
BEGIN
1.0
CRAP 3.5
« blib/lib/Amon2/Web/WebSocket.pm ↑ Summary blib/lib/Amon2/Trigger.pm »
1 package Amon2::Util;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use Crypt::SysRandom qw(random_bytes);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 our @EXPORT_OK = qw/add_method random_string/;
11  
12 11 ▶sub add_method {
Subroutine add_method: called CC=1 SCAR=0.0
Pod undocumented
13 11 my ($klass, $method, $code) = @_;
14 22 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 *{"${klass}::${method}"} = $code;
16 }
17  
18 0 ▶sub base_dir($) {
Subroutine base_dir: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my $path = shift;
20 0 $path =~ s!::!/!g;
21 0 ▶ if (my $libpath = $INC{"$path.pm"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $libpath = $INC{"$path.pm"}) { } 0 0 0
22 0 $libpath =~ s!\\!/!g; # win32
23 0 $libpath =~ s!(?:blib/)?lib/+$path\.pm$!!;
24 0 ▶ File::Spec->rel2abs($libpath || './');
Condition0%0/2
$libpath || './'
l!l
00
MC/DC0%0/1
$libpath || './'
$libpath
Truth table0%0/2
A
A= $libpath
Aresult
11
00
25 } else {
26 0 File::Spec->rel2abs('./');
27 }
28 }
29  
30 201 ▶sub random_string {
Subroutine random_string: called CC=2 SCAR=6.9
Pod undocumented
31 201 my $len = shift;
32  
33 201 ▶ if ($len < 27) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < 27) 26 175 201
34 26 Carp::cluck("Amon2::Util::random_string: Length too short. You should use 27+ bytes for security reason.");
35 }
36  
37 201 my $src_len = int($len / 3 * 4) + 4;
38 201 my $buf = random_bytes($src_len);
39 201 my $result = MIME::Base64::encode_base64($buf, '');
40 201 $result =~ tr|+/=|\-_|d; # make it url safe
41 201 return substr($result, 0, $len);
42 }
43  
44 22 1;
45 __END__
« blib/lib/Amon2/Web/WebSocket.pm ↑ Summary blib/lib/Amon2/Trigger.pm »