eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[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 =head1 NAME
15
16 FS::ClientAPI
17
18 =item load_clientapi_modules
19
20 =cut
21
22 sub load_clientapi_modules {
23
24   #find modules
25   foreach my $INC ( @INC ) {
26     my $glob = "$INC/FS/ClientAPI/*.pm";
27     warn "FS::ClientAPI: searching $glob" if $DEBUG;
28     foreach my $file ( glob($glob) ) {
29       $file =~ /\/(\w+)\.pm$/ or do {
30         warn "unrecognized ClientAPI file: $file";
31         next
32       };
33       my $mod = $1;
34       warn "using FS::ClientAPI::$mod" if $DEBUG;
35       eval "use FS::ClientAPI::$mod;";
36       die "error using FS::ClientAPI::$mod: $@" if $@;
37     }
38   }
39
40 }
41
42 =item dispatch [ name ]
43
44 =cut
45
46 sub dispatch {
47   my ( $self, $name ) = ( shift, shift );
48   $name =~ s(/)(::)g;
49   my $sub = "FS::ClientAPI::$name";
50   warn "$me dispatch: calling $sub with args @_\n" if $DEBUG;
51   no strict 'refs';
52   &{$sub}(@_);
53 }
54
55 1;
56