The Best Art Continues to Surprise

| 3 Comments

I attended an exhibit about the work of Leonardo da Vinci several months ago. Part of that exhibit was a thorough analysis of his Mona Lisa painting. "It's perhaps the most famous painting in the world," I thought. "I've seen it (or at least replicas) thousands of times before."

Then at the suggestion of the exhibit, I looked behind the model and saw more details, such as a low wall, the lack of eyebrows and eyelashes, and other small details that have always been there but somehow failed to catch my attention.

Several years ago, I read an analysis of Roger Zelazny's The Chronicles of Amber series. The analyst admitted that he re-read the series every few years and learned new things each time. (Zelazny's Chandleresque tone in the first five books contributes to the depth of the books, but so does the fact that his characters gladly lie to, backstab, betray, confuse, manipulate, and distrust each other and their own selves.) A reinterpretation of a single line which seemed so innocent during the last reading could cause you to see a character in an entirely different light.

Good art is like that.

Today I understood an underused feature of Perl 5 better.

Paulo Custodio filed a bug on the Modern Perl draft that the explanation of module unimporting was incomplete. I had written that:

no Module::Name qw( arguments );

... is equivalent to:

BEGIN { Module::Name->unimport( qw( arguments ) ) }

In all accuracy (and, upon reflection, obviousness), no Module::Name qw( arguments ) is equivalent to:

BEGIN
{
    require 'Module::Name';
    Module::Name->unimport( qw( arguments ) );
}

Even though I rarely use module unimporting and have never, to my best recollection, unimported a module I haven't previously used, its obvious that unimporting through no should imply require. (I have trouble imagining an interface where you'd initially load a pragma with no, unless you use strictperl, but clever people can do clever things.)

You may all now chuckle at how long it took me to realize this (and, yes, I did read the Perl 5 source code to prove to myself that this occurs).

3 Comments

Three modules which use this kind of interface (presumably for the legibility of "no x;" over "use no::x";) are overloading (which is in 5.12), indirect, and Leading::Zeros. I don't know who started the trend but I could easily believe that it was any one of Yuval, Vincent, or Damian!

Right! I thought I'd seen something like that somewhere. A moment's reflection reveals that the first culprit I noticed was autovivification.

> no Module::Name qw( arguments ) is equivalent to:
> 
> BEGIN
> {
>     require 'Module::Name';
>     Module::Name->unimport( qw( arguments ) );
> }

Nitpick: Module::Name must be a bareword (not a string) for the :: to be interpreted correctly:

BEGIN {
  require Module::Name; # <-- must be bareword
  Module::Name->unimport( qw( arguments ) );
}

Example: Given

--- 8< cut here ---
package Test::Module;
sub unimport { print "unimport called\n" }
1;
--- >8 cut here ---
% perl -I lib -e "no Test::Module"
unimport called
% perl -I lib -e "BEGIN { require 'Test::Module'; Test::Module->unimport(); }"
Can't locate Test::Module in @INC ...
% perl -I lib -e "BEGIN { require 'Test/Module.pm'; Test::Module->unimport(); }"
unimport called

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

affiliated with ModernPerl.net

Categories

Pages

About this Entry

This page contains a single entry by chromatic published on July 22, 2010 3:10 PM.

Eliminating Errors with Little Languages was the previous entry in this blog.

A Checklist for Writing Maintainable Perl is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


Sponsored by Blender Recipe Reviews and the Trendshare how to invest guide

Powered by the Perl programming language

what is programming?