File Coverage

blib/lib/Log/Log4perl/Util.pm
Criterion Covered Total %
statement 27 28 96.4
branch 10 12 83.3
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 3 0.0
total 43 51 84.3


line stmt bran cond sub pod time code
1              
2             require Exporter;
3             our @EXPORT_OK = qw( params_check );
4             our @ISA = qw( Exporter );
5              
6             use File::Spec;
7 70     70   534  
  70         157  
  70         32301  
8             ###########################################
9             ###########################################
10             my( $hash, $required, $optional ) = @_;
11              
12 13     13 0 46 my $pkg = caller();
13             my %hash_copy = %$hash;
14 13         27  
15 13         46 if( defined $required ) {
16             for my $p ( @$required ) {
17 13 50       34 if( !exists $hash->{ $p } or
18 13         29 !defined $hash->{ $p } ) {
19 16 50 33     68 die "$pkg: Required parameter $p missing.";
20             }
21 0         0 delete $hash_copy{ $p };
22             }
23 16         36 }
24              
25             if( defined $optional ) {
26             for my $p ( @$optional ) {
27 13 100       33 delete $hash_copy{ $p };
28 12         16 }
29 24         39 if( scalar keys %hash_copy ) {
30             die "$pkg: Unknown parameter: ", join( ",", keys %hash_copy );
31 12 100       49 }
32 1         33 }
33             }
34              
35             ##################################################
36             ##################################################
37             my($full_name) = @_;
38             # Weird cases like "strict;" (including the semicolon) would
39             # succeed with the eval below, so check those up front.
40 565     565 0 1352 # I can't believe Perl doesn't have a proper way to check if a
41             # module is available or not!
42             return 0 if $full_name =~ /[^\w:]/;
43             $full_name =~ s#::#/#g;
44             $full_name .= '.pm';
45 565 100       2132 return 1 if $INC{$full_name};
46 563         2243 eval {
47 563         1136 local $SIG{__DIE__} = sub {};
48 563 100       2460 require $full_name;
49 131         257 };
50 131     37   1041 return !$@;
51 131         52245 }
52              
53 131         100124 ##################################################
54             ##################################################
55              
56             my $name = File::Spec->catfile(File::Spec->tmpdir(),
57             'l4p-tmpfile-' .
58             "$$-" .
59             int(rand(9999999)));
60 1     1 0 186  
61             # Some crazy versions of File::Spec use backslashes on Win32
62             $name =~ s#\\#/#g;
63             return $name;
64             }
65              
66 1         11 1;
67 1         4  
68              
69             =encoding utf8
70              
71             =head1 NAME
72              
73             Log::Log4perl::Util - Internal utility functions
74              
75             =head1 DESCRIPTION
76              
77             Only internal functions here. Don't peek.
78              
79             =head1 LICENSE
80              
81             Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt>
82             and Kevin Goess E<lt>cpan@goess.orgE<gt>.
83              
84             This library is free software; you can redistribute it and/or modify
85             it under the same terms as Perl itself.
86              
87             =head1 AUTHOR
88              
89             Please contribute patches to the project on Github:
90              
91             http://github.com/mschilli/log4perl
92              
93             Send bug reports or requests for enhancements to the authors via our
94              
95             MAILING LIST (questions, bug reports, suggestions/patches):
96             log4perl-devel@lists.sourceforge.net
97              
98             Authors (please contact them via the list above, not directly):
99             Mike Schilli <m@perlmeister.com>,
100             Kevin Goess <cpan@goess.org>
101              
102             Contributors (in alphabetical order):
103             Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton
104             Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony
105             Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy
106             Grundman, Paul Harrington, Alexander Hartmaier David Hull,
107             Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
108             Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope,
109             Lars Thegler, David Viner, Mac Yang.
110