Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.77 KB | None | 0 0
  1. class NieczaPathSearch;
  2.  
  3. has @.path;
  4.  
  5. # Given Foo::Bar, find ($?FILE, $?ORIG)
  6. method load_module($name) {
  7.     my $sub = "".IO.combine($name.split('::'));
  8.  
  9.     my @path = ($*unit ?? $*unit.get_incs !! ()), @!path;
  10.  
  11.     for @path -> $pe {
  12.         for <pm6 pm setting> -> $ext {
  13.             my $fn = $pe.IO.append($sub).but-extension($ext);
  14.             if $fn.f {
  15.                 my $text = $fn.slurp;
  16.                 # check borrowed from STD to weed out Perl 5 heuristically
  17.                 next if $ext eq 'pm' && $text ~~ /^^\h*package\h+\w+\s*\;/;
  18.                 return ~$fn.realpath, $text;
  19.             }
  20.         }
  21.     }
  22.  
  23.     die "Unable to locate module $name in @path[]";
  24. }
  25.  
  26. method load_file($name) {
  27.     my $p = $name.IO;
  28.     (~$p.realpath, $p.slurp);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement