1package Log::Log4perl::Util;
2
3use File::Spec;
4
5##################################################
6sub module_available {  # Check if a module is available
7##################################################
8# This has to be here, otherwise the following 'use'
9# statements will fail.
10##################################################
11    my($full_name) = @_;
12
13    my $relpath = File::Spec->catfile(split /::/, $full_name) . '.pm';
14
15        # Work around a bug in Activestate's "perlapp", which uses
16        # forward slashes instead of Win32 ones.
17    my $relpath_with_forward_slashes =
18        join('/', (split /::/, $full_name)) . '.pm';
19
20    return 1 if exists $INC{$relpath} or
21                exists $INC{$relpath_with_forward_slashes};
22
23    foreach my $dir (@INC) {
24        if(ref $dir) {
25            # This is fairly obscure 'require'-functionality, nevertheless
26            # trying to implement them as diligently as possible. For
27            # details, check "perldoc -f require".
28            if(ref $dir eq "CODE") {
29                return 1 if $dir->($dir, $relpath);
30            } elsif(ref $dir eq "ARRAY") {
31                return 1 if $dir->[0]->($dir, $relpath);
32            } elsif(ref $dir and
33                    ref $dir !~ /^(GLOB|SCALAR|HASH|REF|LVALUE)$/) {
34                return 1 if $dir->INC();
35            }
36        } else {
37            # That's the regular case
38            return 1 if -r File::Spec->catfile($dir, $relpath);
39        }
40    }
41
42    return 0;
43}
44
45##################################################
46sub tmpfile_name {  # File::Temp without the bells and whistles
47##################################################
48
49    my $name = File::Spec->catdir(File::Spec->tmpdir(),
50                              'l4p-tmpfile-' .
51                              "$$-" .
52                              int(rand(9999999)));
53
54        # Some crazy versions of File::Spec use backslashes on Win32
55    $name =~ s#\\#/#g;
56    return $name;
57}
58
591;
60
61__END__
62
63=head1 NAME
64
65Log::Log4perl::Util - Internal utility functions
66
67=head1 DESCRIPTION
68
69Only internal functions here. Don't peek.
70
71=head1 AUTHORS
72
73Mike Schilli <m@perlmeister.com>
74
75=head1 COPYRIGHT AND LICENSE
76
77Copyright 2002-2004 by Mike Schilli E<lt>m@perlmeister.comE<gt> and Kevin Goess
78E<lt>cpan@goess.orgE<gt>.
79
80This library is free software; you can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84