Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Modulino::Load;
- # ABSTRACT: Load modulinos into their own namespaces
- use strict;
- use warnings;
- use Module::Runtime 'is_module_name';
- use Carp 'croak';
- # We heard you like legacy code
- # so we put legacy code on your legacy code
- # so you can rake technical debt while raking technical debt.
- # Is this too evil?
- sub import {
- my ( undef, @paths ) = @_;
- my ($caller) = caller;
- for my $path (@paths) {
- croak 'Imported path does not exist: ' . $path unless -e $path;
- # Convert path into pseudo-package name
- # ( no extension, change - into _, and with :: as separators )
- my $package = $path;
- $package =~ s/\..*$//;
- $package =~ y/-/_/;
- $package = join '::', split m{/}, $package;
- croak 'Could not generate module name from path: ' . $package
- unless is_module_name($package);
- # Evil code is evil
- eval qq{ package $package { require("$path") }; };
- }
- }
- 1;
- __END__
- #!/usr/bin/env perl
- use strict;
- use warnings;
- # Load multiple modulinos without polluting your own namespace
- use Modulino::Load qw(
- some/modulino.pl
- another/modulino.pl
- yet-another/crazy/modulino.pl
- );
- main() unless caller;
- sub main {
- some::modulino::run();
- yet_another::crazy::modulino::foo();
- another::modulino::main();
- yet_another::crazy::modulino::bar();
- exit;
- };
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement