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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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 post couldn't be simpler. stopw (from the App-stopw distribution) is a very simple CLI program. When run, it displays a running stopwatch, upon which you can press Spacebar to let it move down one line (so you can see/note the time you pressed the Space), or Enter to pause/resume, Z to reset back to 0, or Q to quit. I'm almost shameful that it took my Perl code more than 100 lines to accomplish this (I think the teenager me from the 1980's would surely have been able to whip up this task in about 20 lines of BASICA/GW-BASIC).
I now try hard to remember why I needed this in the first place, but can't recall. Probably to time some subtitle, or a song that I listen on the radio, or to exercise holding my breath, or exercise my reflex. But probably not.
Anyways, there is an existing CLI stopwatch on CPAN before I wrote this: App::Stopwatch (which includes the stopwatch utility), written by BESSARABV. However, it doesn't show subsecond precision, and does not allow for many controls like pausing/reseting. Plus, the name clashes with the Debian package of the same name.
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.
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.
[Pleased as I was to get mentioned in a lightning talk in this year’s YAPC, I noted that my mention was in the context of writing blog posts that “don’t contain much code.”1 Well, fair enough: I’m a verbose bugger, and a wannabe writer, so my prose does tend to ramble. But I can do code, dammit. So, you know ... here’s some code.]
The other day I was working on my music library scripts,2 and I needed a menu for something. Now, there are oodles and oodles of modules on CPAN to help you write menus. I’ve looked at most of them, and tried quite a few, but long ago I settled on using the -menu option in IO::Prompter, by the Damian. For a nice, pretty menu layout—say, something you do as a central feature for a program—it’s tough to beat. It’s not perfect, by any stretch, but it offers some very nice features, such as (optionally) not requiring ENTER after a menu choice.
But that’s not what I wanted in this case. What I was looking for here was a quick, compact menu ... sort of like what you get when you’re interactively staging a commit in git (that is, git add -p, or, probably more commonly, git add -i then choose “patch”). Specifically, the features I wanted were:
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Here's the problem statement: For safety/privacy reason, I generally want my desktop screensaver to trigger rather quickly (say 3-5 minutes) to minimize prying eyes when I'm away or fall asleep and forget to lock. But when I watch videos, I want to set the timeout to a longer time (say the total duration of the videos plus 1 minute, or (better) 20-60 minutes which is the amount of time from I start the video until I doze off at night.
I used to have this line on my ~/.mplayer/config on my PC:
until I use a laptop with KDE plasma on it, which doesn't use xscreensaver by default. Plus I don't think disabling screensaver for the whole playback duration is sometimes not what I want (see above).
I just released Buftabline, a Vim plugin that takes over the tabline and renders the buffer list in it instead of a tab list. It is designed with the ideal that it should Just Work, and has no configurable behaviour: drop it into your configuration and you’re done.
I wonder how many newbies in the whole history of Perl had their "llama" arrive from Amazon and shortly thereafter—in a fever pitch of excitement—managed to create a distribution they thought was the best thing since sliced bread and upload it to CPAN only to have their debut into our wonderful, loving community met by a CPAN rater. After which, naturally, they slowly backed out of the room, closed the door behind them, picked up their (PHP|Ruby|Python|Javascript) book and never coded a line of perl again...
Surely, no one can say but maybe—just maybe—we'd be better off with a system similar to Stack Overflow where a user has to have a certain number of points or special kind of badge (e.g. the Teacher, Ambassador, the "Empathy Lieutenant", the "brian d foy", etc) in order to leave a rating on someone's first distribution.
I dunno. It's worth a thought, because this whole thing just made me cringe...
I’ve posted my slides for the Tour of Imager talk I gave earlier this week at MadMongers. If you are interested in processing photos or drawing in Perl, you’ll want to check this out.