1 package Eval::WithLexicals;
5 our $VERSION = '1.001000'; # 1.1.0
6 $VERSION = eval $VERSION;
8 with 'Eval::WithLexicals::Role::Eval';
9 with 'Eval::WithLexicals::Role::PreludeEachTime';
13 Eval::WithLexicals - pure perl eval with persistent lexical variables
22 use Eval::WithLexicals;
26 $SIG{INT} = sub { warn "SIGINT\n" };
28 { package Data::Dumper; no strict 'vars';
29 $Terse = $Indent = $Useqq = $Deparse = $Sortkeys = 1;
33 my $eval = Eval::WithLexicals->new;
34 my $read = Term::ReadLine->new('Perl REPL');
36 my $line = $read->readline('re.pl$ ');
37 exit unless defined $line;
39 local $SIG{INT} = sub { die "Caught SIGINT" };
40 @ret = $eval->eval($line); 1;
41 } or @ret = ("Error!", $@);
47 $ perl -Ilib bin/tinyrepl
61 my $eval = Eval::WithLexicals->new(
62 lexicals => { '$x' => \1 }, # default {}
63 in_package => 'PackageToEvalIn', # default Eval::WithLexicals::Scratchpad
64 context => 'scalar', # default 'list'
65 prelude => 'use warnings', # default 'use strictures 1'
70 my @return_value = $eval->eval($code_to_eval);
74 my $current_lexicals = $eval->lexicals;
76 $eval->lexicals(\%new_lexicals);
80 my $current_package = $eval->in_package;
82 $eval->in_package($new_package);
86 my $current_context = $eval->context;
88 $eval->context($new_context); # 'list', 'scalar' or 'void'
92 Code to run before evaling code. Loads L<strictures> by default.
94 my $current_prelude = $eval->prelude;
96 $eval->prelude(q{use warnings}); # only warnings, not strict.
100 Matt S. Trout <mst@shadowcat.co.uk>
104 David Leadbeater <dgl@dgl.cx>
108 Copyright (c) 2010 the Eval::WithLexicals L</AUTHOR> and L</CONTRIBUTORS>
113 This library is free software and may be distributed under the same terms