Merged Lmo and updated everything that used it

This commit is contained in:
Brian Fraser fraserb@gmail.com
2013-02-01 13:29:48 -03:00
parent 25e62aa305
commit d816c6497e
38 changed files with 5815 additions and 3772 deletions

46
lib/Lmo/Utils.pm Normal file
View 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;