App-AnteREPL
view release on metacpan or search on metacpan
"requires" : {
"Dist::Zilla" : "6",
"Dist::Zilla::Plugin::Metadata" : "0"
}
},
"runtime" : {
"recommends" : {
"Term::ReadKey" : "0"
},
"requires" : {
"Data::Dumper" : "0",
"Devel::Peek" : "0",
"Encode" : "0",
"File::Basename" : "0",
"File::Spec" : "0",
"File::Temp" : "0",
"POSIX" : "0",
"Text::Balanced" : "0",
"Text::ParseWords" : "0",
"Time::HiRes" : "0",
"feature" : "0",
namespace:
- App::AnteREPL::Workspace
package:
- App::AnteREPL::Evaluator
- App::AnteREPL::Screen
- App::AnteREPL::ScreenInput
- App::AnteREPL::ScreenOutput
recommends:
Term::ReadKey: '0'
requires:
Data::Dumper: '0'
Devel::Peek: '0'
Encode: '0'
File::Basename: '0'
File::Spec: '0'
File::Temp: '0'
POSIX: '0'
Text::Balanced: '0'
Text::ParseWords: '0'
Time::HiRes: '0'
feature: '0'
Makefile.PL view on Meta::CPAN
use 5.016;
use strict;
use warnings;
use ExtUtils::MakeMaker 6.64;
my %prereqs = map { $_ => 0 } qw(
Data::Dumper Devel::Peek Encode File::Basename File::Spec File::Temp
POSIX Text::Balanced Text::ParseWords Time::HiRes strict warnings feature
);
$prereqs{'Term::ReadKey'} = 0 if $^O eq 'MSWin32';
WriteMakefile(
NAME => 'App::AnteREPL',
VERSION_FROM => 'lib/App/AnteREPL.pm',
ABSTRACT_FROM => 'lib/App/AnteREPL.pm',
AUTHOR => 'Brett Estrade',
LICENSE => 'perl_5',
lib/App/AnteREPL.pm view on Meta::CPAN
use 5.016;
use strict;
use warnings;
package App::AnteREPL;
use Data::Dumper ();
use Encode qw(decode encode FB_CROAK);
use File::Basename qw(dirname);
use File::Spec ();
use File::Temp ();
use Text::Balanced qw(extract_quotelike);
use Text::ParseWords qw(shellwords);
use App::AnteREPL::Shorthand ();
our $VERSION = '0.01';
our $PROGRAM_VERSION = '0.1';
lib/App/AnteREPL.pm view on Meta::CPAN
sub run {
my ($self) = @_;
return $self->evaluate($self->source, 1);
}
sub inspect_value {
my ($self, $command, $expression) = @_;
die "$command needs a Perl expression.\n" unless $expression =~ /\S/;
if ($command eq 'DUMP') {
local $Data::Dumper::Sortkeys = 1;
print $self->evaluate("Data::Dumper::Dumper(do { $expression\n })", 0);
return;
}
require Devel::Peek;
require POSIX;
# Devel::Peek writes to the native stderr descriptor, bypassing tied Perl
# handles. Redirect that descriptor temporarily so its output joins VRAM.
my $temporary = File::Temp->new(UNLINK => 1);
my $saved = POSIX::dup(2);
die "Cannot preserve stderr: $!\n" unless defined $saved && $saved >= 0;
unless (defined POSIX::dup2(fileno($temporary), 2)) {
lib/App/AnteREPL.pm view on Meta::CPAN
EVAL leaves AUTO on. AUTO OFF resumes ordinary input.
EVAL do { ... } groups multiline code without storing.
Lowercase eval keeps Perl's normal eval semantics.
EVAL sub name { ... } Define a session function without storing source.
Immediate code and RUN can call it. SAVE excludes it.
Redefining warns by default and replaces the function.
FUNCTIONS List defined names in this workspace, alphabetically.
Includes imports; excludes other packages and stubs.
Works during AUTO; does not execute or store source.
? expression Evaluate in scalar context and display the result.
DUMP expression Data::Dumper output: DUMP $FOO or DUMP \%ENV.
PEEK expression Devel::Peek internals: PEEK $FOO or PEEK $FOO, 10.
Use $x = 1 or our $x for persistent values; my is local to one evaluation.
say/print display output. RUN shares package variables with immediate input.
Stored subroutines become callable after RUN; LOAD/LIST do not define them.
Open quotes, braces, brackets, or parentheses continue on the next row.
A closed subroutine definition, including ($) or (@), submits with Enter.
Ctrl-C cancels unfinished input; commands inside it are still Perl text.
A complete multiline AUTO entry preserves literal source: supply its final ;.
Numbered and AUTO colon entries stay literal, one physical line at a time.
lib/App/AnteREPL.pm view on Meta::CPAN
my ($number, $code) = ($1, $2);
$self->set_line($number, _typed_source($code));
return 1;
}
if ($line =~ /\A\s*(DUMP|PEEK)\b\s*(.*)\z/s) {
$self->inspect_value($1, $2);
return 1;
}
if ($line =~ /\A\s*\?\s*(.*)\z/s) {
my $value = $self->evaluate($1, 0);
print Data::Dumper->new([$value])->Terse(1)->Indent(1)->Sortkeys(1)->Dump;
return 1;
}
if ($line =~ /\A\s*(!{1,2})\s*(\S.*)\z/) {
my ($escape, $command) = ($1, $2);
my @command = $^O eq 'MSWin32' ? ($ENV{COMSPEC} || 'cmd.exe', '/c', $command) : ('/bin/sh', '-c', $command);
my $status = $self->{screen}
? ($escape eq '!!' ? $self->{screen}->external(sub { system @command }, 1) : $self->{screen}->shell(\@command))
: system @command;
die "Cannot start shell: $!\n" if $status == -1;
die "Shell command failed (status $status).\n" if $status;
lib/App/AnteREPL.pm view on Meta::CPAN
buffer; RUN reports errors. This avoids executing BEGIN blocks merely by
editing. Temporary editor files are removed when EDIT finishes.
=head1 WORKSPACE
Immediate input and RUN share a Perl package. C<$x = 1> and C<our $x = 1> persist
between evaluations, along with package arrays, hashes, and subroutines.
C<my> variables are local to one immediate evaluation or one complete RUN.
Pragmas and lexical imports must be repeated in each evaluation that needs
them; C<say> is enabled by default. Evaluation uses scalar context. Use
C<? expression> for Data::Dumper output; ordinary input does not automatically
print its return value. C<EVAL code> bypasses command and line-number parsing.
EVAL must be uppercase; lowercase C<eval> retains Perl's string/block evaluation
and exception-catching behavior. All REPL commands and subcommands must also
be uppercase.
RESET switches to a fresh workspace but keeps the source program. NEW/CLEAR
clear the source but retain the workspace. RUN does not reset variables first.
An exception does not roll back side effects. This runs ordinary Perl with
your account's privileges; C<exit> exits the tool. UNDO affects only stored
source, not executed Perl, shell commands, or saved files.
lib/App/AnteREPL.pm view on Meta::CPAN
For immediate Perl, Enter continues on the next screen row while a brace,
bracket, parenthesis, or quoted literal remains open. Once closed, Enter
submits the whole entry. Earlier multiline entries remain grouped when edited
and resubmitted. Bracketed multiline paste waits for Enter before evaluating.
No extra continuation prompt is printed, and input is never compiled merely
to decide whether it needs another row. This is delimiter continuation, not a
complete Perl parser; use EDIT or literal numbered lines for heredocs/POD and
complex source. Numbered program lines retain their existing single-line rules.
DUMP expression is a prompt command backed by Data::Dumper::Dumper:
$FOO = {
bar => 1,
names => [qw(Alice Bob)],
};
DUMP $FOO
DUMP \%ENV
PEEK expression calls the core Devel::Peek::Dump directly on the expression,
including an optional limit, e.g. C<PEEK $FOO> or C<PEEK $FOO, 10>. Its native
package TestScreen;
our @ISA = ('App::AnteREPL::Screen');
sub key { shift @{ $_[0]{keys} } || 'EOF' }
sub feed { my ($self, @keys) = @_; $self->{keys} = \@keys; return $self->read_entry; }
}
sub typing { map { ['TEXT', $_] } split //, $_[0] }
my $repl = App::AnteREPL->new;
$repl->dispatch('$FOO={bar=>1};');
my $dump = capture { $repl->dispatch('DUMP $FOO') };
like $dump, qr/\$VAR1 = \{/, 'dump uses Data::Dumper output';
like $dump, qr/'bar' => 1/, 'dump sees current workspace';
{
local %ENV = (PERL_ANTE_REPL_TEST => 'visible');
like capture { $repl->dispatch('DUMP \%ENV') }, qr/'PERL_ANTE_REPL_TEST' => 'visible'/, 'dump accepts an environment reference';
}
like capture { $repl->dispatch('DUMP [1, 2];') }, qr/1,\s+2/s, 'dump accepts expressions, optional semicolon';
my $peek = capture { $repl->dispatch('PEEK $FOO') };
like $peek, qr/SV = /, 'peek uses Devel::Peek';
like $peek, qr/FLAGS = \(ROK\)/, 'peek sees a reference scalar';
like $peek, qr/PVHV/, 'peek follows the hash reference';
( run in 0.772 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )