summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/Smokeping.pm46
2 files changed, 45 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index d7a3e86..07d74ce 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+* don't need to have all the external modules installed to build the
+ documentation -- niko
+
2005/9/25 -- released version 20050925_trunk
2005/9/24 -- released version 20050924_trunk
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 {