doy / reply Goto Github PK
View Code? Open in Web Editor NEWread, eval, print, loop, yay!
Home Page: http://metacpan.org/release/Reply
read, eval, print, loop, yay!
Home Page: http://metacpan.org/release/Reply
Hi,
Here is the complete report:
http://www.cpantesters.org/cpan/report/d5fd98c0-dfaa-11e2-998b-7c478de70d86
It looks like that either Package::Stash and B::Keywords should be actual requirements and not only in RuntimeRecommends, no?
Environment key '&foo' should start with @, %, or $ at /home/doy/perl5/perlbrew/perls/perl-5.18/lib/site_perl/5.18.0/Reply/Plugin/Defaults.pm line 61.
$ reply
0> ^C
$
It is not same as other REPLs, usually, when user press Ctrl-C, current input will be cancelled, but the REPL will not quit.
I don't know if it's just me, but when I try to specify some options to reply, Plugin::Defaults complains
> reply -I /path/to/myplugin/lib --cfg /path/to/myconfig.cfg
Can't open -l: No such file or directory at /path/tol/lib/perl5/Reply/Plugin/Defaults.pm line 40.
Can't open -I: No such file or directory at /path/to/lib/perl5/Reply/Plugin/Defaults.pm line 40.
Can't open --cfg: No such file or directory at /path/to/lib/perl5/Reply/Plugin/Defaults.pm line 40.
Use of uninitialized value $package in concatenation (.) or string at /path/tol/lib/perl5/Reply/Plugin/Defaults.pm line 58, <> line 1.
> syntax error at (eval 29) line 4, at EOF
BEGIN not safe after errors--compilation aborted at (eval 29) line 9, <> line 1.
>
Seems like Plugin::Defaults::read_line() is accessing <>, and in turn @argv. @argv is untouched (and has -I, --cfg in it) because Reply::new is calling getopt against @argv, and leaves @argv untouched, I think.
Running reply -e'my $foo = 42'
should enter the reply shell, and run the given code as the first evaluation. So I should end up looking at something like this:
$ reply -e'my $foo = 42'
0> my $foo = 42
$res[0] = 42
1> _
Similarly, running reply foo.pl
should load and run foo.pl; If foo.pl
contained just print "Hello World\n";
then I should end up with something like this:
$ reply foo.pl
0> require "foo.pl"
Hello World
$res[0] = 1
1> _
In other news: I've finally found a use case for <blink>
— that underscore is supposed to represent the cursor — and GitHub's implementation of Markdown strips it out. :-(
env:
Reply --version -> 0.38
Perl -v -> v5.22.1
test:
my $squared_results = map { $_**2 } 1..5
expected:
$res[1] = [
1,
4,
9,
16,
25
]
got:
$res[8] = [
'1',
'4',
9,
'16',
25
]
It is hardwired to 'Reply' at the moment.
Also, is it possible for Reply to support options for IN and OUT handles? I'm trying to implement a standard command interface that could be used by a GUI "front end" by communicating via the IN/OUT handles.
I'm also looking at syntax highlighting for a CLI especially for tab completion where the various possibilities might come from different plugin sources.
In floating point math, there is a representation for a negative zero. In both re.pl
and reply
, a negative zero value is incorrectly printed as '0'
. Observe the first 5 expressions here:
$ reply
0> log(1)
$res[0] = '0' ← Weird to see it quoted as a string, but not wrong.
1> - log(1)
$res[1] = '0' ← Wrong!
2> my $x = -log(1)
$res[2] = '0'
3> $x
$res[3] = '0' ← Wrong!
4> print $x
0$res[4] = 1 ← Wrong! print also incorrectly prints it as zero.
5> sprintf("%f", $x)
$res[5] = '-0.000000' ← See? $x was negative zero.
6> $x < 0
$res[6] = ''
7> $x > 0
$res[7] = ''
8> $x == 0
$res[8] = 1
9> $x eq '0'
$res[9] = 1 ← Huh, wat?
10> $x eq '-0'
$res[10] = '' ← Wat‽
System:
Further references:
Some plugins require modules that are not listed in the prereqs for Reply. If these plugins are enabled in the config file, and these optional modules aren't installed, reply dies. The user winds up going through several rounds of die, install missing module, die, ... It would be better for the user if on startup, they could see a list of all warnings, and install everything in one go. The two common problems to guard against are adding a plugin in the config that isn't installed yet (possible typo or user adds plugin not realizing it's not a builtin), and using a builtin which has undeclared dependencies.
Say I have the following code:
my $factor = 2;
sub mult_by_factor {
$factor * shift;
}
say mult_by_factor(21);
This works when used in a regular Perl script, but not at the REPL. I know it might not be the best practice, but it can come in handy when testing things out.
There is are work arounds:
my $factor = 2;
*mult_by_factor = sub {
$factor * shift;
};
say mult_by_factor(21);
or
our $factor = 2;
sub mult_by_factor {
$factor * shift;
}
say mult_by_factor(21);
This might be worth documenting at least.
I found two problems with the support for Term::ReadLine::Perl in the Reply::Plugin::ReadLine:
I see there is now a Term::ReadLine::Perl5 module which is the one that is actually supported. I'll install and test that. It should be specified as a requirement since for non-gnu-readline platforms, it may be the only Term::ReadLine engine supported.
(I commented in #48 about this, but I'm guessing you didn't see it because the ticket was closed at that point.)
The pod example shows shows the history_file
option can take a quoted path, but that is actually not the case.
This works: history_file = ~/.reply_history
This doesn't: history_file = '~/.reply_history'
.
If you use $history = glob($history)
instead of $history =~ s{^~/}{$ENV{HOME}/}
it will properly deal with the quotes, though it might be better dealing with them at the config reader level.
The history_file option for Plugin::ReadLine should expand a leading '' to allow users to specify the file at the top-level of their home directory. Example: history_file = '/.reply_history'
Was asked about this by a colleague,
would there be a decent way to enable multiline support,
like [ReadTilSemicolon] or something. Then you could do:
my $a = {
c => 'd'
};
On Reply 0.34, Perl 5.18.2, default .replyrc
, lexical variables within blocks escape their scope:
0> { my $x = 3 };
$res[0] = 3
1> $x
$res[1] = 3
It doesn't seem to matter how deep I try to bury them:
0> for (0) { for (0) { my $sksk = 3 } }
$res[0] = ''
1> $sksk
$res[1] = 3
Lexical persistence is on via the LexicalPersistence plugin, but I assumed it would only apply to variables outside of blocks. Bad assumption?
I tried to use a bare heredoc in the repl session and something amazing happened:
1> my $x = <<
Use of bare << to mean <<"" is deprecated at reply input line 1.
Use of uninitialized value $^WARNING_BITS in concatenation (.) or string at reply input line 1.
$res[0] = ';
BEGIN {
201330658 = 256;
HASH(0xd2fe70) = %^H;
UUUUUUUUUUUUUUUUU� = ;
}
'
Hi doy! Thanks a lot for Reply - it's really cool :)
I was wondering if there is a way to see a list of all the variables currently available in the REPL. Specifically, I mean the ones created via my/our/state by the user.
Right now the only way I know how to do it is by either peeking at the history or having tab completion on and doing $a[tab], $b[tab] etc, but it does expand to other stuff as well.
For example:
> my $foo = 42
> my @meep = qw( some values )
> my $schema = My::Schema->connect( "..." );
> #vars
$foo
@meep
$schema
Ideally, it would show values as well, but it doesn't have to be that fancy (specially since values can be huge, and the user can just type "@meep" anyway after "#vars" to see its content anyway)
Would this fit into your vision for Reply?
$ perl -mfeature=say -mReply -e 'Reply->new()->run;'
say "hello"
String found where operator expected at reply input line 1, near "#line 1 "reply input"
say "hello""
(Missing operator before "hello"?)
syntax error at reply input line 1, near "#line 1 "reply input"
say "hello""
$ cpanm Reply
--> Working on Reply
Fetching http://www.cpan.org/authors/id/D/DO/DOY/Reply-0.17.tar.gz ... OK
Configuring Reply-0.17 ... OK
Building and testing Reply-0.17 ... OK
Successfully installed Reply-0.17 (upgraded from 0.01)
1 distribution installed
$ reply
Can't use an undefined value as a HASH reference at /Users/sartak/.perl/perls/perl-5.18.0/lib/site_perl/5.18.0/Reply/Plugin/Defaults.pm line 57.
Can't use an undefined value as a HASH reference at /Users/sartak/.perl/perls/perl-5.18.0/lib/site_perl/5.18.0/Reply/Plugin/Defaults.pm line 57.
Can't use an undefined value as a HASH reference at /Users/sartak/.perl/perls/perl-5.18.0/lib/site_perl/5.18.0/Reply/Plugin/Defaults.pm line 57.
0>
META lists Devel::LexAlias as a dependency, but the module is nowhere used in the code. Git history shows it used to be loaded from lib/Reply/Plugin/Defaults.pm.
Hi,
I have written a plugin and would like it to be published. Here is a short description:
NAME
Reply::Plugin::ConfigPrompt - provides a prompt that can be configured
in the config file
VERSION
version 0.01
SYNOPSIS
; .replyrc
[ConfigPrompt]
format = fixed_string %T %d %p %c >
color = bright_green
DESCRIPTION
This plugin enhances the default Reply prompt. It allows for the prompt
to display in a chosen color using the "color" option. It also
allows user to test a prompt format before using it for his application.
AUTHOR
Balaji Ramasubramanian <[email protected]>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2016 by Balaji Ramasubramanian.
This is free software, licensed under:
The MIT (X11) License
If you give me permission to contribute, I would be happy to add my code to a branch on your repository. Then you can pull it, review it and integrate it in the next release.
Thanks,
Balaji
We should provide print_result
and print_error
to plugins, and they should use that rather than just calling print
themselves.
Mark@travis:/tmp$ reply
> 1
Use of uninitialized value $package in concatenation (.) or string at /opt/markperl/lib/site_perl/5.22.0/Reply/Plugin/Defaults.pm line 55, <STDIN> line 1.
syntax error at (eval 25) line 4, at EOF
BEGIN not safe after errors--compilation aborted at (eval 25) line 9, <STDIN> line 1.
> ^D
Mark@travis:/tmp$ perl -v
This is perl 5, version 22, subversion 0 (v5.22.0) built for darwin-2level
Copyright 1987-2015, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Mark@travis:/tmp$ perl -e 'use Reply; print $Reply::VERSION'
0.37
Mark@travis:/tmp$ ~/perl5/perlbrew/perls/perl-5.18.2/bin/reply
> 1
Use of uninitialized value $package in concatenation (.) or string at /Users/Mark/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Reply/Plugin/Defaults.pm line 55, <STDIN> line 1.
syntax error at (eval 28) line 4, at EOF
BEGIN not safe after errors--compilation aborted at (eval 28) line 9, <STDIN> line 1.
Mark@travis:/tmp$ ~/perl5/perlbrew/perls/perl-5.18.2/bin/perl -e 'use Reply; print $Reply::VERSION'
0.37
hi!
Is it possible to overcome this behavior?
~$ reply
0> my $v = 0;
$res[0] = 0
1> my $inc = sub { ++$v }
$res[1] = sub { "DUMMY" }
2> $inc->()
$res[2] = 1
3> $v
$res[3] = 1
4> $v = 0
$res[4] = 0
5> $inc->()
$res[5] = 2
6> $v
$res[6] = 0
Really should have one of these...
For organization, I install my local modules into an INSTALL_BASE location with the appropriate PERL5LIB environment variable set. Just noticed that any package in that location was not present in the all_packages() and hence the completion for 'use XXX'
This was true for Strawberry Perl Portable 5.19.11.4 and cygwin64 perl 5.14.4
similar to Devel::REPL::Plugin::MultiLine::PPI
Reply::Plugin::CollapseStack requires Carp::Always, but it's only recommended.
I'm working on some PDL development using Moo
for its support of modern OO features and because
it is compatible with full Moose if needed.
In addition, I plan to move the pdl2 interactive shell
implementation from one based on Devel::REPL to
one built with Reply due to its improved startup
file support (more sh-ish!) and the simplicity.
In trying to minimize code duplication, I was wondering
what the design goals were for a more hand-rolled
OO implementation (classic perl5) versus using Moo.
I was thinking to try refactoring Reply to use Moo and
was wondering if you see any benefits or problems
with that?
Thanks,
Chris
A plugin to page long results would be useful.
Devel::REPL uses IO::Pager to do this.
Even if reply shell is terminated by Ctrl+C, I feel the history should be outputted.
I wrote a silly patch, but I think this is not good way...
moznion@c18e870
Do you have any ideas?
I notice ~/.replyrc
is a dos ini file and if user want to customize something, they should create a perl plugin and enable it in ~/.replyrc
It looks like weird. Why not use perl directly as config language? Like ptpython or ipython which are python REPLs using ~/.config/ptpython/config.py
and ~/.ipython/profile_default/ipython_config.py
as their config files. Even if cpython also allow user use $PYTHONSTARTUP
( a python file ) to config its REPL.
Just an advice for discussion. Thanks!
This should include having a print_warnings
method, once #14 is in place.
Hi
Reply shows broken ANSI codes on Windows console.
Please support ANSI color on Windows colsole with https://metacpan.org/release/Win32-Console-ANSI
Thanks.
Is it possible that reply provides tab completions for bash/zsh/fish/etc? TIA!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.