primitive script running support
Matt S Trout [Sat, 5 Mar 2016 08:17:02 +0000 (08:17 +0000)]
bin/dx

diff --git a/bin/dx b/bin/dx
index d5a2107..cd65e0a 100644 (file)
--- 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