From: Matt S Trout Date: Sat, 5 Mar 2016 08:17:02 +0000 (+0000) Subject: primitive script running support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e0644ad0eecb536c5236668c68565e0d1be93332;p=scpubgit%2FDX.git primitive script running support --- diff --git a/bin/dx b/bin/dx index d5a2107..cd65e0a 100644 --- a/bin/dx +++ b/bin/dx @@ -2,6 +2,15 @@ use strictures 2; use Module::Runtime qw(use_module); use DX::Utils qw(:builders); +{ package FakeReadline; + sub readline { + return undef unless defined(my $line = readline($_[0])); + print $_[1].$line; + return $line; + } + sub history_add {} +} + use_module('DX::ShellFrontend')->new( session_mode => 'shell', session => use_module('DX::ShellSession')->new( @@ -17,6 +26,13 @@ use_module('DX::ShellFrontend')->new( proposition_sequence => use_module('DX::PropositionSequence')->new_empty, ), - ) + ), + ), + (@ARGV + ? (readline => do { + open my $fh, '<', $ARGV[0] or die "Couldn't open script: $!"; + bless($fh, 'FakeReadline') + }) + : () ), )->repl