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):

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.

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 ) ) {
    ...
}

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.

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!

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

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.

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?

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.

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.

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.

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.

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.

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!

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.]

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.