Sitemap? Dancer has it!

While I should be blogging on Lacuna Expanse, I actually wanted to write a small bit about Dancer, the Perl web micro-framework.

Yanick - who you might know either from his amusing Shuck and Awe or from his CPAN contributions - has written up a post on providing Catalyst with a Sitemap.

If you're using Catalyst, this is pretty sweet.

If you're using Dancer, there is already a small plugin someone wrote (as his first CPAN upload) called Dancer::Plugin::SiteMap which provides the same idea by adding:

use Dancer::Plugin::SiteMap;

to your code.

P.S.:
I personally love Catalyst and use it on several large-scale projects. If you don't know it, you should!

Coping with double encoded UTF-8

A few months ago a client asked if could help them with a "double encoded UTF-8 data problem", they had managed to store several GB of data with "corrupted" UTF-8 (technically it's not corrupt UTF-8 since its well-formed UTF-8). During the process I developed several regexs that I would like to share and may prove useful to you someday.

Due to the UTF-8 encoding usage of prefix codes it's easy to spot a double encoded UTF-8 sequence, the prefix code is within the range of U+00C2 to U+00F4, followed by one or more continuation codes within in the range U+0080 to U+00BF.

The above translated to a regex:

Lacuna Expanse

While I'm not much of an online gamer I thought I would try out Lacuna Expanse.

It's only been running about 2 weeks now so it's a good time to get in on the ground floor.

http://www.lacunaexpanse.com/

It's even written in Perl.

I blame Adam for getting me involved...and JT.

gizmo

The Lacuna Expanse

So I heard about The Lacuna Expanse http://www.lacunaexpanse.com here on blogs.perl.org the other day when Jesse Thompson posted about it. It's a "massively multiplayer strategic empire simulator" written in Perl.

I started playing last night after work. I choose the rather unimaginative empire name of "Mr. Muskrat's Empire". I renamed my colony "Luas".

The GUI is very polished looking. The graphics are very detailed for a browser-based game. You have multiple zoom levels to choose from. I typically keep it zoomed all the way out unless I want to the see new details of buildings as they are upgraded.

They are running three contests (at last count). I entered the volcano contest and already received my volcano! I won't tell you what it does but you might want to enter fast before all ten are gone. I am entering a second one as I type this up; I want the Kalavian Ruins because they look a lot like the Colosseum (and I really want to know what they do).

So head over to http://www.lacunaexpanse.com and sign up for your free account and begin playing. Then head over the forums http://community.lacunaexpanse.com/forums and find out how to enter the contests.

Kephra 0.4.4 on the verge

I fixed some nasty bugs lately and get these days ready for the next testrelease. Im happy that this release brings also some new features. And I don't mean new for Kephra, but literally unknown to many editors. and in this episode I will highlight just 2 of them.

I already mentioned, that if you select a text by holding the left mouse button and while its still pressed you push the right too, the text gets deleted (opposite of acme). Now i just seperate the direction you selected it. If its from left to right, its cuts, meaning remember in the clipboard. if you do it backwards, its not (function called clear.). In times you still have something in the clipboard, that might come very handy. I found this kind of editing very fast and I like it the more i use that.

How the other half lives

Here’s a bitter, but very accurate description of what goes for open community development in the realm of .NET (Thanks, Merlyn!). It’s a pretty sad state of affair, and I can attest for at least some of it, mainly:

”Last year Microsoft released a new web framework called MVC. It’s not new by web standards … Yet people were waiting for it. People were waiting for Microsoft to deliver it to them.”

”Microsoft themselves … are so cleverly changing just fast enough to keep developers from solving problems themselves.”

And this also goes for faulty “standards”. Some half-baked ideas (like the Microsoft .NET remoting framework) are getting implemented into core systems before someone, Microsoft or else, realises that these are the technical equivalent of horse manure that spent several days in the sun, and now, not only that they are stuck with it, but Microsoft is no longer providing support for their festering framework of scum and villainy.

Lets play Lacuna Expanse

While normally I never play Facebook'y web games like Farmville, clearly an exception should be made for Lacuna Expanse, especially since it's made with Perl and since it's only been running for 2 days, we can set up a nice little Perl posse in the very first week and rule the universe!

(Evil laugh follows, echoing and trailing into the distance)

(I am contactable with the rather unimaginative empire name of "Adam")

This game probably also marks the highest volume and potentially most high profile user of Email::Stuff (one of my favourite little creations) outside of myself and Ricardo who now maintains it.

http://www.lacunaexpanse.com/

As a small bonus, the game seems to be the Farmville equivalent of EVE Online, which is at least a familiar genre for me :)

Learning Perl sells decently well, even in eBook formats

It's royalty report time, so the mailbox was full of checks this week. I keep close tabs on how well my books do so I can figure out if the time to write the books would have been better spent making fancy coffees at Starbucks. I think I'm slightly ahead, but only slightly.

However, I noticed that the total revenue for Learning Perl, 4th Edition is very close to $1,000,000 for the 20 quarters it has been available. And, curiously, it's getting closer to that number even though the latest edition has been out for 9 quarters. Who's still buying the old edition?

Even better, though, the Fifth Edition is already over $500,000 in total revenue. Now, only a small slice of that gets to the authors, especially on a title with multiple authors, and that only comes four times a year over several years. My cut of Learning Perl, 4th Edition is only 1%, so I'm not buying any Bentleys.

Sometimes you *don't* want circular checking

I use the nifty Data::Rmap to "flatten" DateTime objects into strings so they can be exported to JSON and handled outside Perl. But due to circular checking in Data::Rmap, this:

$ perl -MData::Rmap=:all -MData::Dump \
-e'$d = DateTime->now; $doc = [$d, $d];
rmap_ref { $_ = $_->ymd if UNIVERSAL::isa($_, "DateTime") } $doc;
dd $doc'

produces something like this:

["2010-10-01", ...unconverted DateTime object...]

For now I work around this by defeating Data::Rmap's circular checking, though I wonder if there's a better way.

$ perl -MData::Rmap=:all -MData::Dump \
-e'$d = DateTime->now; $doc = [$d, $d];
rmap_ref { $_[0]{seen} = {}; $_ = $_->ymd if UNIVERSAL::isa($_, "DateTime") } $doc;
dd $doc'

will correctly produce:

["2010-10-01", "2010-10-01"]

Mangling CPAN with Plack::App::Proxy

If you want syntax highlighting when viewing docs and source at search.cpan.org, you don't actually need to use Greasemonkey. You can do it with Plack and be up and running in just a few minutes.

Last night I gave a lightning talk about this at Toronto.pm and I've just posted the slides

Basically, all you need to do is this:

---
git clone http://github.com/ioncache/Plack-Middleware-HTMLify.git
git clone http://github.com/oalders/cpan-mangler.git

cpanm Plack Plack::App::Proxy Plack::Handler::Twiggy

cd cpan-mangler
plackup -I../Plack-Middleware-HTMLify/lib
---

Once you've got that done, just point your browser at http://localhost:5000 and use search.cpan.org as you normally would. It's the same site, only prettier. Now, it's not perfect, but it's a fun idea. Using the proxy setup you can bend the site to your will and add or remove features as you see fit.

cpan-pod-after.png

cpan-source-after.png

What's in a name?

For my recent projects, I've been using Dist::Zilla and enjoying its very advanced features. The reason I've never used it before? I thought it had a silly name. I still do, in fact, just that I managed to ignore the silliness enough to find out it incorporates some major wins.

Another project I overlooked is KiokuDB. I was looking around for a non-relational/Object-based/Document-based Database (aka NoSQL), and kept overlooking KiokuDB for two reasons; first, KiokuDB is a front-end to several different back-ends, including RDBMS like MySQL and Postgresql, making me unsure whether it is a true object-based DB, or just a glorified ORM, and second, it has a silly name.

I solve another big set of problems for MyCPAN

I knocked off another big chunks of distributions that MyCPAN didn't like. I worked on the 700 or so dists that it couldn't unpack, and that number is now down to about 30. The changes to my method weren't that dramatic, but it clears up a bunch of the problem dists.

First, I was stopping too soon. Many archives unpack just fine even if they give warnings. Now I'll just record the warnings and wait to see if I get a directory with some files in it.

Second, I was using an HFS case-insensitive file system (stupid, but it's the default). Many distributions did not like that. Moving everything to a case-sensitive file system solved many of those problems. Once I find out why Foo-Bar-0.01.tar.gz doesn't unpack, I usually solve the problem for all Foo-Bar-* series which probably had the same problem.

Littlest uuencode

Hi, For your amusement, here's a very small uuencode program.

perl -0777 -e '$uue = pack u, <>; print "begin 0644 $ARGV\n${uue}end\n"' your-file.bin

Perl-based Massively Multiplayer Online Game

JT Smith and his crew have created a massively multiplayer online game called the Lacuna Expanse. The game is great, but the coolest part is that the back-end is written entirely with Perl!

JT unveiled the game and the underlying technology at the latest Madison Perl Mongers meeting.

Amsterdam

I've mentioned this elsewhere, but I thought it was worth mentioning here: my wife and I are moving to Amsterdam next month. After three lovely years with the BBC, I'm giving in to the temptations of Amsterdam and booking.com. Here comes a new adventure!

A `tail -f` in BBEdit.

I knew BBEdit would update open files when they changed on disk, but I never thought to try that with a continually updating file. It works. You just have to have the file open. No big whoop.


Yet another stupid mistake #1

During a refactor of a data from array @foo to hash %foo, I used 'each' to iterate over the hash, but forgot to change the 'for' statement with 'while'. So I ended up with something like:

$ perl -MData::Dump -E'%a=(a=>1, b=>2);
for (my ($k, $v) = each %a) { $_ = "$k x"; dd {k=>$k, v=>$v, "\$_"=>$_} }'

And this is nasty because for(@ary) aliases $_ to each element in @ary, and in this case it modifies $k (quiz #1: and $v too, do you know why?) right under your nose! Thus the result are really messed up:

{ "\$_" => "a x", "k" => "a x", "v" => 1 }
{ "\$_" => "a x x", "k" => "a x", "v" => "a x x" }

Not to mention the loop stops after processing two items (quiz #2: do you know why?) But you might not realize that after you add some pairs to %a and wondering why they don't get processed.

The error message Perl gives is not really helpful, to say the least :)

Hackathon


We'll have another hack session at Quetzal Internet Cafe in the
middle of October. The location is close to Civic Center BART,
and the 38, 47, and 49 bus lines. Come bring you laptop and hack on your
favorite CPAN module, and chat with fellow SF.pm Perl Mongers.

Announcement posted via App::PM::Announce

RSVP at Meetup - http://www.meetup.com/San-Francisco-Perl-Mongers/calendar/14948010/

One-liner XML / Perl / JSON

castaway blew my mind this morning in irc.perl.org #axkit-dahut.

Convert an XML file to Perl data structure:

perl -MXML::Simple -MData::Dumper -le'print Dumper XMLin("foo.xml")'

Convert an XML file to JSON:

perl -MJSON::Any -MXML::Simple \
   -le'print JSON::Any->new()->objToJson(XMLin("foo.xml"))'

"How do I do X?" Like this! Poof!

Some days Perl feels like a Las Vegas magic show. :)

Reading META.yml when it's not UTF-8

Part of the 3% of the distributions I couldn't index with MyCPAN had encoding issues. YAML is supposed to be UTF-8, but when I don't always get UTF-8 when I generate a META.yml for files that don't have one. I guess I could do the work to poke around in Makemaker, etc, to convert all the values before I generate the META.yml, but um, no. Not only that, not all of the META.yml files already in the dists are UTF-8. Remember, however, this is a very small part of BackPAN: about 700 distributions out of 140,000 (or about 1/7th of my problem cases).

A couple hundred distros have Makefile.PL files encoded as Latin-1 in a way that it matters. If it's not collapsable to ASCII, the META.yml ends up with Latin-1 in it. Some YAML parsers refuse to deal with that.

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.