File Coverage

blib/lib/Apache/Voodoo/Loader.pm
Criterion Covered Total %
statement 31 31 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             ################################################################################
2             #
3             # Apache::Voodoo::Loader
4             #
5             # Base class for each of the module loading mechanisms. Look at Loader::Static
6             # and Loader::Dynamic
7             #
8             ################################################################################
9             package Apache::Voodoo::Loader;
10              
11             $VERSION = "3.0200";
12              
13 3     3   16 use strict;
  3         5  
  3         118  
14 3     3   22 use warnings;
  3         5  
  3         311  
15              
16             sub load_module {
17 11     11 0 20 my $self = shift;
18 11   66     68 my $module = shift || $self->{'module'};
19              
20 11         28 my $file = $module;
21 11         60 $file =~ s/::/\//go;
22 11         24 $file .= ".pm";
23              
24             # HERE BE THE BLACK MAGIC
25             # perl stores the names of the loaded modules in here.
26             # so, if you require the same module twice (or you change it on disk later)
27             # perl consults this hash and doesn't reload it.
28             # delete the entry, and perl will re-require the module from scratch
29             #
30             # We don't want to do this when the server is starting for the first time. If
31             # we're running multiple instances of the same application, then we're just
32             # wasting time recompiling the same modules over and over, and "warnings" will
33             # sometimes (uselessly) yell about modules being redefined.
34 11 100       51 unless ($self->{'bootstrapping'}) {
35 3     3   17 no warnings 'redefine';
  3         5  
  3         176  
36 6         29 delete $INC{$file};
37             }
38              
39 11         21 my $obj;
40 11         22 eval {
41 3     3   14 no warnings 'redefine';
  3         11  
  3         624  
42 11         61 local $SIG{__DIE__};
43 11         4883 require $file;
44 10         4883 $obj = $module->new();
45             };
46 11 100       48 if ($@) {
47 1         3 my $error = "$@";
48 1         4 $error =~ s/Compilation failed in require at .*Apache\/Voodoo\/Loader.pm line.*//;
49              
50 1         6 $module =~ s/^[^:]+:://;
51              
52 1         740 require Apache::Voodoo::Zombie;
53 1         8 $obj = Apache::Voodoo::Zombie->new($module,$error);
54             }
55              
56 11         78 return $obj;
57             }
58              
59             1;
60              
61             ################################################################################
62             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
63             # All rights reserved.
64             #
65             # You may use and distribute Apache::Voodoo under the terms described in the
66             # LICENSE file include in this package. The summary is it's a legalese version
67             # of the Artistic License :)
68             #
69             ################################################################################