Some nifty things you can do with Catalyst on Plack

Catalyst 5.9 is coming up, and the big change is a wholesale switch to PSGI, completely dropping Catalyst’s own engine system (outside of compatibility shims). This is bound to bring in new people wondering what PSGI and Plack are all about and what you can do with them.

I’ve been using Catalyst on top of Plack for a while now (with the aid of Catalyst::Engine::PSGI) and have gotten around to some nifty things with it. So here is my app.psgi for inspiration:

Carbon Emacs and Samba shares

Lastly I tried to access files on a Samba share (running on a Debian machine) from Carbon Emacs running on Snow Leopard. The files where in a git-repo, so vc-git tried to do his stuff. This made Carbon Emacs hang while creating .#file.pm linked files. flymake had the same issue. So instead of disabling vc-git and flymake, I searched the internet.

The problem got solved by adding this line to the [global] part of the smb.conf file:
unix extensions = no

Yenta - a highly-available key-value store

I have uploaded the source code for Yenta, our highly-available key-value store to CPAN.

Yentas operate as a peer-to-peer network (there is no "master" node). Nodes use gossip based protocols for distributing membership + status information. Put() operations distribute data in a network-topology aware manner. Eventual consistency is achieved by data versioning and gossiping merkle-tree hash values.

At Solve Media, our web-site partners depend on our technology. If we go down, they go down. Yenta is one of the technologies we use to ensure our high availability at scale.

enjoy!

Convert FLAC to MP3 on OS X for iTunes

Sorry. No Perl in this post, but this appears to be such a common problem that I've decided to write up a simple description of how to convert FLAC to run in iTunes.

FLAC is the "Free Lossless Audio Codec". It's a fantastic file format, but there are a couple of issues. First, songs typically run 25 to 40 megs per song. This means that they take up roughly 10 times the hard disk space as a corresponding MP3. For extremely large music collections this could be a problem.

The other problem is that Apple has chosen not to support FLAC for iTunes. I tried many solutions listed online, including Xiph and Fluke and got nowhere. Finally I decided it was time to go "old-school" and fall back to the command line.

I downloaded the FLAC tools and installed them. That gave me access to the flac program. Then I installed the LAME MP3 encoder. I used MacPorts for the latter, but you can get it from the Sourceforge link I provided.

Plack - give it a go... and white paper

Having had Plack on my 'to looking to list' for a long time we've finally started using it at work. Yet again here is another of the 'modern perl' pieces of software that once you start using you'll wonder how you ever coped without it.

As first it doesn't seem like you have much that wasn't done in Apache (or what ever web server you are using). The moment you realise that you can put everything that was in Apache (rewrite rules, expiry headers, serving static content) into your app.psgi (web application configuration) file and that this will then run under any of the many supported web servers the light bulb goes on.

You can then try Starman or run everything using plackup in your development environment.

The simplicity of Plack's structure $ENV in, [ status, [ headers ], [ content ] ] out makes writing middleware easy and adapting your code to use this standard very clean (even if you don't use one of the many frameworks which already directly support Plack).

I've also added a white paper on Plack to Perl.org.

Why I Stuck With Perl

I've just read a very thoughtful description of why one Perl programmer switched to Python. In this blog post, I'll explain why I did not.

When I started on the Marpa project, Perl was not an automatic choice. In fact it looked like it might be the wrong one. There was as much buzz for Python then as now. Maybe more. I'd had my own experience with Python, and it was excellent. I'd used Python to create a threaded mail client for testing purposes. I found Python to be easy to learn, fun to use, and an effective way to accomplish my task.

Perl had another problem. An important audience for Marpa, my new parser, is academia. Academics certainly use Perl. My experience is that they even respect it in a certain sense. But Perl does not fit neatly into the minimalist paradigms which still rule academia. If you speak Perl to academics, you are not talking their language. That means you run a great risk that nobody will listen.

Give a talk at FOSDEM

So, FOSDEM is approaching. If you don't know what FOSDEM is, it's a very big European technology conference, taking place in Brussels, Belgium. Usually it deals with generic topics, such as "systems administration", "BSD", "GNU", "accessibility" and such, but this time Gabor Szabo was able to secure a devroom specifically for Perl!

This is a great opportunity in presenting Perl both to more mongers, but also to the external geek community (outside of Perl Mongers, CPAN authors, and other Perl community members) and showcase some of our stuff.

People have volunteered and we're going to have a few really cool talks: Moose, Dancer, PEG, Packing Perl, Tracing Perl with DTrace/SystemTap, Template::Zoom, SPORE and Padre are just some of the talks you'll see.

However, we still have a few slots open, so please do submit a talk if you're coming!

And remember, if you see me there, don't be afraid to step up and say hi, because I'll probably be too shy to do it! :)

Update: to submit a talk, contact me via xsawyerx AT cpan DOTT org.

What's "a good book about programming for Unix"?

What's a good book about programming for Unix? In Learning Perl, while showing the file test operators, we say:

Don't worry if you don't know what some of the other file tests mean--if you've never heard of them, you won't be needing them. But if you're curious, get a good book about programming for Unix.

But, we then leave the reader hanging without giving them an idea which book they might. I guess Chapter 4 of Stevens's Advanced Programming in the UNIX Environment might be the answer, but is there something else?

Perlbal - load balancing white paper

I've added a new White paper to Perl.org: Perl load balancer - which is really there to make people aware of Perlbal.

Thanks to a TPF Grant there is now actual Documentation which really makes using it a whole lot easier! I've had this in production for about 4 years now and it's very stable. Being able to change which servers (or ports) your entire sites traffic goes to make gradual rollouts (and quick rollbacks!) very easy. It also makes upgrading your servers far less complex.

If your not already using a web load balancer infront of your web server check it out!

What's New in WebGUI 8 #2: Auth Improvements

Auth changes

WebGUI::Auth was developed as part of 6.0.0, back in 2003. To put that into perspective:

  • Auth predates Facebook, which was founded in 2004.

  • Since Auth, there have been two Summer Olympiads.

  • Auth was written when I was still in college.

Since then, it has not fundamentally changed, though everything about the Internet surely has.

We began our planning for 8.0 with the idea to completely rebuild Auth from scratch, but that quickly got scrapped when we realized both the scope of that project. But since Auth is one of the most visible parts of a WebGUI site for the end-user, who must be able to quickly and simply create an account and log in to participate in the community of your website, we decided to take a closer look at what we could do to improve the Auth API.

What resulted were a series of small changes (and only one break) that has made it far easier to create convenient choices for your users.

Multiple Methods

Using each() to iterate over an array

In perl 5.12, each() - as well as keys() and values() - works on arrays, where previously these functions were restricted to hashes. When iterating over an array, each() returns both the index and the value.

my @x = 50..59;
while(my ($i, $v) = each @x) {
    say "index $i, value $v";
}

will print:

A Perl interface for sharktools

Sinan Ünür created a first pass at a Perl interface to sharktools so you can have all the fun of Wireshark right in your Perl program. Why should Java and Python have all of the fun while analyzing network traffic?

I'm paying him to do it because I need it for a project and he's much better than I am at that sort of thing. However, I bet a lot of other Perl people would find it useful, so we're making it open source. Sinan already set up the github repository, and eventually that will make its way to CPAN as Net::Sharktools under the Artistic License.

If you're interested in helping with the project, don't be shy. As with most projects, we can always use help with testing or documentation. I know some of you out there have Wireshark expertise. It doesn't bundle the rawshark stuff (so far). Anyone want to make an Alien distribution for that other stuff?

Padre 0.78 has been released - the late announcement...

Well, for those of you who have installed Padre from CPAN recently or who upgrade frequently, will know that Padre is now on CPAN and it's at version 0.78.

I've been rather slow getting back into the swing of things after the Christmas break, so after rolling out the release, I promised to myself that I'd get the announcement done the following night, only to become distracted with pretty much everything and anything else.

So for those of you who actually track changes to Padre via these announcements, my apologies for my apathy.

To be honest, I really thought that development might have taken a bit of a back seat over the break, however the Changes file indicates this isn't the case, even with Adam Kennedy being busy coding on a project in SDL that Kartik Thakore some how goaded him into. ;)

So the quick summary for Padre: "Making Padre play nicer when working with projects on locally mounted remote filesystems" - Adam Kennedy #padre.

Template Toolkit and Emacs

I am messing around with Template::Toolkit. Found the Emacs mode for template toolkit written by Dave Cross : https://github.com/davorg/tt-mode

Put the file tt-mode.el somewhere in your Emacs path and add these lines to your .emacs config file:

;; tt-mode
(load "tt-mode.el")
(setq auto-mode-alist (append '(("\\.tt$" . tt-mode)) auto-mode-alist ))
(setq auto-mode-alist (append '(("\\.tt2$" . tt-mode)) auto-mode-alist ))

works like a charm. Thank you Dave !

Caching multi-statement computations using an anonymous subroutine

Suppose that a subroutine gets called several times and that in the subroutine you need to use some computational result that stays the same for every call. You could use a state variable or an our variable.

sub foo {
    # ...

    state $some_value //= ... some computation ...;

    # ...
}

Using the defined-or operator, the value will only be computed the first time the subroutine is called.

But what if the computation takes several statements? You could move it to its own subroutine and call it with a single statement, or you might resort to something like:

Debugging in the (Very) Large

Debugging in the (Very) Large describes Microsoft's challenges in implementing Windows Error Reporting. Those challenges include TBs of data, 1 billion+ computers running WER, and multiple entities accessing that data (anyone that can afford a VeriSign certificate can use WER for their own Windows applications and drivers). Worth a look (hey, it is even a SIGOPS paper).

warnings::unused versus PPI

I had the following in my .bash_aliases file:

alias unused='perlcritic --single-policy ProhibitUnusedVariables'

However, I found a few cases where it didn't work. That's when mithaldu told me about warnings::unused. I installed it locally and ran it on some code which had a case that ProhibitUnusedVariables didn't find:

$ unused $some_module
$some_module source OK
$ perl -Mwarnings::unused -c $some_module 2>&1 | wc -l
34

Whoa! The one area were Perl::Critic modules repeatedly break for me is when I'm dealing with scope issues. It appears to miss where a variable is legitimately declared and used in one sub, but declared and unused in another. It also missed something like the following:

The Puneet of the Dancer Community

There are definitely more and more people involved with Dancer which makes me proud.

Alberto Manuel Brandão Simões (ambs) has been putting a lot of development work into Dancer recently, improving it in ways we haven't even thought about. Flavio Poletti has been also offering some commits, and more importantly, takes the time to help newbies within the Dancer community (successfully, might I add!) and we can see more and more new-comers giving us good feedback and pull requests.

However, as much as all the aforementioned people deserve their own posts for their work (which isn't just the code, but the motivation they give others), this post is about someone else. A person by the name of Puneet Kishor.

Puneet has been a member of the Dancer community for a long while now. He has been writing quite a bit on the mailing list, and raises a lot of inquiries, possible bugs, feature suggestions and general issues such as recommended writing methodologies.

Useful Links

Here are some useful resources.

Khan Academy If you have or know any children who are in school, this is an awesome resource, Sal is an excellent and talented teacher . The video's are ten minutes in length and of very good quality.

This Javascript exercise by John Resig ( Jquery creator) is a good way to learn some advance javascript

This Clojure article is a pretty good way to get your feet wet in getting started with Clojure programming.

If you want to get started with HTML5 this is a pretty good book , You can also order a print version here

WebService::Yahoo::BOSS open sourced

My employer kindly (and prudently) gave me the go ahead to open source our interface to Yahoo's awesome search API. First release version is crude, but it works. Patches welcome. I just pushed 0.03 to PAUSE, so it should be available at a CPAN mirror near you shortly.

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.