remove unnecessary circular use of FS::ClientAPI, doesn't work with 5.8.[56] + perl??
[freeside.git] / FS / FS / ClientAPI.pm
1 package FS::ClientAPI;
2
3 use strict;
4 use vars qw(%handler $domain $DEBUG);
5
6 $DEBUG = 1;
7
8 %handler = ();
9
10 #find modules
11 foreach my $INC ( @INC ) {
12   my $glob = "$INC/FS/ClientAPI/*.pm";
13   warn "FS::ClientAPI: searching $glob" if $DEBUG;
14   foreach my $file ( glob($glob) ) {
15     $file =~ /\/(\w+)\.pm$/ or do {
16       warn "unrecognized ClientAPI file: $file";
17       next
18     };
19     my $mod = $1;
20     warn "using FS::ClientAPI::$mod" if $DEBUG;
21     eval "use FS::ClientAPI::$mod;";
22     die "error using FS::ClientAPI::$mod: $@" if $@;
23   }
24 }
25
26 #(sub for modules)
27 sub register_handlers {
28   my $self = shift;
29   my %new_handlers = @_;
30   foreach my $key ( keys %new_handlers ) {
31     warn "WARNING: redefining sub $key" if exists $handler{$key};
32     #warn "registering $key";
33     $handler{$key} = $new_handlers{$key};
34   }
35 }
36
37 #---
38
39 sub dispatch {
40   my ( $self, $name ) = ( shift, shift );
41   my $sub = $handler{$name}
42     or die "unknown FS::ClientAPI sub $name (known: ". join(" ", keys %handler );
43     #or die "unknown FS::ClientAPI sub $name";
44   &{$sub}(@_);
45 }
46
47 1;
48