PageRenderTime 33ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Apache/Voodoo/Loader.pm

http://github.com/maverick/ApacheVoodoo
Perl | 69 lines | 31 code | 11 blank | 27 comment | 2 complexity | b9ebef505288bef324abe4772365e72b MD5 | raw file
Possible License(s): LGPL-2.0
  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. $VERSION = "3.0206";
  11. use strict;
  12. use warnings;
  13. sub load_module {
  14. my $self = shift;
  15. my $module = shift || $self->{'module'};
  16. my $file = $module;
  17. $file =~ s/::/\//go;
  18. $file .= ".pm";
  19. # HERE BE THE BLACK MAGIC
  20. # perl stores the names of the loaded modules in here.
  21. # so, if you require the same module twice (or you change it on disk later)
  22. # perl consults this hash and doesn't reload it.
  23. # delete the entry, and perl will re-require the module from scratch
  24. #
  25. # We don't want to do this when the server is starting for the first time. If
  26. # we're running multiple instances of the same application, then we're just
  27. # wasting time recompiling the same modules over and over, and "warnings" will
  28. # sometimes (uselessly) yell about modules being redefined.
  29. unless ($self->{'bootstrapping'}) {
  30. no warnings 'redefine';
  31. delete $INC{$file};
  32. }
  33. my $obj;
  34. eval {
  35. no warnings 'redefine';
  36. local $SIG{__DIE__};
  37. require $file;
  38. $obj = $module->new();
  39. };
  40. if ($@) {
  41. my $error = "$@";
  42. $error =~ s/Compilation failed in require at .*Apache\/Voodoo\/Loader.pm line.*//;
  43. $module =~ s/^[^:]+:://;
  44. require Apache::Voodoo::Zombie;
  45. $obj = Apache::Voodoo::Zombie->new($module,$error);
  46. }
  47. return $obj;
  48. }
  49. 1;
  50. ################################################################################
  51. # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
  52. # All rights reserved.
  53. #
  54. # You may use and distribute Apache::Voodoo under the terms described in the
  55. # LICENSE file include in this package. The summary is it's a legalese version
  56. # of the Artistic License :)
  57. #
  58. ################################################################################