Skip to content

Instantly share code, notes, and snippets.

@khanhtran3005
Created April 22, 2016 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khanhtran3005/6c7ec54a0282ec66790262ea9ec84781 to your computer and use it in GitHub Desktop.
Save khanhtran3005/6c7ec54a0282ec66790262ea9ec84781 to your computer and use it in GitHub Desktop.
Load Perl's class by package name
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