Skip to content

Commit

Permalink
Perlito5 - "do FILE" fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed May 12, 2015
1 parent 7addc1d commit 153ee95
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
26 changes: 22 additions & 4 deletions perlito5.pl

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src5/lib/Perlito5/Grammar/Use.pm
Expand Up @@ -303,6 +303,25 @@ sub require {
}
}

sub do_file {
my $filename = shift;
eval {
filename_lookup($filename);
1;
} or do {
$INC{$filename} = undef;
$@ = '';
$! = 'No such file or directory';
return 'undef';
};
my $realfilename = $INC{$filename};
open FILE, '<', $realfilename
or die "Cannot read $realfilename: $!\n";
local $/ = undef;
my $source = <FILE>;
close FILE;
return $source;
}

Perlito5::Grammar::Statement::add_statement( 'no' => \&stmt_use );
Perlito5::Grammar::Statement::add_statement( 'use' => \&stmt_use );
Expand Down
4 changes: 2 additions & 2 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -2150,8 +2150,8 @@ package Perlito5::AST::Apply;
namespace => '',
arguments => [
Perlito5::AST::Apply->new(
code => 'slurp',
namespace => 'Perlito5::IO',
code => 'do_file',
namespace => 'Perlito5::Grammar::Use',
arguments => $self->{arguments}
)
]
Expand Down
4 changes: 0 additions & 4 deletions src5/lib/Perlito5/Javascript2/IO.pm
Expand Up @@ -458,10 +458,6 @@ if (isNode) {
}
};
p5typeglob_set("Perlito5::IO", "slurp", function(List__) {
return fs.readFileSync(List__[0],"utf8");
});
} else {
// not running in node.js
p5typeglob_set("Perlito5::IO", "print", function (filehandle, List__, p5want) {
Expand Down
4 changes: 2 additions & 2 deletions src5/lib/Perlito5/Javascript3/Emitter.pm
Expand Up @@ -1656,8 +1656,8 @@ package Perlito5::AST::Apply;
namespace => '',
arguments => [
Perlito5::AST::Apply->new(
code => 'slurp',
namespace => 'Perlito5::IO',
code => 'do_file',
namespace => 'Perlito5::Grammar::Use',
arguments => $self->{arguments}
)
]
Expand Down
4 changes: 2 additions & 2 deletions src5/lib/Perlito5/XS/Emitter.pm
Expand Up @@ -494,8 +494,8 @@ package Perlito5::AST::Apply;
namespace => '',
arguments => [
Perlito5::AST::Apply->new(
code => 'slurp',
namespace => 'Perlito5::IO',
code => 'do_file',
namespace => 'Perlito5::Grammar::Use',
arguments => $self->{arguments}
)
]
Expand Down

0 comments on commit 153ee95

Please sign in to comment.