Created
April 22, 2016 01:53
-
-
Save khanhtran3005/6c7ec54a0282ec66790262ea9ec84781 to your computer and use it in GitHub Desktop.
Load Perl's class by package name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub load_class { | |
my($class, $prefix) = @_; | |
if ($prefix) { | |
unless ($class =~ s/^\+// || $class =~ /^$prefix/) { | |
$class = "$prefix\::$class"; | |
} | |
} | |
my $file = $class; | |
$file =~ s!::!/!g; | |
require "$file.pm"; ## no critic | |
return $class; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment