Day 16: Making tab completion setup seamless for users (App::shcompgen)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

I've created a couple of frameworks that make it easy for Perl developers to add tab completion feature to their scripts (and am planning to write another one). One is Perinci::CmdLine, which I recommend and use a lot more myself but requires you to immerse yourself with the concepts Rinci metadata, Riap URLs, and all that. Another is Getopt::Long::Complete which is more suitable to casual Perl programmers familiar with de-facto and builtin module for options parsing in Perl, Getopt::Long. Getopt::Long::Complete allows you to use Getopt::Long interface; you just need to add a subroutine to tell how to complete option values and arguments.

A Marpa-powered SQL-2003 parser

This blog entry is to announce MarpaX-Languages-SQL2003-AST, a Marpa::R2 SQL-2003 parser.

The SQL language is quite big, and consist of approximately ~2500 production rules, and almost as many terminal tokens.

Thanks to Ron's SQL page, the EBNF describing SQL was translated to Marpa::R2's Scanless BNF.

The most interesting things behind this exercice were:
  • Dealing with known (and native!) SQL grammar ambiguities
  • Do some semantic actions in the case when the parsing of a terminal depend on a terminal that is after
  • Provide something useful on the command-line
A note as prolog, one has to eliminate some usual pitfalls with SQL-2003. For instance, it requires a FROM after the SELECT , column names as well their eventual AS alias are not single-quoted, and so on.

Looking for new maintainer for Memcached::libmemcached

Howdy folks.

I offered to help Tim Bunce maintain Memcached::libmemcached earlier this year and managed to get a single release out with a few fixes.

I intended a second release to solve some compilation issues, but never got around it, and I'm not sure I ever will - there's still more work to do to there, and my time/interests have moved on.

I'm looking for someone to take over maintainership of this. Bug reports have been fairly minimal so far, most of it coming down to "Please update to latest upstream version" or "allow to link against system version instead of bundled version."

See https://github.com/timbunce/Memcached-libmemcached/issues for more about the above.

If this sounds of interest to you, please let me or Tim know - we'd love to have someone keep this going.

Thanks,

-- Matthew Horsfall (alh)

Announcing WebService::Vultr v0.1

Complete Perl bindings for the Vultr v1 API uploaded to CPAN.
The module is managed at: https://github.com/eskaaren/WebService-Vultr

Vultr is a global VPS provider similar to DigitalOcean and Amazon EC2.
http://www.vultr.com/?ref=6816711

(By signing up using that link and spending at least $10 I will get a one time kickback)

Day 15: Words on CPAN (App::wordlist)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

Some of you might already know that there are some wordlists on CPAN, under the Games::Word::Wordlist:: namespace. These lists can be used for, as the package name suggests, word games like Hangman or Word Search or Scrabble, but can also be used for other purposes, among others: cracking/bruteforce dictionary, password generation, feeding into search engine, or some linguistics tasks like word length/frequency analysis.

The wordlist CLI utility (from App-wordlist distribution) is a small script which I recently wrote to query the contents of the abovementioned modules.

What prevent warnings pragma become default feature?

What prevent warnings pragma become default feature by use VERSION?

In Perl 5.12, strict pragma become default feature by use VERSION .

  use v5.12; # enable strict pragma

Now many source code examples in web is written by the following way.

  use v5.x;
  use warnings;

If warnings is enabled by use VERSION, it is useful.

The Joy in What We Run

You may recall that my mentioning that my favorite talk at this year’s YAPC was Sawyer X’s “The Joy in What We Do”.  If you remember (or click one of these links I keep throwing at you), long about 26:28 Sawyer X makes a radical suggestion: if you want to release an application which uses Perl, maybe you shouldn’t be releasing it via CPAN.  I mean, CPAN is awesome for modules, and it’s not too shoddy for Perl apps either.  It makes it very easy to install for people who already have Perl, and know how to operate the CPAN shell, or cpanm, and either have root access on their machine or are already using perlbrew or plenv, and ...  In other words, other Perl programmers.  And, if that’s your audience, then lovely.  Although, even then ... what if you need a particular version of Perl, and particular versions of certain modules?  It’s all doable, certainly, and even moderately easy for Perl’ers of a certain experience level.  But why should we limit ourselves unnecessarily?

Of course you can `requires` attributes!

During the patch -p2 hackathon, two seasoned Perl programmers told me that "you can't requires attributes". This sounded weird to me, as attributes are exposed as methods and besides, I'm doing that all the time in my current work project.

Day 14: What $! The $? (Proc::ChildError)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

Finding out OS error message in Perl is pretty straightforward: just print out the $! variable. Example:

open my $fh, ">", "somefile" or die "Can't open file: $!";

The $! is pretty magical, it can return an integer (errno) or a string.

However, finding out child error message is not equally straightforward: there needs to be some bit-fiddling involved, which I always forget. To quote the perlvar manpage (or, perldoc -f system):

Test-Simple Release-Candidates

This is an update to the ongoing efforts to update Test-Builder. At this point the updates have been merged into blead, that means the new Test-Simple will be part of perl-5.22, barring any significant reasons to remove it. This post is to provide details you should probably know.

The changes have entered the release-candidate stage. The plan at the moment is to go stable if we have an entire blead-cycle without any significant changes needed. What constitutes a significant change? This is a grey area, obviously documentation, version number, and error message typo fixes are not significant. Logic changes on the other hand can be, at the moment I am relying on discussion with the toolchain-gang and the perl-qa group to make this call.

Pod::Readme can now be used with Dist::Zilla

I've recently released a new version of Pod::Readme with hooks to work with Dist::Zilla.

I also worked with Fayland 林 so that Dist::Zilla::Plugin::ReadmeFromPod will use Pod::Readme.

This means that you can use Pod::Readme's POD syntax in your module for generating README files. This includes the ability to:

  • Write POD sections in your module that are only shown in the README, such as the installation instructions, prerequisites, etc.;
  • Exclude other POD sections from the README, such as the details of functions and methods in your module;
  • Include the module's version, latest changes, or prerequisites in the README automatically;

You can also generate README files in alternative formats, such as POD, markdown or HTML.

The patch -p2 hackathon in Lyon is over

patch -p2 was held in Lyon, in the local Booking.com office, and organized by the French Perl Mongers.

It was the sixth hackathon the French Perl Mongers organized in three years (we're now on a steady "two hackathons a year" rythm), following the Perl QA Hackathon 2012, Quack and Hack Europe 2012, patch -p0, patch -p1, and the Perl QA Hackathon 2014.

Day 13: *PAN

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

What is XPAN you say? I wanted to write *PAN, but since that is not a valid module name (or perhaps it is? maybe there's some word character somewhere in the set which resembles an asterisk/star?) I settled with XPAN. The XPAN::Query explains it and I quote: "XPAN is a term I coined for any repository (directory tree, be it on a local filesystem or a remote network) that has structure like a CPAN mirror, specifically having a modules/02packages.details.txt.gz file. This includes a normal CPAN mirror, a MiniCPAN, or a DarkPAN. Currently it excludes BackPAN, because it does not have 02packages.details.txt.gz, only authors/id/C/CP/CPANID directories.

Using Role as Partial Classes

For Veure, my text MMORPG, I found myself worrying about the Character class turning into a god object. At over 2,300 lines, 105 methods, and growing, it was getting hard to keep track of everything. I want my code to be clean and easy to follow. As a result, when new behavior arose, I started thinking of other places to put behavior, and wound up with abominations like this:

if ( $missions->has_misssion_for( $character, $npc ) ) {
    ...
}

Use Ctrl-d!

Due to recent events, we now broadcast a public service announcement:

Stop typing "exit" or "logout" to quit your current shell session!

Thank you for your attention - we now return to our regular programming.

Test::Perl::Critic Is Now Wicked Fast

Test::Perl::Critic-1.02_002 has just hit CPAN. The new release uses MCE to run tests in parallel across multiple cores. So if you have an 8 core machine, you could see an 8x performance boost! If you are using the recommended all_critic_ok() function then no code changes are required -- just upgrade and fire away.

For the moment, this is just a developer release so you'll have to fetch it explicitly (using cpanm) as THALJEF/Test-Perl-Critic-1.02_002.tar.gz. MCE is very robust and it should behave well on all sorts of platforms and hardware. But I'd really appreciate if you give it a try and report any problems on GitHub.

Update: That should be version 1.02_002, not 1.02_001 as originally written.

Thanks. Enjoy!

Day 12: A fatpackable, SSL-aware HTTP::Tiny (but sadly, with a catch)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

Okay, this one is a silly proof-of-concept, and currently incomplete. But nevertheless might fit your need in some situation, like for testing.

It all began a few weeks ago when MELO posted this blog post about his attempt to produce a fatpacked version of a chat client. At the end he failed because HTTP::Tiny depends on IO::Socket::SSL and eventually Net::SSLeay which is an XS module and cannot be fatpacked. So I got this idea of having an HTTP::Tiny variant which uses a CLI network client like wget or curl. Sure, we're just trading one dependency to another, but on a typical Linux system on the deployment, chances are it'll probably have either one. So an experimental module HTTP::Tiny::CLI is born. I don't know if it's going to be useful for somebody, but nevertheless I had a bit of fun writing it, so there you go.

Gazelle - High performance PSGI Server

Gazelle is high performance PSGI Server, which have compatible with Sterlet by Auther kazeburo.


Gazelle(CPAN)
Gazelle(Qiita)
Gazelle(slide share)

Feature is:

  • Plack Handler / PSGI Server
  • HTTP/1.0 Web Server
  • Preforking Architecture
  • Sutable for running application servers befind a reverse proxy
  • Starlet compatible / hot deploy
  • Fast Fast Fast

Gazelle is very fast. Performance is as near fast as nginx(nginx is 1.2x) in slide share benchmark.

A small puzzle for you

This had me stumped for a bit, but I was quite pleased when I came up with a relatively simple solution.

Given several arrays, each of which has elements which are a subset of allowed elements, and given that every allowed element appears at least once in each array, how do I rewrite all arrays such that each element of each array which has an identical value to an element in another array has the same index number in each array, with missing elements being undef?

OK, that was a mouthful. Here's an example which should make it clear:

@a = ( 'b', 'c', 'f' );
@b = ( 'a', 'd' );
@c = ( 'c', 'd', 'e' );

I should have the following when I'm done:

@a = (  undef,    'b',    'c',  undef,  undef,    'f' );
@b = (    'a',  undef,  undef,    'd',  undef,  undef );
@c = (  undef,  undef,    'c',    'd',    'e',  undef );

In other words, I'm trying to line up all of those values (because they're going to an HTML table and my $client needed to see the missing values). Once you see the answer to the puzzle, it's actually not too hard.

Post your solutions below!

tmux musings

Inspired partially by Ingy's keynote at the Pittsburgh Perl Workshop where he showed his mastery of pair programming, sort of, I've been using tmux.

Some thoughts posted here...

http://openbedrock.blogspot.com/2014/12/using-tmux-and-lovin-it.html

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.