Currying

I'm working on learning what currying can be used for. I tried at first to install from the cpan shell on my WinXP netbook, but this failed a large chunk of testing and I didn't bother attempting the install. PPM did the job, however, and after confirming the install is good, I have moved to flipping between reading HOP and trying code out.

Birmingham.pm Tech Meet, Wed 28th July

Event:   Birmingham.pm Technical Meeting
Date:    Wednesday 28th July 2010
Times:   from 6pm/8pm onwards (see below)
Venue:   Birmingham Science Park Aston, Faraday Wharf, Holt Street, Birmingham, B7 4BB.
Details: http://birmingham.pm.org/tech/next

Talks:

  • Into the Black: Exploring North Korea (or, how I learned to stop worrying and love the bomb) [Mike Kemp]

Details

This month's meeting will be at the new tech meet venue, over at The Birmingham Science Park Aston. Car parking is available, as is wifi and pubs nearby :)

Announce: Rakudo Perl 6 development release #31 ("Atlanta")

Announce: Rakudo Perl 6 compiler development release #31 ("Atlanta")

On behalf of the Rakudo development team, I'm happy to announce the July 2010 development release of Rakudo Perl #31 "Atlanta". Rakudo is an implementation of Perl 6 on the Parrot Virtual Machine (see http://www.parrot.org). The tarball for the July 2010 release is available from http://github.com/rakudo/rakudo/downloads.

Please note: This is not the Rakudo Star release, which is scheduled for July 29, 2010. The Star release will include the compiler, an installer, modules, a book (PDF), and more.

The Rakudo Perl compiler follows a monthly release cycle, with each release named after a Perl Mongers group. The July 2010 release is code named "Atlanta" in recognition of Atlanta.pm and their Perl 5 Phalanx project, which they selected for its benefits to Perl 6.

Some of the specific changes and improvements occurring with this release include:

Module Authors Wiki?

I really like the Perl QA wiki. Is there something similar for Perl module authors? I'm looking for updated information on name recommendations (and don't say to send a message to modules@perl.org because the "official" list says it's a closed list), tools to help create new distributions (I haven't been able to install Dist::Zilla yet, I'm working through it's long list of dependencies), and any other suggestions that module authors might need.

The mod_perl debugger you've always wanted

To use the nice mod_perl debugger you've always wanted:

To connect the two and start up your apache with no fuss:

Simple symbol overriding for tests

When testing a subroutine, it might interact with another subroutine. A useful trick is "mocking", which is to provide a given answer back from that subroutine, helping you imitate some situation for your subroutine to run into, and for you to test.

There's a very easy way to do this:

{
no warnings qw/redefine once/;
*My::Object::connect = sub {
ok( 1, 'Reached connect' );
isa_ok( $_[0], 'My::Object' );
is_deeply( $_[1], { something => 'else' }, 'connect method params' );
};
}

This is a very simple and relatively controlled way to override the subroutine in the symbol table. It is usually what I use.

If you prefer not to play around with the symbol table yourself and leave it to the professional, there's always chromatic with his excellent Test::MockObject which is great for this particular purpose and both you and I should be using it. :)

I'll probably switch over back to it sometime.

Update: whoops, forget the "local". :)

Perl.com - initial relaunch

http://www.perl.com/ has been relaunched! - VERY basic at the moment, but this is the start.

Tom (who owns the Domain) and O'Reilly (who's strong support of Perl over the years has helped make it such a great language) have been kind enough to let the TPF take on Editorial control and the site has now joined the Perl.org family.

As you can see initially we've ported the existing content over (but still need to link it all in to make it easy to find) - Chromatic aims to have a least on post a week about the Perl language, it's libraries, and the great community surrounding Perl.

Basically watch this space - or rather watch http://www.perl.com/!

Design implications of MI strategies

While doing research for my OSCON talk on roles, I was struck by something very interesting. You could, if you wish, group OO languages into multiple inheritance and single inheritance camps. Languages like C++ and Perl, which allow multiple inheritance, generally have taboos against it. As a result, experienced developers create designs which allow them to avoid multiple inheritance.

Single-inheritance languages, such as Ruby and Java, tend to offer language features to substitute for the lack of MI (e.g., mixins and interfaces). For these languages, use of these features is encouraged and hyped, as opposed to MI being discouraged and avoided. I'd be rather curious to know how this impacts the software design trends in those languages.

Using Skels

This time I am writing mainly for beginners, and not specifically for Perl programmers, but any programmer of any language. Skels (my abbreviation for skeletons) are totally relevant in a programming environment.

What are skeletons? There are different names for the same thing. You can call it a template, or call it a snippet. Skels, for me, are both: pieces of code, that might work or not, that might have placeholders or not, but that save you time by remembering how something is done.

I have a bunch of skeletons ready to use in my Emacs. I would like to have more, but sometimes I am too lazy and forget that with skeletons I can be yet more lazy. Some examples of skeletons: the line used in XML to refer to an external CSS file; an empty HTML document; an empty LaTeX document with the more usual packages; a LaTeX presentation document; a common POD document structure; etc.

This can be done in different ways. TextMate let you start typing something, press tab, and get your snippet expanded. I am sure vim, komodo and other editors have similar mechanisms. The important is not what editor to use. The important is to have the skeletons ready to use.

Pod to ePub to iBooks

Olaf Alders's recent post about CPAN on your iPhone gave me the impetus to look at an idea I had after iBooks became available on the iPhone and iPad: to convert Perl Pod documents to ePub format for offline reading.

So I created a simple pod2epub program and here are the results along with some free books from the iBooks store:

ibooks01.png

The screen shot shows the Moose::Manual and Spreadsheet::WriteExcel documentation converted to ePub and transferred to iBooks on my iPhone. Here is a sample from the Moose::Manual ebook:

ibooks02.png

And here is another with some code:

ibooks03.png

All of the heavy lifting was done with the stalwart Pod::Simple and Oleksandr Tymoshenko's comprehensive EBook::EPUB.

I still have a few issues to resolve and formatting to tweak and after that I will upload the code to Github and then to CPAN

Parrot 2.6.0 "Red-rumped" supported release.

What we call the beginning is often the end
And to make an end is to make a beginning.
The end is where we start from.
--T. S. Eliot, Four Quartets

On behalf of the Parrot team, I'm happy to announce Parrot 2.6.0 "Red-rumped." Parrot (http://parrot.org/) is a virtual machine aimed at running all dynamic languages.

Parrot 2.6.0 is available on Parrot's FTP site, or follow the download instructions at http://parrot.org/download. For those who would like to develop on Parrot, or help develop Parrot itself, we recommend using Subversion on the source code repository to get the latest and best Parrot code.

SHA digests for this release are:

372d46f36308ef358e148c380344bf7ae1ddff9ea6c35799bfda9ada3eea88ae  parrot-2.6.0.tar.bz2
ab2c5f7249cfcecb42cf9ef355098c904c861a1f7736ad81209f7bcca2096652  parrot-2.6.0.tar.gz

Comprising about 4 weeks worth of development, this release contains code from 25 authors across 202 files.

The following people have contributed to this release of parrot:

Not Quite Getting It

Stories of obfuscated Perl written by incompetent people (or sadists) are legion. But sometimes you come across some code that appears as if it was mostly written by someone who knew what they were doing, but seemed to be missing some crucial bit of information.

Today I saw a set of OO Perl packages that appeared perfectly cromulent, until I noticed that every method call looked like this:

Watching directories for new files

Linux::Inotify2 is great for detecting newly created files in a directory. You can watch a directory by simply using:

use Linux::Inotify2;

my $inotify = new Linux::Inotify2;

$inotify->watch($dir, IN_CREATE, \&handle_new);

sub watch_new {
    my $e = shift;

    print "New file or dir: " . $e->fullname . "\n";
}

This will execute the callback function hande_new everytime a file is created in $dir. The function will simply print the new directory or file name created.

Unicode abuse

I was looking at doing a little bit of political activism on twitter, and as part of this, though about maximising the amount of information in each tweet a la Tweet Compressor which is an abuse of unicode to increase the 140 character (not byte!) limit for tweets.

Here's the implementation:


use utf8;
sub tweet_compress {
my $tweet = shift;
$tweet =~ s/\. ?$//; # we don't need no end of sentence punctuation
my @orig = ( qw/cc ms ns ps in ls fi fl ffl ffi iv ix vi oy ii xi nj/, ". " ,", ");
my @new = qw/㏄ ㎳ ㎱ ㎰ ㏌ ʪ fi fl ffl ffi ⅳ ⅸ ⅵ ѹ ⅱ ⅺ nj . ,/;
$tweet =~ s/\Q$orig[$_]\E/$new[$_]/g for 0 .. $#orig;
return $tweet;
}

Doing the rest of the right thing with unicode is a bit annoying (e.g.
binmode STDOUT, ':utf8';
to output the tweet correctly to stdout), and I really wish there were better unicode docs that didn't have high cognitive load .

Rakudo *'s Really Really Release Ready

How do you know when a new programming language is ready to be released? You try porting a real software framework to it. I recently completed a port of a Perl 5 framework to the Rakudo implementation of Perl 6, and guess what? It just works! This is my story...

After only a short ten year wait, a Perl 6 implementation is scheduled for release this month. Rakudo * (aka Rakudo Star) will be inaugurated on July 29th, 2010. Is it ready? That certainly depends on your expectations, but I am here to make the case that it is a usable programming language with at least one killer feature that will interest programming language addicts (like me).

I am an Acmeist Hacker, which is to say that I only like to work on projects that serve many programming languages. I have lots of these projects: YAML, TestML and JSYNC are three that I have been actively hacking on recently.

Following convention across language boundaries

I've been meaning to write this post for a while. I'd like your opinion on it.

In my last post [0] I touched on the question of following the Python ctypes API in the context of Type objects. The issue of how closely to stick to the Python API has come up a few times. There just bits and pieces I'm not wild keen on. The whole WINFUNCTYPE / CFUNCTYPE function prototype factory thing [1] for callbacks is a good example (in our implementation creating callbacks is as simple as my $cb = Ctypes::Callback->new(\&perl_func, <returntype>, <argtypes>);).

Who is the audience?

The argument for of course is the assumption that some of the first and most important users of Perl's Ctypes module will be C library authors or porters who already have a Python binding and will be interested in doing the same thing for Perl. Obviously if the Perl Ctypes implementation followed Python's 100% then the friction for those users would be low as possible and we might get more library bindings written sooner.

I've uploaded my Mastering Perl slides to the OSCON website.

I've uploaded my Mastering Perl tutorial slides to the OSCON website.

Introducing Catechesis

I love testing. I like to know, to the greatest degree manageable, that the code I have written does what I think it does. I love testing in Perl because there's a selection of tools available which is broad and deep. I wish the implementors of other languages would take a look at the Test:: and Devel:: sections of the CPAN and steal some ideas, really.

Recently I found myself designing a message-passing framework, and I decided that I wanted to at least have Perl 5, ObjC, Python, and Javascript implementations. The arguable sanity and hubris of this aside, it brought up an interesting problem in the domain of testing.

Monthly Meeting Report Of July

Yesterday, on Monday 19th of July we had our reoccuring Perl-mongers group meeting. Due to refurbishment we went to a different restaurant this time.

We were eight Perl programmers and every one of them primarly declared their participation on Doodle. Yes, we use Doodle to coordinate our meetings but we came up with the idea of implementing an online planner software by our self. Maybe this is the project one of us needed to get started with mojolicious.

We also spoke about who is going to YAPC, who is arriving when, and in which hotel do our fellow mongers stay. We also made some kind of plans for the 3rd of August when some of us want to do some site seeing in the afternoon until the preconference meeting starts. Maybe You want to come along with us to, we are looking forward to meet you.

And we also did some jibba jabba about our personal lifes, about physics, mechanics and electronics and other stuff more or less far from Perl. And we had quite some fun and a good meal.

Using magic hash key transformation

Since version 5.10, perl has the ability to magically transform keys on a hash. This feature was added to make fieldhashes possible, but has more uses. Here I'll show you how to do in using Class::Private as an example.

Loading the XS

package Class::Private;

use 5.010;
use strict;
use warnings;
use XSLoader;

our $VERSION = '0.05';

XSLoader::load('Class::Private', $VERSION);

1;

As you can see, there's not much to the Perl part of this module, it loads some pragma's (the 5.010 is important because this feature will not work on older versions) and then loads the XS.

Casting the magic

SV* new(class) SV* class; CODE: HV* hash = newHV(); sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (const char*)&hash_filter, sizeof hash_filter); RETVAL = sv_bless(newRV_noinc((SV*)hash), gv_stashsv(class, GV_ADD)); OUTPUT: RETVAL

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.