perlcritic tool is often your first defense against "awkward, hard to read, error-prone, or unconventional constructs in your code," per its description. It's part of a class of programs historically known as linters, so-called because like a clothes dryer machine's lint trap, they "detect small errors with big effects." (Another such linter is
perltidy, which I've referenced in the past.)
You can use
perlcritic at the command line, integrated with your editor, as a
git pre-commit hook, or (my preference) as part of your author tests. It's driven by policies, individual modules that check your code against a particular…
A recent Lobsters post lauding the virtues of AWK reminded me that although the language is powerful and lightning fast, I usually find myself exceeding its capabilities and reaching for Perl instead. One such application is analyzing voluminous log files such as the ones generated by this blog. Yes, WordPress has stats, but I’ve never let reinvention of the wheel get in the way of a good programming exercise.
This blog has devoted a fair amount of attention to the popular and multifaceted object-oriented system Moose and its lightweight subset Moo. I’ve also covered Object::Pad, the testbed of concepts and syntax for Corinna, the proposed next-generation Perl core OO system. But what if your project is too memory‑, performance‑, or dependency-constrained for these options?
It turns out that CPAN has a rich history of lighter-weight OO modules to meet many different needs. If you can live with their trade-offs, they’re worth investigating instead of rolling your own layer over Perl’s OO. Here are a few.
Class::Struct’s main claim to…
Last month I wrote about using Moose’s
override function to, well, override a superclass's method. Chris Prather on the #moose IRC channel suggested soon after that the
around method modifier (or its little sisters
after) might be a better choice if you're also calling the original method inside. He noted that "at a minimum
override only works if you're subclassing,
around will apply to composed methods too."
Last week I explored using the Inline::Perl5 module to port a short Perl script to Raku while still keeping its Perl dependencies. Over at the Dev.to community, Dave Cross pointed out that I could get a bit more bang for my buck by letting his Feed::Find do the heavy lifting instead of WWW::Mechanize ’s more general-purpose parsing.
A little more MetaCPAN investigation yielded XML::Feed, also maintained by Dave, and it had the added benefit of obviating my need of XML::RSS by not only discovering feeds but also retrieving and parsing them. It also handles the Atom syndication format as well…
The Perl and Raku programming languages have a complicated history together. The latter was envisioned in the year 2000 as Perl 6, a complete redesign and rewrite of Perl to solve its problems of difficult maintenance and the burden of then-13 years of backward compatibility. Unfortunately, the development effort towards a first major release dragged on for ten years, and some developers began to believe the delay contributed to the decline of Perl’s market- and mindshare among programming languages.
Last week found me exploring Object::Pad as an alternative to the Moo object-oriented framework for Perl since the former is prototyping the syntax and concepts for a proposed built-in OO framework named Corinna. I had to put that particular project on hold as dbcritic’s current design is a bit too role-happy and Object::Pad currently lacks method modifiers as in Moo. (Corinna is explicitly skipping them for its current minimum viable product.) Thankfully, development continues at a rapid pace. For instance, author Paul Evans has already addressed a problem I ran into when attempting to examine slot values in the debugger.
Perl has ”very minimal” support for object-oriented (OO) programming out of the box by its own admission. It’s class-based but classes are just packages used differently. Objects are just data structures
I think this is the real point about Perl code readability: it gives you enough flexibility to do things however you like, and as a result many programmers are faced with a mirror that reflects their own bad practices back at them.
This is why Damian Conway’s Perl Best Practices (2005) is one of my favorite books and
perlcritic, the code analyzer is one of my favorite tools. (Though the former could do with an update and the latter includes…
I publish Perl stories on this blog once a week, and it seems every time there’s at least one response on social media that amounts to, I hate Perl because of its weird syntax.” Or, ”It looks like line noise.” (Perl seems to have outlasted that one — when’s the last time you used an acoustic modem?) Or the quote attributed to Keith Bostic: ”The only language that looks the same before and after RSA encryption.”
So let’s address, confront, and demystify this hate. What are these objectionable syntactical, noisy, possibly encrypted bits? And why does Perl have them?