Moo, how do you annoy me? Let me count the ways...

OK, Moo is actually a rather nice little OO framework. It's inspired by Moose but not a clone of it.

When Moo detects Moose has been loaded, it "inflates" all Moo classes and roles into Moose classes and roles, so Moo code integrates with Moose code perfectly. Because of this, and Moo's very light memory and CPU footprint, many Moose-based projects are migrating to Moo. High profile migrations include Throwable, Message-Passing and MooseX-Role-Loggable.

Not all Moose-based projects are easy to port to Moo. Some require a high level of introspection and meta-hackery that only Moose can provide. But if Moo does seem to be a good fit for your project, switching to Moo is not as simple as dropping the "se" from your "use Moose" lines. There are a number of incompatibilities between the declarative syntaxes of Moo and Moose.

I've recently released MooX-late to help smooth over the differences and translate Moose code to Moo. Currently it handles:

Foswiki tip: How to hide web at the left pane

Rename the web to hide it from left pane. Say the directory is ZAdminTest, rename the folder to zAdminTest

Access it using: http://host/foswiki/bin/view/Main/ZAdminTest/WebHome

I am not sure if this works on *nix system though..

Adding Macros to Excel::Writer::XLSX

Macros are a powerful feature of Excel and are a frequently requested feature for Spreadsheet::WriteExcel and Excel::Writer::XLSX.

It is also a feature that I've wanted to add for some time but it wouldn't be feasible, with current human lifespans, to re-implement Excel's VBA in Perl. So instead I implemented a scheme to "borrow" the VBA code from Excel and add it to an Excel::Writer::XLSX file.

At its simplest an Excel 2007+ file is a collection of XML files in a zip container. Here is a look inside a sample file that contains macros:

Nicer dumping of data structure in Log::Any

When you log data structures with Log::Any, e.g.:

% DEBUG=1 perl -MLog::Any::App='$log' -e '... $log->debugf("ccls=%s", $ccls); ...'

do you often see something like this?

[38] ccls=[{fmt => ['integer','integers'],text => ['integer','integers'],type => 'noun'},{expr => 1,fmt => 
'default value %s',text => 'default value 1',type => 'clause'},{expr => 1,fmt => '%(modal_verb)s be divisi
ble by %s',multi => 1,text => 'must be divisible by 2 and 3',type => 'clause'},{expr => 1,fmt => '%(modal_
verb)s be at least %s',multi => 1,text => 'must be at least 1',type => 'clause'},{expr => 1,fmt => '%(moda
l_verb)s be at most %s',multi => 1,text => 'must be at most 100',type => 'clause'}]

Log::Any uses Data::Dumper with Indent setting of 0. This is compact, but hard to read. Tired of scanning hash keys with my fingers or mouse pointer, I finally spent about 5 minutes creating two patch modules to fix this annoyance. The first one is Log::Any::Adapter::Core::Patch::SetDumperIndent to let you set indent level, and the second is Log::Any::Adapter::Core::Patch::UseDataDump to use Data::Dump instead of Data::Dumper.

For convenience when typing these module aliases are provided: Log::Any::{DD,DI1,DI2,DI3}.

Now you can conveniently do this:

% DEBUG=1 perl -MLog::Any::App='$log' -MLog::Any::DD -e'... $log->debugf("ccls=%s", $ccls); ...'

Perl Oasis 2013: Call for Speakers

The 5th Annual Orlando Perl Workshop, aka Perl Oasis, is coming on January 11th. That's only about a month away. Obviously the organizers are behind on things but they have announced the call for speakers! Please sign up now! If speaking isn't your thing, you can simply come and enjoy the company and geekery. Details are on the website: http://perloasis.info/opw2013/.

MooseX::Role::Loggable improvements (version 0.110)

I've released a new version of MooseX::Role::Loggable: 0.110. It provides some improvements and basically a more steady version of it.

Here's a description of what it is, what the improvements are, and some of the considerations in doing them.

TMTOWTDI, plus benchmarking

There's a very common Perl idiom for getting "top N elements" from an array: @top = (sort @a) [0 .. $n - 1]. Mostly, it's good enough for anything one would dare to store in RAM.

Then, there is Sort::Key::Top, which allows you to write @top = top $n => @a. Yet another syntax sugar?

Not even close! While the docs don't state it boldly, it is:

  1. a XS based module
  2. partition-based general selection algorithm (also known as quickselect) implementation

So, expect it to be fast. How fast?

MooseX::Params::Validate

Subroutines that take more than a single argument should really be using something like MooseX::Params::Validate.

Consider:

sub vivisect { 
    my ( $self, $args ) = @_;
    confess 'Expected a hashref of arguments' unless 'HASH' eq ref $args;

    my $hamster = $args->{hamster};

OK, so we know it accepts a hashref of arguments, and what's more, we know one of them is called hamster. But: what constitutes an acceptable hamster? What do we want to do if we don't have a hamster? What other arguments am I going to need? All of this is mental load at 7am and sure, maybe there's documentation, but maybe the intern snuck in some new options and didn't tell anyone...

Compare and contrast this to:

sub vivsect {
      my ( $self, %params ) = validated_hash( \@_,
          hamster => { isa => 'Hamster', default => sub { Hamster->animate(), } },
      );

Yes, it's some more typing. But now, as a reader, I know what's what. I know a hamster is optional, and I know what'll happen if I don't include it. I know no-one else has been adding other options like guinea_pig, because they'd show up there.

Versioning Loops

I just found something interesting.. well, at least, fun:

Package namespace         installed    latest  in CPAN file
Perl::MinimumVersion           1.29      1.30  CHORNY/Perl-MinimumVersion-1.30.tar.gz

After installing Perl::MinimumVersion, I get:

Package namespace         installed    latest  in CPAN file
Perl::MinimumVersion::Reason      1.20      1.29  CHORNY/Perl-MinimumVersion-1.29.tar.gz

And if I ask to install Perl::MinimumVersion::Reason, yeah, of course, I get:

Package namespace         installed    latest  in CPAN file
Perl::MinimumVersion           1.29      1.30  CHORNY/Perl-MinimumVersion-1.30.tar.gz

Probably a good idea to add a bug report... later.

But fun to have problems with versions on a module that deals with versions.

Perl 5 Porters Weekly: November 19-November 25, 2012

Welcome to Perl 5 Porters Weekly, a summary of the email traffic of the perl5-porters email list. Sorry I didn't publish a summary last week. Although there was list traffic I didn't find any messages I wanted to summarize.

This week's topics include:

  • perl 5.17.6 is now available!
  • On deprecating unescaped literal left brace
  • Parrot 4.10.0 released
  • Perl in Git on Windows?
  • Move tests not using t/test.pl into a separate directory
  • Hash randomisation breaks CPAN

Visually graphing module dependencies

I've just released the first version of prereq-grapher, a script which generates the dependency graph for a module or script in any of the formats supported by Graph::Easy. The functionality lives in App::PrereqGrapher, which in turn uses Perl::PrereqScanner to extract dependencies.

Smart whitespace and the Ruby Slippers

Scannerless parsing

[ This is cross-posted from the new home of the Ocean of Awareness blog. ]

I've been working on a "scannerless" Marpa interface. "Scannerless" means that the user does not need to write a separate lexer -- the lexer (scanner) is included in the parser. One of my working examples is the synopsis from the main Marpa::R2 POD page, rewritten to do its own lexing:

    
:start ::= Expression
Expression ::=
       Number
    || Expression '*' Expression action => do_multiply
    || Expression '+' Expression action => do_add
Number ~ digits '.' digits action => do_literal
Number ~ digits action => do_literal
digits ~ [\d]+
    
      

Here the notation is that of my last post, as documented here. New for the scannerless parser are

A Question of Location

The great detective was staring at the door, as he had done for the past two weeks. He needed a case to occupy that mind. Thankfully today the door opened and Holmes had a case.

A man stepped in and introduced himself as Mr. Mokko.

”Watson, here is a man having troubles with Perl.”

”Holmes, how can you know that?”

”We can tell from the lines on his face, the stiff wrists and the pads of his fingers that he a much maligned sysadmin; from the Hawaiian shirt and the hat that he’s into the Perl scene. The scowl and the fact that he’s here on our doorstep tells me that he’s having troubles.”

Holmes looked back to the man and said, “Come now, you must tell me the tale.”

Method::Signatures: where and when

I’ve just released a new version of Method::Signatures: 20121201, a.k.a. yesterday.  This one has been a long time coming—I thought for a while there that $work was going to either bury me or sap my will to live—but it’s finally here, and I hope you MS fans out there will be rejoicing.  Let’s take a look at some of the goodies.

(By the way, most of these awesome new features came from the Damian, as I described in my post about Git and patches.  The remainder come from schwern, who is of course the original author of MS.  This time around, I really am just the guy who put it all together and uploaded it for all y’all.)

where Constraints

The Case of the Unexpected Pax

It was late afternoon of a chill November in Paris. I was walking along the quai, lost in a brown study. Looking up, I saw my friend C. Auguste Dupin approaching me.

"Ah, bon soir, mon ami," said Dupin, "and what brings you beside the Seine on this crisp evening?"

"Something has been puzzling me," I replied, "and I thought the walk would give my thoughts an opportunity to put themselves in order."

"It is a day of puzzlements, no? Will you not share your puzzlement with me?"

"Well," I demurred, "it is a small thing -- probably something I did to myself. But I do not wish to intrude on your time."

"Ah, but it is no intrusion for a friend."

"Well," I said as we turned across the Pont Neuf, "as you know I dabble in Perl, and I like to keep a variety of systems available for testing purposes. I upgraded one of these and was re-installing Perl, when one single module failed to install -- indeed, failed to unpack."

Redesigning Package::Strictures

Package::Strictures on metacpan

Design goals

  1. An infrastructure for having “optional” code blocks that can be eliminated prior to execution.
  2. Ideally, these code blocks can be toggled by calling code and then eliminated from the execution tree at the OP level.
  3. In essence, delegate 100% of the “Speed vs Correctness” concern to the consumer of the code, not the implementer.

Presently implemented using dead-code folding mechanisms.

a();
if( 0 ){ 
   /* code */ 
}
b()

Which becomes

a();
/* noop */
b();

Additionally, this is implemented with perl constant subs so that the if logic is performed at code body compile time, eliminating any run-time penalties from doing the check:

YAPC::Europe 2013 in Kiev, week minus 37. More ideas about extra programme

Dear Perl users,

Two weeks ago I mentioned a couple of activities that I found nice to have in the conference. Today I will tell about other things that we already tested during our previous events.

In 2009, at YAPC::Russia in Moscow Alex Kapranov hosted the Game of the Future, where we were trying to predict the future of Perl and related things. There were a few groups that were compiling the future based on probable or improbable events that might happen in a few years, as well as on the known facts. As a result, a mind map was build, which is quite interesting to read today:

What is the future of Perl.pdf

Screen Shot 2012-11-27 at 10.31.56 PM.png

You may find a number of region-specific items there but the funniest thing is that we were considering the YAPC::Europe in Kiev an unlikely event at that time.

Perlybook on 24pullrequests.com

I added perlybook.org to 24pullrequests.com. Hopefully we get some pull requests to iron out the issues we have.

Another related project I added is EPublisher-Source-Plugin-PodFromGithub. When we have finished that plugin we would be able to convert stuff like the Perl Advent Calender articles into ebook formats.

Due to private reasons I wasn't able to finish that plugin before December started :-(

Have you added your Perl project to 24pullrequests.com?

24pullrequests.com takes the spirit of the Advent coding calendar and puts a new spin on it. Try to send one pull request per day for the next 24 days and 24pullrequests.com will help you track your progress. At the time of writing, 1,224 devs have already signed up.

Some Perl projects are already represented, but there's still room for more. It would be good to see some more Perl projects on the list for participating Perl devs who are looking for something to contribute to.

Musing on Perl::Critic config

I've been exploring the Perl::Critic configuration file somewhat, and something struck me as unusual.

It seems fine for using for the usecase of "inherit some predefined set of rules and apply them selectively", which works fine if you just want to adopt some other standard that is pre-existing, and just make minor adjustments.

However, if you're wanting to create policy sets for others to use, it seems poorly suited.

1. Existing Systems

1.1. Severity level

This feature seems confusing.

It looks simple at first, but its problematic for anyone to utilise this to create a large, custom policy set.

The gist I get of reading it is you specify a severity level in your configuration, and policies that are included with a larger severity number than that are used. ie: Specify severity = 2 and items with severity levels 2,3,4,5, will be applied, while rules with severity level 1 are ignored.

The documentations suggest it might be a good idea to manually override the severity level for a plugin, ie:

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.