per-agent disable_previous_balance, #15863
[freeside.git] / FS / FS / ClientAPI.pm
1 package FS::ClientAPI;
2
3 use strict;
4 use base 'Exporter';
5 use vars qw( @EXPORT_OK %handler $domain $DEBUG $me );
6
7 @EXPORT_OK = qw( load_clientapi_modules );
8
9 $DEBUG = 0;
10 $me = '[FS::ClientAPI]';
11
12 %handler = ();
13
14 sub load_clientapi_modules {
15
16   #find modules
17   foreach my $INC ( @INC ) {
18     my $glob = "$INC/FS/ClientAPI/*.pm";
19     warn "FS::ClientAPI: searching $glob" if $DEBUG;
20     foreach my $file ( glob($glob) ) {
21       $file =~ /\/(\w+)\.pm$/ or do {
22         warn "unrecognized ClientAPI file: $file";
23         next
24       };
25       my $mod = $1;
26       warn "using FS::ClientAPI::$mod" if $DEBUG;
27       eval "use FS::ClientAPI::$mod;";
28       die "error using FS::ClientAPI::$mod: $@" if $@;
29     }
30   }
31
32 }
33
34 sub dispatch {
35   my ( $self, $name ) = ( shift, shift );
36   $name =~ s(/)(::)g;
37   my $sub = "FS::ClientAPI::$name";
38   warn "$me dispatch: calling $sub with args @_\n" if $DEBUG;
39   no strict 'refs';
40   &{$sub}(@_);
41 }
42
43 1;
44