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.

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

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!

Random Perl wishlists #1: uncapture modifier, require+import, backtick function

Uncapture modifier. The new /r regexp substitution modifier in Perl 5.13.2 indicates that there might be hope for even more modifiers in the future. A possible modifier might be one that ignores all capture groups, which can solve this guy's problem.

require that can also import. I wonder why "require" doesn't also support importing like "use" does: use MODULE_NAME LIST... since it already support "require MODULE_NAME". This way, whenever I want to defer loading some modules, I can just replace "use" with "require" and put the statement under some "if" statement.

the backtick function.. Do you find yourself often having to do use a temporary variable like this, $cmd = "some longish and ".quote("complexly formed")."command"; before doing backtick `$cmd`? This is because unlike in PHP, we have system() but no backtick(). Most probably remnants from shell. There is Capture::Tiny for more general solution but of course it's a bit more cumbersome.

YAPC::EU 2010 videos are on YouTube

The YAPC::EU 2010 team has uploaded to YouTube videos of the conference in the yapceu2010 channel. There's even one of me presenting the White Camel Awards to cog and to Barbie. I don't think I'm terribly interesting, but I like their comments as they accept their awards.

Paul Fenwick couldn't be there, but maybe someone can convince him to do a video acceptance speech. He's dressed as a Star Fleet officer, a pirate, and a mad scientist. What should he be in the video?

Resurrecting Glasgow.pm

During YAPC::EU mst suggested "why don't you just start Glasgow.pm?"

I talked about it a bit with a friend who'll be back in the country soon enough and even today at work, and I think we may have enough people to kickstart the new Perl mongers group.

I know there are several businesses and people in the West of Scotland who either use or like Perl, so I am hoping that enough of them would like to join the group.

I've sent the request to pm.org's support to reinstate the old Glasgow.pm. I will endeavour to bring the mailing list and website up as soon as possible, and will start reaching out to people who use Perl in the area. Dear lazyweb, could you help me?

Ubic - how to implement your first service

I had a hidden agenda when I asked on this blog about how do you run your daemons.

There is a tool I recently opensourced. It can be compared to classic SysV init script system or to daemontools, runit or upstart, but it already is better and more flexible at least in some of its properties (otherwise I wouldn't bother to implement it :) ).

It is called Ubic and it is a toolkit for describing daemons in pure perl.

Ubic service is simply a perl object of some class inherited from base Ubic::Service class. Ubic loads service descriptions from /etc/ubic/service/ directory. To create your first service, you have to write something like this:
# cat >/etc/ubic/service/test
use Ubic::Service::SimpleDaemon;
return Ubic::Service::SimpleDaemon->new({ bin => "sleep 1000" });
"ubic status" command can show you status of all or some services on host:
# ubic status
test	off
ubic-ping	running
# ubic status test
test off
Now, as you probably already guessed, to start service you simply have to say "ubic start":

spreading perl on multiple level // please help with your codexp

jejky, I got a TPF grant. Even if scheduled it for 7 month, I plan to be ready end of this year. I think it will also appear in the first Module I ever uploaded to CPAN: Perl6::Doc, so you can grok perl 6 too. More info about that on my Perl 6 related blog.

Last weekend i was in Bonn at Froscon standing at perl booth, giving a talk about perls testing modules and we were talking there about educational material. I say education not PR. Because if there was a satan, pr is one of the best evidences of his existence. I speak of education in the best sense. No bragging, no flattering, no hot air. just knowledge, delivered entertaining. As part of that we want posters and slides showing perl code snippets that are eaysy readible, even to python programmers and powerfull. so lets open 4 categories. perl <5.10, 5.8<, modules and 6. I have some ideas but please send me your best lines, so that we can show it at conferences.

thank you very much.

Crypt-SSLeay 0.58

Earlier today, I uploaded Crypt-SSLeay to CPAN with much trepidation.

I am hoping that the module is in no worse shape today than when I joined the project as a co-maintainer. As I outlined in response to brian's post, I plan to work on multi-threading support for the next release.

I would also like to add more tests.

If you use this module (i.e., if you use LWP or WWW:Mechanize with HTTPS), please try out development versions in the upcoming weeks and report bugs.

Help newbies, your project and the community - README

If you want newbies to help you with a project - in fixing code, writing tests or even documentation - my course students will be given a course completion project to help out an open source project. That project can be yours!

Background:
I've been very inspired by DJB (Daniel J. Bernstein) and his course on UNIX Security Holes. The highlight to me was how his students interacted with the outside world - something I personally never did while studying programming (or anything else, for that matter) at school. I saw two of my brothers go through their degree (computer science, biology), helped with their homework and even attended some classes. They too never interacted with the outside world! I decided I want this changed in my course.

Javascript: adding a unique ID to every object

This entry is about Javascript, not Perl. It's about object identity in particular.

If you have two objects in x and y, you can check whether they're really the same object with x === y. However, as far as I know Javascript provides no way to get an object's address (which you could use as a key in a hashtable or whatever). The following code attempts to fix this problem by adding a unique ID to every object (and I do mean "every"):

Ponies are the truth

Did you know you can modify perl's readonly constants for undef, true and false? Yep.

&Internals::SvREADONLY( \ !!1, 0 );
${ \ !!1 } = 'ponies!';
&Internals::SvREADONLY( \ !!1, 1 );

print !!1; # ponies!

Same thing for \ undef and \ !!0.

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.