The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::redisp::EvalWithLexicals

VERSION

version 0.1

SYNOPSIS

  # file: bin/tinyrepl

  #!/usr/bin/env perl

  use strictures 1;
  use App::redisp::EvalWithLexicals;
  use Term::ReadLine;
  use Data::Dumper;

  $SIG{INT} = sub { warn "SIGINT\n" };

  { package Data::Dumper; no strict 'vars';
    $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
    $Quotekeys = 0;
  }

  my $eval = App::redisp::EvalWithLexicals->new;
  my $read = Term::ReadLine->new('Perl REPL');
  while (1) {
    my $line = $read->readline('re.pl$ ');
    exit unless defined $line;
    my @ret; eval {
      local $SIG{INT} = sub { die "Caught SIGINT" };
      @ret = $eval->eval($line); 1;
    } or @ret = ("Error!", $@);
    print Dumper @ret;
  }

  # shell session:

  $ perl -Ilib bin/tinyrepl 
  re.pl$ my $x = 0;
  0
  re.pl$ ++$x;
  1
  re.pl$ $x + 3;
  4
  re.pl$ ^D
  $

NAME

App::redisp::EvalWithLexicals - pure perl eval with persistent lexical variables

VERSION

version 0.1

METHODS

new

  my $eval = App::redisp::EvalWithLexicals->new(
    lexicals => { '$x' => \1 },      # default {}
    in_package => 'PackageToEvalIn', # default App::redisp::EvalWithLexicals::Scratchpad
    context => 'scalar',             # default 'list'
  );

eval

  my @return_value = $eval->eval($code_to_eval);

lexicals

  my $current_lexicals = $eval->lexicals;

  $eval->lexicals(\%new_lexicals);

in_package

  my $current_package = $eval->in_package;

  $eval->in_package($new_package);

context

  my $current_context = $eval->context;

  $eval->context($new_context); # 'list', 'scalar' or 'void'

AUTHOR

Matt S. Trout <mst@shadowcat.co.uk>

CONTRIBUTORS

None required yet. Maybe this module is perfect (hahahahaha ...).

COPYRIGHT

Copyright (c) 2010 the Eval::WithLexicals "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE

This library is free software and may be distributed under the same terms as perl itself.

AUTHOR

David Leadbeater <dgl@dgl.cx>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by David Leadbeater.

This is free software; you can redistribute it and/or modify it under the terms of the Beerware license.