$client in tak repl
Matt S Trout [Tue, 15 Nov 2011 07:18:06 +0000 (07:18 +0000)]
Changes
lib/Tak/EvalService.pm
lib/Tak/Role/ScriptActions.pm

diff --git a/Changes b/Changes
index 640da79..26974f5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,4 @@
+  - Provide a $client in repl objects
   - Support for -l/--local in Tak::Script
 
 0.001001 - 2011-11-15
index 629beae..70b663d 100644 (file)
@@ -9,8 +9,15 @@ with 'Tak::Role::Service';
 
 has 'eval_withlexicals' => (is => 'lazy');
 
+has 'service_client' => (is => 'ro', predicate => 'has_service_client');
+
 sub _build_eval_withlexicals {
-  Eval::WithLexicals->new
+  my ($self) = @_;
+  Eval::WithLexicals->new(
+    $self->has_service_client
+      ? (lexicals => { '$client' => \($self->service_client) })
+      : ()
+  );
 }
 
 sub handle_eval {
index 9551b62..2d4a23a 100644 (file)
@@ -59,7 +59,10 @@ sub each_repl (I=s@;m=s@;M=s@) {
   my ($self, $remote, $options) = @_;
   require Tak::REPL;
   require B;
-  $remote->ensure(eval_service => 'Tak::EvalService');
+  $remote->ensure(
+    eval_service => 'Tak::EvalService',
+    expose => { service_client => [ '' ] },
+  );
   foreach my $lib (@{$options->{'I'}||[]}) {
     $remote->do(eval_service => eval => "lib->import(${\B::perlstring($lib)})");
   }