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.

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.

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!

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.

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

Catalyst Advent 2014

http://www.catalystframework.org/calendar/2014

I don't have articles to cover 25 days and could use a hand! I can commit to doing articles on each new feature and a review of the current development branch "Holland". That's about 10 articles. The rest I could really use some contrib.

Thanks!

jnap

I want Package BLOCK syntax return 1.

I want Package BLOCK syntax return 1.

package Point {
  # foo
}

I want This is interpreted as the following.

{
  package Point;

  # foo

  1;
}

In current Perl, module need to return 1 at the end of script. But this is a little strange specification. If package BLOCK syntax return 1;, we don't need to write 1; at the end of module.

Is this difficult?

Day 11: Tab-completion galore (App::{PM,Pl,Prog,Dzil,Git}Utils)

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

Ever since I got interested in doing shell tab completion with Perl, I've been trying to add tab completion to various programs or, in some cases, (re)creating utilities with tab completion capability. Granted, many of the utilities mentioned here are pretty trivial, but that's okay since tab completion is the main point. Here are some of them:

First of all, if you want to try these utilities out and you use bash, you might want to install and setup bash-completion-prog first. Just do a cpanm App::BashCompletionProg and put . ~/.bash-completion-prog in your ~/.bashrc. After that, installing the other utilities cpanm -n App::PMUtils App::PlUtils App::ProgUtils App::GitUtils App::DzilUtils will automatically add completion entries to ~/.bash-completion-prog so the next shell you start will automatically enable tab completion for all the included utilities.

Testing HTTP client code with Plack

I've been using Perl for a while now, and while much of my day job has revolved around legacy Perl, continuous development and refactoring has helped to introduce more and more modern Perl into my daily work. It was one of my more recent adventures that led me to write this, my first Perl blog post.

I'd been working on a small Plack-based application which grabs image files over HTTP for processing. To make testing easier, I'd written the class so that I could inject the HTTP client as a dependency (the default is HTTP::Tiny). But I then wondered if rather than creating a mock HTTP client for testing, it would be simpler and more effective to fire up a simple HTTP server instead. I thought I'd share my solution here because I've been so impressed with all the modules that made it (and the project as a whole) possible.

Next stable DBD::SQLite to be released in mid-December

DBD::SQLite 1.45_05 is a release candidate of the next stable DBD::SQLite. I usually wait one month for users to test, but as it includes an important security fix for PerlData virtual table, I'll release it a bit earlier than usual, in mid-December, hopefully on 10th (if there's no blocker nor request to wait). Please test it with your modules/applications and let me know if you find anything. I also strongly encourage you to upgrade DBD::SQLite to this release candidate immediately if you're using PerlData virtual table.

Other notable changes since the last stable release follow:

  • Performance enhancements introduced in SQLite 3.8.7.
  • Improved 64bit integer handling under 32bit environments.

Can you send 24 pull requests this December?

For many of us, the holiday season is approaching. The Advent calendars will be kicking off soon, which is great. If you're into blogging, I'm sure there are some calendars which may still be looking for articles. However, if you're looking to push some code, let me point out 24pullrequests.com The idea is that you send one pull request per day for 24 days.

There are two ways for you to contribute. You can sign up and start pushing code or you can suggest a project for others to create pull requests for. http://24pullrequests.com/projects/new Hey, you can probably do both. There's no commitment once you start. It's just a fun leaderboard to let you track your progress in the 24 days leading up to Christmas.

Day 10: Finding module's path and more (Module::Path::More)

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

NEILB's Module::Path is a handy little module (that comes with a handy little utility mpath to find the filesystem path to a locally installed module. It works by iterating @INC, pretty much like require() except it doesn't do coderefs like require().

You can use Module::Path to test whether a certain module is installed, for example. In my case, I'm using it to provide shell tab completion of Perl modules (will be covered in subsequent entry). However, I find it lacking some features. And after waiting for a while (not) getting my patches submitted/rejected, I launched a fork which, after several iterations, eventually called Module::Path::More.

RFC Perl for education

For some time now, I have an idea of ePerl in my head. A subset of Perl or Perl in a sandbox. You might guess why? well Perl is great language, backwards compatibility makes your old code still run, even if some of the ancient designs are considered wrong nowadays. It’s all fine, except it’s not suitable for education.

In my opinion, to make Perl more acceptable in School/University curriculum we need to sell it to lazy teachers/lecturers, who need something like:

  • Current best practises upfront
  • No backwards compatibility
  • Strict, warnings, utf8 and newest Perl features on by default
  • Sub signatures and postfix dereferencing should be on and without experimental warnings
  • Most of the greatest CPAN modules should come preinstalled, and I am really talking about modules that helps beginners! i.e. Devel::REPL, Devel::DidYouMean, Moo, and many many other like Mojolicious, Dancer, Catalyst, whatever…
  • Forbid/remove special cases like split emulating awk.. or indirect object notation and many other silly leftovers
  • etc. etc.

Perl::Critic Has New Home And New Look

Perl::Critic has been improving code and irritating developers for almost 10 years! To celebrate, perlcritic.com has been moved to new hardware and completely rewritten.

The back end is now written in Modern Perl™ using Mojolicious. And the front end uses Bootstrap and jQuery to create a productive and fun user experience.

The source code is on GitHub as Perl-Critic/Perl-Critic-Jed and I welcome pull requests. If you're looking for an opportunity to contribute to a public site, this is a great place to start.

Check it out now: http://perlcritic.com

Imager::Draw::Hexagon - Draw hexes easily using Imager - metacpan.org

Imager::Draw::Hexagon - Draw hexes easily using Imager - metacpan.org :

After I gave my Tour of Imager talk last week I ended up releasing my own Imager module: Imager::Draw::Hexagon. It allows you to easily calculate the points of a hexagon of any size and draw it or outline it into your image. 

[From my blog.]

Day 9: Set operations with files (App::setop)

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

Have you ever encountered one or all of these situations?

1) You have two or ten log files, and want to know which IP addresses occur in all of them.

2) You have two SQL dump files, and want to know which tables are in the first but not in the second.

3) You have several files containing a list of usernames to create. You want to create all the users in order, but don't want to create twice.

Web sites with source code for hacking

Once in a while people ask me what open source projects could the contribute to? I can point them to any module on CPAN, but it can be a lot more fun to contribute to a project where the contribution has immediate and visible impact.

I don't mean projects like Bugzilla which is downloaded and run by the end user, but projects like MetaCPAN, or the web site of Rex.

I've started to create a list of web sites where the source code is available, and of course that is is written in in Perl. I tried to group them according to the level of activity of the project and where I could, I also mentioned the framework used for the project.

I got a lot of input from people on Reddit, but I am sure there are plenty of other sites. Please suggest more sites, or even send me pull requests.

Using Minion with a REST API

Minion is a job queue for the Mojolicious real-time web framework. Below is example usage that sends an email using a REST API. The email address is handed off to minion and then minion processes the task. Everything is in a self-contained file as a Mojolicious::Lite app.

In addition, a config file is shared between minion and the web app.

One cool thing about Minion is that it has support for a Postgres backend using Mojo::Pg. Given that, workers can be running jobs on different physical boxes as long as they use a compatible "Pg" connect string.

The web app is started like so:

$ /opt/perl minion_email.pl daemon

A Minion worker is started with:

$ /opt/perl minion_email.pl minion worker

Example usage:

Parsing: top-down versus bottom-up

[ This is cross-posted by invitation, from its home on the Ocean of Awareness blog. ]

Comparisons between top-down and bottom-up parsing are often either too high-level or too low-level. Overly high-level treatments reduce the two approaches to buzzwords, and the comparison to a recitation of received wisdom. Overly low-level treatments get immersed in the minutiae of implementation, and the resulting comparison is as revealing as placing two abstractly related code listings side by side. In this post I hope to find the middle level; to shed light on why advocates of bottom-up and top-down parsing approaches take the positions they do; and to speculate about the way forward.

Top-down parsing

The basic idea of top-down parsing is as brutally simple as anything in programming: Starting at the top, we add pieces. We do this by looking at the next token and deciding then and there where it fits into the parse tree. Once we've looked at every token, we have our parse tree.

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.