Author: jhorwitz
Date: Wed Jul 30 12:31:00 2008
New Revision: 29882

Modified:
   trunk/languages/perl6/src/builtins/guts.pir
   trunk/languages/perl6/src/builtins/io.pir

Log:
[rakudo] 'require' should check paths in PERL6LIB


Modified: trunk/languages/perl6/src/builtins/guts.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/guts.pir (original)
+++ trunk/languages/perl6/src/builtins/guts.pir Wed Jul 30 12:31:00 2008
@@ -433,6 +433,34 @@
 .end
 
 
+=item !find_file_in_path(path, filename)
+
+Searches a standard colon-separated path for a filename.
+
+=cut
+
+.sub '!find_file_in_path'
+    .param string search_path
+    .param string filename
+    .local string path
+    .local pmc iter
+
+    $P0 = split ':', search_path
+    iter = new 'Iterator', $P0
+  iter_start:
+    null path
+    unless iter goto return_path
+    $S0 = shift iter
+    path = concat $S0, '/'
+    path .= filename
+    $I0 = stat path, 0
+    unless $I0 goto iter_start
+
+  return_path:
+    .return(path)
+.end
+
+
 =back
 
 =cut

Modified: trunk/languages/perl6/src/builtins/io.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/io.pir   (original)
+++ trunk/languages/perl6/src/builtins/io.pir   Wed Jul 30 12:31:00 2008
@@ -88,10 +88,21 @@
 
 .sub 'require'
     .param pmc filename
+    .local string path
 
+    $S0 = substr filename, 0, 1
+    if $S0 == '/' goto eval_file
+
+    .local pmc env
+    .local string perl6lib
+    env = new 'Env'
+    perl6lib = env['PERL6LIB']
+    path = '!find_file_in_path'(perl6lib, filename)
+
+  eval_file:
     .local pmc p6compiler
     p6compiler = compreg 'Perl6'
-    p6compiler.'evalfiles'(filename)
+    p6compiler.'evalfiles'(path)
 .end
 
 .sub 'open'

Reply via email to