X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FUID.pm;h=3d893ee2fcd7ad989b0c5486300f87c490da76c5;hp=87830cb0469468b718bdf67ca058bdb9648f0805;hb=e7acc4af0a47299644ff2389be3991b708878693;hpb=251c436ab3d9b79d74ab4fc9af05aac4acf26489 diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm index 87830cb04..3d893ee2f 100644 --- a/FS/FS/UID.pm +++ b/FS/FS/UID.pm @@ -3,8 +3,8 @@ package FS::UID; use strict; use vars qw( @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user - $conf_dir $secrets $datasrc $db_user $db_pass %callback $driver_name - $AutoCommit + $conf_dir $secrets $datasrc $db_user $db_pass %callback @callback + $driver_name $AutoCommit ); use subs qw( getsecrets cgisetotaker @@ -16,7 +16,7 @@ use FS::Conf; @ISA = qw(Exporter); @EXPORT_OK = qw(checkeuid checkruid cgisuidsetup adminsuidsetup forksuidsetup - getotaker dbh datasrc getsecrets driver_name ); + getotaker dbh datasrc getsecrets driver_name myconnect ); $freeside_uid = scalar(getpwnam('freeside')); @@ -84,20 +84,46 @@ sub forksuidsetup { $ENV{'BASH_ENV'} = ''; croak "Not running uid freeside!" unless checkeuid(); - getsecrets; - $dbh = DBI->connect($datasrc,$db_user,$db_pass, { - 'AutoCommit' => 0, - 'ChopBlanks' => 1, - } ) or die "DBI->connect error: $DBI::errstr\n"; + + $dbh = &myconnect; foreach ( keys %callback ) { &{$callback{$_}}; - delete $callback{$_}; #run once + # breaks multi-database installs # delete $callback{$_}; #run once } + &{$_} foreach @callback; + $dbh; } +sub myconnect { + $dbh = DBI->connect( getsecrets, {'AutoCommit' => 0, 'ChopBlanks' => 1, } ) + or die "DBI->connect error: $DBI::errstr\n"; +} + +=item install_callback + +A package can install a callback to be run in adminsuidsetup by passing +a coderef to the FS::UID->install_callback class method. If adminsuidsetup has +run already, the callback will also be run immediately. + + $coderef = sub { warn "Hi, I'm returning your call!" }; + FS::UID->install_callback($coderef); + + install_callback FS::UID sub { + warn "Hi, I'm returning your call!" + }; + +=cut + +sub install_callback { + my $class = shift; + my $callback = shift; + push @callback, $callback; + &{$callback} if $dbh; +} + =item cgisuidsetup CGI_object Takes a single argument, which is a CGI (see L) or Apache (see L) @@ -246,17 +272,28 @@ sub getsecrets { =head1 CALLBACKS -Warning: this interface is likely to change in future releases. +Warning: this interface is (still) likely to change in future releases. -A package can install a callback to be run in adminsuidsetup by putting a -coderef into the hash %FS::UID::callback : +New (experimental) callback interface: + +A package can install a callback to be run in adminsuidsetup by passing +a coderef to the FS::UID->install_callback class method. If adminsuidsetup has +run already, the callback will also be run immediately. $coderef = sub { warn "Hi, I'm returning your call!" }; - $FS::UID::callback{'Package::Name'}; + FS::UID->install_callback($coderef); -=head1 VERSION + install_callback FS::UID sub { + warn "Hi, I'm returning your call!" + }; -$Id: UID.pm,v 1.15 2002-06-14 09:19:33 ivan Exp $ +Old (deprecated) callback interface: + +A package can install a callback to be run in adminsuidsetup by putting a +coderef into the hash %FS::UID::callback : + + $coderef = sub { warn "Hi, I'm returning your call!" }; + $FS::UID::callback{'Package::Name'} = $coderef; =head1 BUGS @@ -269,7 +306,7 @@ cgisuidsetup will go away as well. Goes through contortions to support non-OO syntax with multiple datasrc's. -Callbacks are inelegant. +Callbacks are (still) inelegant. =head1 SEE ALSO