Log4perl/Util.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 83.3% 10 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 82.4% 47 / 57 CC 10 SCAR 17.5
CC
10
Cov
89%
params_check
8.6
module_available
3.0
BEGIN
1.0
CRAP 5.8
« Log4perl/Config/BaseConfigurator.pm ↑ Summary Log4perl/Level.pm »
1 package Log::Log4perl::Util;
2  
3 54 require Exporter;
4 54 our @EXPORT_OK = qw( params_check );
5 54 our @ISA = qw( Exporter );
6  
7 54 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ###########################################
10 13 ▶sub params_check {
Subroutine params_check: called CC=8 SCAR=21.5
Pod undocumented
11 ###########################################
12 13 my( $hash, $required, $optional ) = @_;
13  
14 13 my $pkg = caller();
15 13 my %hash_copy = %$hash;
16  
17 13 ▶ if( defined $required ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $required) 13 0 13
18 13 for my $p ( @$required ) {
19 16 ▶ if( !exists $hash->{ $p } or
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash->{$p} and defined $hash->{$p}) 0 16 16
Condition33%1/3
exists $hash->{$p} and defined $hash->{$p}
!ll&&!rl&&r
0016
MC/DC0%0/2
exists $hash->{$p} and defined $hash->{$p}
exists $hash->{$p} defined $hash->{$p}
Truth table33%1/3
A and B
A= exists $hash->{$p}B= defined $hash->{$p}
ABresult
0X0
100
111
20 !defined $hash->{ $p } ) {
21 0 die "$pkg: Required parameter $p missing.";
22 }
23 16 delete $hash_copy{ $p };
24 }
25 }
26  
27 13 ▶ if( defined $optional ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $optional) 12 1 13
28 12 for my $p ( @$optional ) {
29 24 delete $hash_copy{ $p };
30 }
31 12 ▶ if( scalar keys %hash_copy ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %hash_copy) 1 11 12
32 1 die "$pkg: Unknown parameter: ", join( ",", keys %hash_copy );
33 }
34 }
35 }
36  
37 ##################################################
38 470 ▶sub module_available { # Check if a module is available
Subroutine module_available: called CC=3 SCAR=11.0
Pod undocumented
39 ##################################################
40 470 my($full_name) = @_;
41 # Weird cases like "strict;" (including the semicolon) would
42 # succeed with the eval below, so check those up front.
43 # I can't believe Perl doesn't have a proper way to check if a
44 # module is available or not!
45 470 ▶ return 0 if $full_name =~ /[^\w:]/;
Branch: 1 branch
BranchTrueFalseTotal
if $full_name =~ /[^\w:]/ 2 468 470
46 468 $full_name =~ s#::#/#g;
47 468 $full_name .= '.pm';
48 468 ▶ return 1 if $INC{$full_name};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$full_name} 375 93 468
49 93 eval {
50 93 ▶ local $SIG{__DIE__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
51 93 require $full_name;
52 };
53 93 return !$@;
54 }
55  
56 ##################################################
57 1 ▶sub tmpfile_name { # File::Temp without the bells and whistles
Subroutine tmpfile_name: called CC=1 SCAR=0.0
Pod undocumented
58 ##################################################
59  
60 1 my $name = File::Spec->catfile(File::Spec->tmpdir(),
61 'l4p-tmpfile-' .
62 "$$-" .
63 int(rand(9999999)));
64  
65 # Some crazy versions of File::Spec use backslashes on Win32
66 1 $name =~ s#\\#/#g;
67 1 return $name;
68 }
69  
70 54 1;
71  
72 __END__
« Log4perl/Config/BaseConfigurator.pm ↑ Summary Log4perl/Level.pm »