mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Merged Lmo and updated everything that used it
This commit is contained in:
46
lib/Lmo/Utils.pm
Normal file
46
lib/Lmo/Utils.pm
Normal file
@@ -0,0 +1,46 @@
|
||||
package Lmo::Utils;
|
||||
use strict;
|
||||
use warnings qw( FATAL all );
|
||||
require Exporter;
|
||||
our (@ISA, @EXPORT, @EXPORT_OK);
|
||||
|
||||
BEGIN {
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = @EXPORT_OK = qw(_install_coderef _unimport_coderefs _glob_for _stash_for);
|
||||
}
|
||||
|
||||
{
|
||||
# Gets the glob from a given string.
|
||||
no strict 'refs';
|
||||
sub _glob_for {
|
||||
return \*{shift()}
|
||||
}
|
||||
|
||||
# Gets the stash from a given string.
|
||||
# A stash is a symbol table hash; rough explanation on
|
||||
# http://perldoc.perl.org/perlguts.html#Stashes-and-Globs
|
||||
# But the gist of it is that we can use a hash-like thing to
|
||||
# refer to a class and modify it.
|
||||
sub _stash_for {
|
||||
return \%{ shift() . "::" };
|
||||
}
|
||||
}
|
||||
|
||||
sub _install_coderef {
|
||||
my ($to, $code) = @_;
|
||||
|
||||
return *{ _glob_for $to } = $code;
|
||||
}
|
||||
|
||||
sub _unimport_coderefs {
|
||||
my ($target, @names) = @_;
|
||||
return unless @names;
|
||||
my $stash = _stash_for($target);
|
||||
foreach my $name (@names) {
|
||||
if ($stash->{$name} and defined(&{$stash->{$name}})) {
|
||||
delete $stash->{$name};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
Reference in New Issue
Block a user