diff options
author | Niko Tyni <ntyni@iki.fi> | 2005-09-25 14:16:47 +0200 |
---|---|---|
committer | Niko Tyni <ntyni@iki.fi> | 2005-09-25 14:16:47 +0200 |
commit | 77a6167109b90747b8e3f5fe766cb7979ecea640 (patch) | |
tree | 63722d360c05d985aa9483263dcf44a1d3019d23 /lib | |
parent | 684cb417be1d156c5f48460c73f9d32b851c576b (diff) | |
download | smokeping-77a6167109b90747b8e3f5fe766cb7979ecea640.tar.gz smokeping-77a6167109b90747b8e3f5fe766cb7979ecea640.tar.xz |
* (trunk,2.0)/
lib/Smokeping.pm,
CHANGES:
+ no need to have all the external modules (Net::DNS, Authen::Radius etc.)
installed just to build the documentation.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Smokeping.pm | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm index 04514e4..8becf93 100644 --- a/lib/Smokeping.pm +++ b/lib/Smokeping.pm @@ -1473,8 +1473,7 @@ DOC # load the probe module my $class = "Smokeping::probes::$name"; - eval "require $class"; - die "require $class failed: $@\n" if $@; + Smokeping::maybe_require $class; # modify the grammar my $probevars = $class->probevars; @@ -2755,11 +2754,50 @@ sub pod2man { } } +sub maybe_require { + # like eval "require $class", but tries to + # fake missing classes by adding them to %INC. + # This rocks when we're building the documentation + # so we don't need to have the external modules + # installed. + + my $class = shift; + + # don't do the kludge unless we're building documentation + unless (exists $opt{makepod} or exists $opt{man}) { + eval "require $class"; + die("require $class failed: $@") if $@; + return; + } + + my %faked; + + my $file = $class; + $file =~ s,::,/,g; + $file .= ".pm"; + + eval "require $class"; + + while ($@ =~ /Can't locate (\S+)\.pm/) { + my $missing = $1; + die("Can't fake missing class $missing, giving up. This shouldn't happen.") + if $faked{$missing}++; + $INC{"$missing.pm"} = "foobar"; + $missing =~ s,/,::,; + + delete $INC{"$file"}; # so we can redo the require() + eval "require $class"; + last unless $@; + } + die("require $class failed: $@") if $@; + my $libpath = find_libdir; + $INC{$file} = "$libpath/$file"; +} + sub probedoc { my $class = shift; my $do_man = shift; - eval "require $class"; - die("Failed to load $class: $@") if $@; + maybe_require($class); if ($do_man) { pod2man($class->pod); } else { |