Rakudobrew
Brian Wisti (@brianwisti)
june 2nd, 2015
Perl 6 will be ready for production in 2015, according to Perl creator Larry Wall. At least, that’s what he said during his FOSDEM 2015 talk. This news reminded me that it has been quite a while since I tried anything interesting with Perl 6. I decided to spend my weekend installing and playing with Rakudo, the primary Perl 6 implementation.
If all you want to do is play with the language, then grabbing the latest available Rakudo Star bundle is all you need. It includes Task::Star, a collection of modules which are generally useful. You can even run the sample code at the end of this post with Rakudo Star, in case you’re in a TL;DR kind of mood.
I prefer to stay current with development and explore different backends which may not be available in the Rakudo Star release. Juggling those installations can be a challenge. Rakudobrew helps with that exact situation.
Enter Rakudobrew
Rakudobrew is a “quick and dirty” command line tool for managing Rakudo installations. It can fetch the latest code from GitHub, build against your choice of backends, and simplify version upgrades. It is suited for the same sort of folks that use tools like Perlbrew or RVM. Rakudobrew behaves like those except—as with all things Perl 6—a little rough around the edges.
Setup
Setting up Rakudobrew and its requirements did not take much time.
Requirements
Rakudobrew assumes a UNIX-like system, so it probably won’t work on Windows. OS X users should use a packaging system such as MacPorts or Homebrew to install dependencies. The basic dependencies you’ll need are:
- Git, which is available in the
git
package on Ubuntu, and comes with the OS X Command Line Tools. - Perl 5 (5.10 or greater), which is already available on most UNIX-like systems.
You will also need the requirements for Rakudo itself. The Rakudo INSTALL.txt details those requirements. There are currently three backends: Parrot, Moar, and the Java JVM. There will be additional requirements depending on which backends and features you want to use.
- A C compiler
make
- Optional
- GNU readline development libraries for command history and editing
- JDK 1.7 or greater to build the JVM backend
- ICU library for Unicode support on Parrot backend.
The compiler and make
generally come with the base development
package for your platform: build-essential
on Ubuntu, or Xcode on OS
X. Installation of readline depends on what packaging system you are
using.
# Ubuntu
$ sudo apt-get install git build-essential libreadline-dev
# OS X Macports (with Xcode and Command Line Tools already installed)
$ sudo port install readline
# OS X Homebrew (with Xcode and Command Line Tools already installed)
$ brew install readline
$ brew link readline
The dependencies were the most confusing part. Installation of Rakudobrew itself is much easier.
$ git clone https://github.com/tadzik/rakudobrew ~/.rakudobrew
$ export PATH=~/.rakudobrew/bin:$PATH
It wouldn’t hurt to put export PATH=~/.rakudobrew/bin:$PATH
into
~/.bash_profile
, or whatever your shell uses for initialization, so
that the rakudobrew
executable is available in new login shells.
Usage
rakudobrew help
will give you a list of available commands.
$ rakudobrew help
rakudobrew current
rakudobrew list
rakudobrew list-available
rakudobrew build jvm|moar|all [tag|branch|sha-1] [--configure-opts=]
rakudobrew build-panda
rakudobrew triple [rakudo-ver [nqp-ver [moar-ver]]]
rakudobrew rehash
rakudobrew switch jvm|moar
rakudobrew nuke jvm|moar
rakudobrew self-upgrade
rakudobrew test [jvm|moar|all]
build
The build
command will grab code from the Rakudo repository and
compile it for you with reasonable defaults. These defaults are based
on the backend you choose.
$ rakudobrew build moar
rakudobrew
will install from the repository HEAD
unless you
specify a version. You may want to build a specific
release of Rakudo. This could
be useful if you have Rakudo installed on multiple machines and you
want them to match each other’s behavior.
$ rakudobrew build moar 2015.05
$ rakudobrew build jvm
Yes. All this building takes a while. Do not feel obligated to build
every backend and version that I do. moar
should suffice for
language exploration.
list
Use the list
command to summarize all of the Rakudo installations
that Rakudobrew has installed.
$ rakudobrew list
* moar-nom
jvm-nom
moar-2015.05
The currently active installation gets tagged with an asterisk.
switch
Use switch
to change the active Rakudo installation from among those
that you have installed.
$ perl6 --version
This is perl6 version 2015.05-80-g2cc3afe built on MoarVM version 2015.05
$ rakudobrew switch jvm-nom
Switching to jvm
Updating shims
$ rakudobrew current
Currently running jvm-nom
$ perl6 --version
This is perl6 version 2015.05-80-g2cc3afe built on JVM
build-panda
Once you have a Rakudo implementation installed, you can install Panda. Panda is a Perl 6 module manager.
$ rakudobrew build-panda
You installed Panda. Might as well install some modules. How about Task::Star? That adds the packages bundled with Rakudo Star, giving you roughly the normal “batteries included” experience available to normal people downloading the latest installer.
$ panda install Task::Star
I noticed a couple of problem areas when using Panda and Rakudobrew together.
- I needed to run
build-panda
on each of my installations. Otherwisepanda
complains about missing dependencies. panda
was unable to install every Task::Star module for every backend. Part of this is due to differences between JVM and Moar backends, and part of this is due to Task::Star modules relying on Perl 6 language features being deprecated for an eventual release of Perl 6 release candidate. Perl 6 is still an exercise for the bold and / or patient. Those with both traits in abundance canpanda install
each of the modules listed in the Task::Star META.infp.
rehash
The Task::Star install included the command line tool
p6doc
, but that won’t be available
on your $PATH
until you give the command. rehash
looks for new
executables in your current Rakudo installation, and creates shims nfor
them in the Rakudobrew bin
path.
$ rakudobrew rehash
$ p6doc Template::Mojo
Be aware that p6doc
and Perl 6 documentation in general is not the
seemingly infinite resource that perldoc
is in Perl 5. Your best
bets for now are the
Perl 6 documentation and pages.
You Mentioned Perl 6
You probably want to see some real Perl 6 code that shows off what the language and platform can really do.
Oh I’m sorry. We’re just about out of time.
Okay, fine. Let me look at the
modules available for Rakudo. How about
we use LWP::Simple and
JSON::Tiny to fetch the
leaderboard
of ++
recipient Perl 5 distributions according to the
MetaCPAN API?
This should work with Rakudo Star as well, since both of those modules
are included in Task::Star.
use v6;
use JSON::Tiny;
use LWP::Simple;
my $limit = 5;
my $host = "http://api.metacpan.org/v0/favorite/_search";
my $headers = {
Accept => 'application/json',
Content-Type => 'application/json',
};
my $query = {
query => {
match_all => {},
},
facets => {
leaderboard => {
terms => {
field => "distribution",
size => $limit,
}
}
},
size => 0,
};
my $json-query = to-json($query);
say "Listing top $limit distributions from MetaCPAN";
my $json-result = LWP::Simple.post($host, $headers, $json-query);
my $result = from-json($json-result);
my @terms = $result<facets><leaderboard><terms>.list;
for @terms -> $term {
say "$term<count>\t$term<term>";
}
Now we have some functioning code. What does it produce?
$ perl6 top-distros.pl
Listing top 5 distributions from MetaCPAN
268 Mojolicious
250 perl
233 Moose
174 DBIx-Class
92 App-cpanminus
Note: Had some confusing results with the version first published, but @miyagawa on Twitter pointed out that I was using the wrong endpoint. Mojolicious is the module with the most favorites, which makes sense. It’s an excellent framework.
Wrapping Up
So, my “Perl 6 weekend” ended up stretching into Wednesday because I had forgotten quite a bit of syntax. I can’t say whether Perl 6 will be ready for production in 2015, but with Rakudobrew I can easily update when it is announced.
To learn more about Perl 6, look over the reference material and tutorials linked from the Perl 6 documentation. For community news, the P6 Weekly blog summarizes recent activity in the Perl 6 community.
Tags: technology perl