summaryrefslogtreecommitdiff
path: root/FS/FS/ClientAPI.pm
diff options
context:
space:
mode:
Diffstat (limited to 'FS/FS/ClientAPI.pm')
-rw-r--r--FS/FS/ClientAPI.pm27
1 files changed, 17 insertions, 10 deletions
diff --git a/FS/FS/ClientAPI.pm b/FS/FS/ClientAPI.pm
index 902f58b31..7cbbdbf67 100644
--- a/FS/FS/ClientAPI.pm
+++ b/FS/FS/ClientAPI.pm
@@ -1,35 +1,42 @@
package FS::ClientAPI;
use strict;
-use vars qw(%handler $domain $DEBUG);
-
-$DEBUG = 0;
+use vars qw(%handler $domain);
%handler = ();
#find modules
foreach my $INC ( @INC ) {
- my $glob = "$INC/FS/ClientAPI/*.pm";
- warn "FS::ClientAPI: searching $glob" if $DEBUG;
- foreach my $file ( glob($glob) ) {
+ foreach my $file ( glob("$INC/FS/ClientAPI/*.pm") ) {
$file =~ /\/(\w+)\.pm$/ or do {
warn "unrecognized ClientAPI file: $file";
next
};
my $mod = $1;
- warn "using FS::ClientAPI::$mod" if $DEBUG;
+ #warn "using FS::ClientAPI::$mod";
eval "use FS::ClientAPI::$mod;";
die "error using FS::ClientAPI::$mod: $@" if $@;
}
}
+#(sub for modules)
+sub register_handlers {
+ my $self = shift;
+ my %new_handlers = @_;
+ foreach my $key ( keys %new_handlers ) {
+ warn "WARNING: redefining sub $key" if exists $handler{$key};
+ #warn "registering $key";
+ $handler{$key} = $new_handlers{$key};
+ }
+}
+
#---
sub dispatch {
my ( $self, $name ) = ( shift, shift );
- $name =~ s(/)(::)g;
- my $sub = "FS::ClientAPI::$name";
- no strict 'refs';
+ my $sub = $handler{$name}
+ or die "unknown FS::ClientAPI sub $name (known: ". join(" ", keys %handler );
+ #or die "unknown FS::ClientAPI sub $name";
&{$sub}(@_);
}