What you should know about signal based timeouts

The problem

I think we've all seen code like this example from perlipc:

my $ALARM_EXCEPTION = "alarm clock restart";
eval {
    local $SIG{ALRM} = sub { die $ALARM_EXCEPTION };
    alarm 10;
    flock(FH, 2)  || die "cannot flock: $!";
    alarm 0;
};
alarm 0;
if ($@ && $@ !~ quotemeta($ALARM_EXCEPTION)) { die }

Here, signals are used to put a time limit on some action. However sometimes this doesn't work as wanted. In particular, some C libraries used in XS modules don't honor the [deferred signaling](http://perldoc.perl.org/perlipc.html#Deferred-Signals-(Safe-Signals%29) resulting in it being ignored until the C function has finished, which is unlikely to be what you want.

Therefore, people resort to unsafe signals

use Sys::SigAction qw( set_sig_handler );
my $ALARM_EXCEPTION = "alarm clock restart";
my $h;
eval {
    $h = set_sig_handler('ALRM', sub { die $ALARM_EXCEPTION }, { });
    alarm 10;
    flock $fh, 2 or die "cannot flock: $!";
    alarm 0;
};
alarm 0;
$SIG{ALRM} = $h;
if ($@ && $@ !~ quotemeta($ALARM_EXCEPTION)) { die }

Perl documentation is Awesome

Learning Perl, 6th Edition book review most popular of 2011

The "Learning Perl, 6th edition" book review had the distinction of being iProgrammer's most popular review of 2011, between more than 250 reviews on a vast variety of subjects with thousands of reads each, but the Perl review reached top spot with 10,800 reads (figure untill 29/12/2011)
The benefit is that it exposed the language to a wide audience, since the site appeals to a general programming public from C# to Javascript, therefore I do hope that it managed to attract "new blood" and/or converts !

YAPC::NA 2012 Call For Presenters Now Open!

We are now accepting talk proposals for YAPC::NA 2012

We’re of course interested in anything Perl-related you want to talk about. However, we have two areas we’re definitely interested in:

First, we’re looking for talks on Perl in the Wild. These talks are about businesses and individuals who have done great things with Perl. Perhaps you’ve automated your house with Perl, or built the latest and greatest web app. Or maybe you’re controlling Arduino boards to build robots with Perl. Maybe you’ve got amazing case studies in high-end performance with Perl. Or maybe, you’ve built a boring little app in Perl that has enabled your business to make millions of dollars. You could be building a great video game in Perl, or perhaps a social network to take down Facebook and Twitter.  Whatever it is that you’ve built or are building, we want to hear about it.

Happy New Year!

Welcome to 2012. You made it! Can you believe it? I can't believe it either, the way you partied last night. Have you no shame?

Well it's time to make a New Year's resolution. You're coming to YAPC::NA 2012 in Madison, WI on June 13-15. 

While you're at it, have your spouse or significant other make the resolution with you. Bring them to the YAPC::NA 2012 Spouses Program.

YAPC::NA Has A Mailing List

Did you know that YAPC::NA has a mailing list? Neither did I until a couple days ago. Starting now, I'll be cross posting our news items to the mailing list, in case that is your preferred way to receive news about YAPC::NA 2012.

YAPC::Europe 2012 still alive

We are still alive!

Our silence regarding the progress and especially
the venue location and conference dates is owed to the restrictions of
the planned venue which explicitly forbids mentioning the date and
place before the contract is signed by both parties.

We didn't keep up with the post frequency after the first blog posts,
but as the contract should be signed at the start of January 2012, you
should see more frequent updates from us again. We can't promise to compete with the excellent communication of YAPC::NA 2012 though.

We wish you a good start in 2012 and hope to see you in Frankfurt!

Tinkering with a (safe) string use

I read Schwern’s post How (not) To Load a Module just as I was wanting to dynamically load different Module::Build subclasses for different OSes. It struck me just as odd as it seems to for everyone that use-ing a module from a string should be so hard.

In my spare time, I have been working on some use problems using Devel::Declare and it gives some intersting hope here. Preliminarily I am calling it UseX::Declare but hopefully someone will come up with something better. Basically it provides a function called use_from which acts like:

use UseX::Declare;
BEGIN {
  our $var = 'Net::FTP';
}
use_from $var;

Through the magic of Devel::Declare, the parser sees:

use UseX::Declare;
BEGIN {
  our $var = 'Net::FTP';
}
use_from(1); use Net::FTP;

The use_from(1); is no-op cruft that allows me to get around a limitation in Devel::Declare (or if not a limitation, then a failure in my understanding).

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is run by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.