More tentacles for the cpXXXan

My mad experiment in CPAN mirrors has grown a couple of new tentacles. Previously it could be a perl-X.Y.Z-specific mirror, such as the CP5.6.2an, or an OS-specific mirror such as the cpMSWin32an. Now it can combine the two such as in the CP5.8.8-irixAN and all of those can also be combined with a date/time to only include stuff that was already on the CPAN as at that time, such as at the CP2000AN.

Why do this? Let's assume that you have a large complex application which uses lots of stuff from the CPAN, and depends on Elk version 1.009 and ListOfDogs version 5.1, and will break with any later version of Elk (or of ListOfDogs). You get a feature request from
a user, and think "ah-ha, there's a module for that", and so you go to install Some::Module. Unfortunately, the latest version of Some::Module depends on Elk 1.234, so your CPAN client merrily upgrades Elk, breaking everything. Doom and Disaster. Having a CPAN "mirror" nailed to the date of the last release of Elk and ListOfDogs that works for you will save you from pain, suffering, and the Dark Side.

Searching for Daemons

One of the problems with the Ironman Challenge is that it’s too successful! I’m sure I saw an interesting post about daemoni[sz]ing scripts … can I find it now? Of course not!

EDIT: Perseverance paid off! Here’s the sneaky post I was looking for!

Pittsburgh Perl Workshop CFP ends Monday Sept 6

The Pittsburgh Perl Workshop 2010 will be Saturday October 9 and Sunday 10 at the Gates Center at CMU.

Don't miss your chance to speak at this years Workshop. The Call For Papers ends Monday Sept 6.

Submit your talk.

Book review: Catalyst 5.8 The Perl MVC Framework

Book information
Title: Catalyst 5.8 The Perl MVC Framework.
Subtitle: Build Scalable and extendable web applications using the Agile MVC framework.
Author: Antano Solar John.
Publisher: Packt Publishing.
Country: UK/India.
Year: 2010.

This book is a follow up to the 2007 Catalyst book by Jonathan Rockway (member of Catalyst core developer team). I have no idea how much of the content is changed between the two.

About the review(er)
This is a review on the electronic (PDF) edition of the book. I am a Perl developer and a CPAN author, but have not used Catalyst (or most other recent web frameworks, for that matter) before.

Back on the track for Perl 6

Yes, Dave Vaux, one of the british daves helps me translating my perl 6 tutorial and I'm writing here and there new lines into it. More important I'm reading synopses again. Im chatting with the Perl 6 crew again. What a great feeling, even jnthn is currently traveling. But I'm doing it more focussed then earlier. And when I learn something it gets immediately into stuff i write for the wiki, talks, slides. And to all of you who also stay at perl booths, I will try deliver them also in english. At least in a git so then TPF and bunch aroung gabor can do something out of it. Yes one more promise, but my perl 6 talk for mrccc is getting currently not so bad, so im hopeful to deliver there something too.

No More Excuses

Occasionally I find a bug in someone's module and post a patch or a bug report. About half the time, the bug is fixed and the new module is released in less than a week. Could be better, but not too shabby. However, about the other half of the time the bug either goes unanswered, or I hear back from the module author that the patch needs to wait until some big release that they are waiting on. I hereby declare bullshit on that. Dist::Zilla makes it so ridiculously easy to push out a release that there is no longer a reason to wait on pushing a bugfix release immediately.

Yet another readonly module

I’m done with Readonly. It has served it’s purpose but I’m frustrated to the point of writing a replacement. I still think it’s a good idea to declare variables readonly, but as an implementation I find Readonly unworkable. The problem is two-fold.

Maintenance.

Readonly hasn’t been updated in 6 years. It has collected quite a list of bugs. Not all of them can be fixed, but most that can be are either trivial or already have patches. Fact is it hasn’t been done and I have my doubts on whether it will be done.

Broken by design

Coding Style As A Failure Of Language Design?

Read this older blog post the other day. Hilarious at best, creepy at worst.

Arbitrary limitations should not be added to a general-purpose programming language unless for a really good reason. Do you really want to code in a language that forces you to indent with 2 spaces, never cross 80-column line, or require/forbid whitespace here and there? And besides, is there any language (no matter how strict the syntax of which is) which do not have some sort of coding style?

Testing that darned filehandle

It wasn't fun finding out that some legacy code creates a bunch of filehandles on the fly to do logging.

package Some::Client;
use Some::Logging::Module;

# later ...
print MAGICLOGHANDLE $some_data;

That MAGICLOGHANDLE is dynamically generated and shoved into my namespace (along with a ton of other handles, one per log). So I needed to test what was being printed to it. Fortunately, Perl's dynamism makes this really, really easy.

Test::Class::Filter::Tags

I'm happy to announce the release of Test::Class::Filter::Tags. This module uses the new filter support introduced in version 0.36 of Test::Class to allow selective running of Test::Class tests.

With the filter support of Test::Class, it's now possible to supply any number of filter subs, when running Test::Class tests. Each filter is given the opportunity to suppress the running of each test; If any filter says to suppress a specific test, that test will not be executed.

Using this mechanism, when Test::Class::Filter::Tags is used in your Test::Class classes, you can specify 'Tags' attributes on non-fixture (ie, not startup, setup, teardown or shutdown tests). When running tests, you can set an environment variable of TEST_TAGS, to run only the subset of the tests that have the specified tags. Conversely, you can limit a subset of tests that have specified tags via the TEST_TAGS_SKIP environment variable. Both of these vars can be used to give even more granularity in deciding what tests are run.

Ubic - code reuse and customizations

In my previous post I showed most trivial example of ubic service.
Now it's time to talk about more interesting stuff :)

Every ubic service is simply a perl object which implements start/stop/status methods.
It is very similar to /etc/init.d shell scripts, but since perl is a real programming language, you don't have to copy-paste tons of boilerplate code every time (Dave Rolsky, if you're reading this - your silki init script is good, but "apache2-backend" line in comments means it was copy-pasted too; is there anyone who can actually write proper init script by hands?).

So, instead of copy-pasting, you can reuse any existing Ubic::Service::* module, or implement your own if it's necessary. For example, there is the Ubic-Service-Plack distribution on CPAN which you can use to run any PSGI applications. Quoting Ubic::Service::Plack synopsis:

Yet Another Post on "Pascal Triangle"

又名:如何用一行Perl 6打印杨辉三角前n行。

此时开始到目前为止,网上至少有三篇关于如何用Perl 6打印杨辉三角的文章:这里(TimToady), 这里(Moritz), 和 这里(Masak)。

"There's more than one way to do it.",好吧,我也来写一个,下面这行代码打印杨辉三角的前10行:

([1], -> @p { 0, @p Z+ @p, 0 } ... *).[^10].perl.say;
(......多少都有些抄袭的嫌疑,其实就是直接拼成一行了,不是吗?:))


简单解释下:

"infix:<...>"称为"Series Operator"(S03),相当于把对一个块的求值结果push到最前面的List里面,直到满足右边的条件为止。比如:

(1, {$_ + 1} ... 5).perl.say;
→ (1, 2, 3, 4, 5)


"*"在这里是一个被叫做"Whatever"(S02)的东西,在这里起构造惰性求值列表的作用。

中间自"-> { }"起,是一个由"->"(S06)构造的轻量型匿名函数块,即要应用("apply")的部分。类似于Perl 5中"map BLOCK LIST"的"BLOCK"。同时,"Z+ Operator"(S03)将两边列表结对相加。关于此操作符的用法举例如下:

(1, 2, 3 Z+ 4, 5, 6).perl.say;
→ (5, 7, 9)

额外一提:"Z+"属于"Zip Operator"系列,类似的还有"Z~",可以用它实现成对字符串拼接:

(1, 2, 3 Z~ 4, 5, 6).perl.say;
→ ("14", "25", "36")

现在,把代码中的"10"改成需要打印的行数,就可以实现"用一行Perl 6打印杨辉三角前n行"了。:)

顺便说下,现在想试试Perl 6的话用不着安装,直接Try Rakudo

Prime Factors in Perl 6

There's really nothing extraordinary about this and certainly nothing specific to Perl 6, but I really liked how it felt writing code to find prime factors. I do note, however, that the habit of using a dash instead of an underscore in identifiers does slow down the Perl 6 to Perl 5 translation (since I'm doing that manually). Hopefully we won't need to keep doing that translation in the future.

Wishlist for a service framework and/or manager

I maintain code for a few daemons/services written in Perl (most of them serve requests by forking/preforking). Reading post on Ubic, I started to feel that I am reinventing a lot of wheels. Currently I am doing these by writing my own code, as much as which I hope can be offloaded to CPAN in the future:

Fundraising idea for YAPC?


Poker tourney with buyins going to the TPF, and higher end schwag going to the winners?

Useful side effects of the perl testing culture

I am currently in the middle of trying a new mechanism to deploy perl applications (several which are catalyst based) on servers at work while attempting to keep the level of supporting system (ie perl and the required modules) maintenance work to a minimum whilst being able to use modern perl - and we are running on Centos systems by default, so currently the system perl is 5.8.8. I intend to write about my proposed solution to this in a few weeks when I have had more of a chance to see how it works...
However as part of this I have been building perl and a whole raft of supporting modules under a set of build system scripts - encouragingly the whole build appears to be around one hour in length.
What I wasn't expecting to see was test failures when building the modules.
I really wasn't expecting to see a set of failures down to the tests failing in XML::Parser - thats a widely used and slow changing module.
So I went digging... and finally got to the Red Hat Bugzilla entry #556415.
A undertested security fix to expat had caused a regression - which went unnoticed other than by the XML::Parser test suite.
Thats a big win for the perl testing culture.

Avoid my keys() accident

I broke $work yesterday when a change I'd made that I thought was mundane was not in fact. I'd changed some code from: if ( keys %$hash_ref ) { to if ( %$hash_ref ) { under the theory that we weren't supporting any perl less than our current production at perl-5.10.0.

What I'd completely missed was that $hash_ref might be undef and that keys %$... would auto-vivify the hash if necessary. Previously, the hash would be created as a side effect of dereferencing it. Afterward, I got an exception because the hash wasn't being automatically created just by looking at it.

The reason for this is keys() is actually an lvalue, something you can assign to. The meaning of keys( %... ) = 8 is actually fairly obscure and not what you would guess if you haven't read the documentation for keys(). Because keys() is an lvalue, the dereference %$... will auto-vivify anything necessary because I might want to modify it.

When I dropped the usage of something strictly defined as an lvalue function, the dereference stopped auto-vivifying and now I had exceptions in production. Wheee!

The Foursquare gaming code challenge

Mayank Lahiri writes a Foursquare checkin tool in nine Perl statements, and Alex Ford says he has a two line solution, where line means statement, and statement. Part of the reason their solutions look so ugly is that they want to do it with the Standard Library. I was slightly interested in this because someone had asked Randal if he was checking in with Perl (he is not).

Larry Wall once said that he could program anything in one-line of Perl given a sufficiently long line. That is, in a language where lines aren't significant, line count is stupid. If you want to count lines, Python is probably your language.

ElasticSearch::AnyEvent pre-release available on github

I've just pushed ElasticSearch::AnyEvent - this brings async requests to the Perl ElasticSearch client. It is still lacking proper documentation and any tests, which will soon follow.

It is available on the anyevent branch on github

This is my first foray into async programming in Perl, so I'd appreciate feedback on the API and code.

Briefly, it can be used as follows:

Pittsburgh Perl Workshop 2010


The Pittsburgh Perl Workshop is a low-cost technical conference held at the Carnegie Mellon University's Oakland Campus. The workshop will be held on October 9-10 2010.

We are happy to have Larry Wall keynote PPW 2010 in the new Gates and Hillman Centers.


* Talk Proposals

* Classes

* Hack-a-thons

* Sponsors

* Talk Proposals

We do not have deadline for talk proposals yet but please send them sooner than later or you may miss your chance to speak.

The Pittsburgh Perl Workshop 2010 is the perfect opportunity to share your ideas, code, and projects with masses of code-loving Perl hackers. Shouldn't you have a speaking slot at this year's event? Shouldn't you experience the full, PPW-powered glory that only speakers can know?

Of course you should!

Haven't you ...
done interesting stuff for Perl?
written cool code?
seen the future of Perl?
got a story to tell?
got a trick to share?

In fact, if you have anything to say that would interest Perl people,
we want to hear you say it!

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.