Skip to content

Commit

Permalink
-- load plugins by either the exact case specified, all lowercase,
Browse files Browse the repository at this point in the history
       or all lowercase with first letter uppercase.  then remember
       the case for unloading (which was never implemented?)


git-svn-id: http://code.sixapart.com/svn/perlbal/trunk@384 6caf28e9-730f-0410-b62b-a31386fe13fb
  • Loading branch information
bradfitz committed Aug 11, 2005
1 parent 452b852 commit 2fbf664
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- load plugins by either the exact case specified, all lowercase,
or all lowercase with first letter uppercase. then remember
the case for unloading (which was never implemented?)

-- reorganize/cleanup code related to stalling the backend due to
client's buffer size exceeding one of the two limits.
introduce "backend_stalled"
Expand Down
49 changes: 38 additions & 11 deletions lib/Perlbal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ our $reqs = 0; # total number of requests we've done
our $starttime = time(); # time we started
our ($lastutime, $laststime, $lastreqs) = (0, 0, 0); # for deltas

our %PluginCase = (); # lowercase plugin name -> as file is named

# setup XS status data structures
our %XSModules; # ( 'headers' => 'Perlbal::XS::HTTPHeaders' )

Expand Down Expand Up @@ -183,6 +185,12 @@ sub pool {
return $pool{$_[0]};
}

# given some plugin name, return its correct case
sub plugin_case {
my $pname = lc shift;
return $PluginCase{$pname} || $pname;
}

# run a block of commands. returns true if they all passed
sub run_manage_commands {
my ($cmd_block, $out, $ctx) = @_;
Expand Down Expand Up @@ -859,18 +867,37 @@ sub MANAGE_enable {
}
*MANAGE_disable = \&MANAGE_enable;

sub MANAGE_unload {
my $mc = shift->parse(qr/^unload (\w+)$/);
my ($fn) = $mc->args;
$fn = $PluginCase{lc $fn};
my $rv = eval "Perlbal::Plugin::$fn->unload; 1;";
$plugins{$fn} = 0;
return $mc->ok;
}

sub MANAGE_load {
my $mc = shift->parse(qr/^(un)?load (\w+)$/);
my ($un, $fn) = $mc->args;
$un ||= "";

if (length $fn) {
# since we lowercase our input, uppercase the first character here
$fn = uc($1) . lc($2) if $fn =~ /^(.)(.*)$/;
eval "use Perlbal::Plugin::$fn; Perlbal::Plugin::$fn->${un}load;";
return $mc->err($@) if $@;
$plugins{$fn} = $un ? 0 : 1;
}
my $mc = shift->parse(qr/^load \w+$/);

my $fn;
$fn = $1 if $mc->orig =~ /^load (\w+)$/i;

my $last_case;

my $load = sub {
my $name = shift;
$last_case = $name;
return eval "use Perlbal::Plugin::$name; Perlbal::Plugin::$name->load; 1;";
# TODO: return $mc->err immediately if $@ is a syntax
# error (or something not regarding missing files)?
};

my $rv = $load->($fn) || $load->(lc $fn) || $load->(ucfirst lc $fn);
return $mc->err($@) unless $rv;

$PluginCase{lc $fn} = $last_case;
$plugins{$last_case} = 1;

return $mc->ok;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Perlbal/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ sub set {
foreach my $plugin (split /[\s,]+/, $val) {
next if $plugin eq 'none';

# since we lowercase our input, uppercase the first character here
my $fn = uc($1) . lc($2) if $plugin =~ /^(.)(.*)$/;
my $fn = Perlbal::plugin_case($plugin);

next if $self->{plugins}->{$fn};
unless ($Perlbal::plugins{$fn}) {
$mc->err("Plugin $fn not loaded; not registered for $self->{name}.");
Expand Down

0 comments on commit 2fbf664

Please sign in to comment.