| 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
| |||||||||||||||||||||||||||||
| 18 | 13 | for my $p ( @$required ) { | |||||||||||||||||||||||||||
| 19 | 16 | ▶ | if( !exists $hash->{ $p } or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $hash->{$p} and defined $hash->{$p}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | 12 | for my $p ( @$optional ) { | |||||||||||||||||||||||||||
| 29 | 24 | delete $hash_copy{ $p }; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 12 | ▶ | if( scalar keys %hash_copy ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 468 | $full_name =~ s#::#/#g; | |||||||||||||||||||||||||||
| 47 | 468 | $full_name .= '.pm'; | |||||||||||||||||||||||||||
| 48 | 468 | ▶ | return 1 if $INC{$full_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||