I posted REPL In Perl With Reply on Thursday, 14 August, 2014

REPL In Perl With Reply
Post perl reply mojolicious

Part of the The Reply Perl REPL series.

REPL In Perl With Reply

Time for a quick post about Reply, a new Perl toy from Jesse Luers. There will not be much for me to say, because I have only been playing with it for about twenty minutes.

Note

This post used Questhub.io for a subject. Unfortunately, that site is no longer with us. Updating the content for an active site is on my TODO list.

Reply is a REPL for Perl. It is an interactive shell that simplifies quick experimentation with language features. It is extensible via a plugin system that I may look at later if I have more time.

Installation

I use perlbrew and cpanm, so installation was easy.

$ cpanm Reply

Oh. It is worth pointing out that if you do not have GNU Readline or a similar library installed, you will not get command-line editing or history in Reply.

Hello Reply

The reply command starts a new session. Once the session is going, it’s pretty much just Perl.

$ reply
0> "Hello World"
$res[0] = 'Hello World'

1> my $name = "Brian"
$res[1] = 'Brian'

2> "Hello $name"
$res[2] = 'Hello Brian'

Getting user input via STDIN works pretty much how you would expect.

3> chomp( $name = <STDIN> )
Brian
$res[3] = 1

4> $name
$res[4] = 'Brian'

Defining subroutines is no big deal.

5> sub greeting { "Hello $_[0]" }
6> greeting $name
$res[5] = 'Hello Brian'

And exit will quit Reply. It all seems straightforward.

7> exit
$

A Marginally More Complex Example

I have been working on a little experiment: fetching Questhub.io JSON with Mojo::UserAgent and Mojo::JSON. I decided to see if I could try some of that experiment in Reply.

0> use Mojo::UserAgent
1> use Mojo::JSON 'decode_json'
2> my $ua = Mojo::UserAgent->new
$res[0] = bless( {}, 'Mojo::UserAgent' )

3> sort map { $_->{name} } @{ decode_json( $ua->get( 'https://questhub.io/api/realm' )->res->body ) }
$res[1] = [
  'Big Data',
  'Chaos',
  'Code',
  'DC Metro Region',
  'Fitness',
  'Haskell',
  'Japanese',
  'Lisp',
  'MOOCs',
  'Meta',
  'Node.js',
  'Perl',
  'Portland',
  'Python (Ru)',
  'Read',
  'Testing',
  'Yoga + Meditation'
]

Yes, I can.

What Do I Think?

I like Reply overall. I am not used to thinking in REPL terms when it comes to Perl, and need to spend more than twenty minutes with it. I like Reply enough that I do expect to spend more time with it.

I noticed that my coding style was more terse within the confines of Reply. Maybe I should install GNU Readline support on my machine or enable the Editor plugin.

Social

Got a comment? A question? More of a comment than a question? Talk to me about this post!

Indieweb Social

Did you mention this somewhere? I'd love it if you sent me the link!

disclaimer about timing

Mentions are sent to webmention.io. I fetch the latest mentions when building the site, so I may not see your feedback right away. Especially if my site's broken, which is often the case.

Public replies and mentions might be shared on the site, but I try to do a little quality check first.

Site Links