X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FClientAPI.pm;h=2a880687e3ee334ed3542331b7945bbc91528e44;hp=7cbbdbf67246304c3ad21f615bdc383f7ad879b9;hb=772656864b377bbd2ef2febd40891ef1206b5be0;hpb=0ebeec96313dd7edfca340f01f8fbbbac1f4aa1d diff --git a/FS/FS/ClientAPI.pm b/FS/FS/ClientAPI.pm index 7cbbdbf67..2a880687e 100644 --- a/FS/FS/ClientAPI.pm +++ b/FS/FS/ClientAPI.pm @@ -1,42 +1,56 @@ package FS::ClientAPI; use strict; -use vars qw(%handler $domain); +use base 'Exporter'; +use vars qw( @EXPORT_OK %handler $domain $DEBUG $me ); + +@EXPORT_OK = qw( load_clientapi_modules ); + +$DEBUG = 0; +$me = '[FS::ClientAPI]'; %handler = (); -#find modules -foreach my $INC ( @INC ) { - 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"; - eval "use FS::ClientAPI::$mod;"; - die "error using FS::ClientAPI::$mod: $@" if $@; - } -} +=head1 NAME + +FS::ClientAPI + +=item load_clientapi_modules -#(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}; +=cut + +=cut + +sub load_clientapi_modules { + + #find modules + foreach my $INC ( @INC ) { + my $glob = "$INC/FS/ClientAPI/*.pm"; + warn "FS::ClientAPI: searching $glob" if $DEBUG; + foreach my $file ( glob($glob) ) { + $file =~ /\/(\w+)\.pm$/ or do { + warn "unrecognized ClientAPI file: $file"; + next + }; + my $mod = $1; + warn "using FS::ClientAPI::$mod" if $DEBUG; + eval "use FS::ClientAPI::$mod;"; + die "error using FS::ClientAPI::$mod: $@" if $@; + } } + } -#--- +=item dispatch [ name ] + +=cut sub dispatch { my ( $self, $name ) = ( shift, shift ); - my $sub = $handler{$name} - or die "unknown FS::ClientAPI sub $name (known: ". join(" ", keys %handler ); - #or die "unknown FS::ClientAPI sub $name"; + $name =~ s(/)(::)g; + my $sub = "FS::ClientAPI::$name"; + warn "$me dispatch: calling $sub with args @_\n" if $DEBUG; + no strict 'refs'; &{$sub}(@_); }