So, you're deep inside of a series of functions and you find that you really, really want what is effectively a goto: that is to say, you want to jump right out of all of those functions to the top level. Many people think "aha!, I'll just throw an exception."
Years ago, many Java programmers used to do this (of course, Exceptions are first class in Java). To paraphrase Mencken, it was simple, easy, and wrong. As understanding grew of how exceptions should be used, it was learned, surprisingly to some, that exceptions should be used for exceptional conditions. One rule of thumb was that exceptions (like aspects later) should be reserved for code where, in theory, if nothing went wrong, they could be completely removed without affecting the program's correctness. So you might throw an exception if you fail to open a file, but if you're iterating over the lines in that file (and if it's OK for that file to have no lines), then you don't throw an exception just because you've reached the end of the file. EOF is expected. Failure to connect is not. Unfortunately, failure to understand failure caused some horrible knock-on effects.
Recently I've spent more time with Dancer development, since it's such a fast, fun and flowing project. I've written Task::Dancer (after bugging a few people on #toolchain - thanks daxim!), Dancer::Template::Tiny and even patched Dancer::Template::Tenjin (and thanks to Ido for released it so quickly!).
Once thing I recently implemented in Dancer is Route Caching. Route Caching is a new term - at least for me - since I don't remember seeing it elsewhere (though I wouldn't be surprised if it's implemented in other frameworks).
When Dancer gets all the routes you want, it compiles them into regular expressions in a registry and then matches each request against the compiled routes, returning the first match. Route Caching allows to cache the path matches.
This version is completely rewritten to to make it easier to extend later (more like one big dispatch table), and has improved debugging, usage messages, errors etc.
Try: (with a server running on localhost)
use ElasticSearch;
my $e = ElasticSearch->new(
servers => '127.0.0.1:9200',
trace_calls => 1,
);
$e->nodes;
Today I released Text::BibTeX 0.40_3. I hope it to be the final release (that is, 0.40 will get out with the same code). But I just tested it with Strawberry Perl, Linux (Arch Linux) and Mac OS X (intel, Leopard).
We can't test on all available architectures, and that's why CPAN Testers exist. Long live to them. But sometimes it would be cool if we could use a machine and do some experiments before releasing. Waiting for the module to be picked and tested is not an efficient method.
It would be cool to create a set of queues (one per architecture/operating system) where CPAN authors could submit a module to be tested. The module would be installed, tested, and a report generated. It would be nice to check the current waiting list on each queue, so we can have an idea of how things will evolve.
Recently I started a new project at $work in which I'm using a lot of cool projects (DBIx::Class, KiokuDB, Search::GIN, POE and Dancer to name a few) and it involved a lot of layers so I wanted to do this one just right.
I finally started using KiokuDB and it went relatively easy, though Search::GIN is still lacking (and 0.4 still hasn't been released to CPAN, so I'm relying on the code on Github). It's amazing how easily I can write tests with KiokuDB and plug my stuff in and out. Sometimes, I have a hard time realizing it's that simple.
I'm in the process of writing a test suite for ElasticSearch.pm, but in order for it to run any tests, it requires access to an ElasticSearch cluster.
Currently, I just skip all tests unless $ENV{ES_SERVER} is set, but this requires manual installation / testing.
Alternatively, I could (if $ENV{ES_SERVER} isn't set) try to download and compile a test version, which requires git and java v 1.6 or higher. It doesn't take long to compile, but long enough so that user may not want to do it by default.
So I could ask them if they want the script to build a test server, but again, this requires manual installation.
It'd be nice to use the cpan testers to run the test suite on multiple platforms, which implies building a test cluster by default.
Some of you will be aware of one of my projects that is driven off CPAN-testers data: the cpXXXan. Well, I'm in the process of extending it. Soon it will grow a cpNETBSDan tentacle, and likewise for some other OSes. Once I'm convinced that it works and is reasonably efficient, I'll probably make it so that you can filter by both OS and perl version, using hostnames such as irix.cp5.8.9an.barnyard.co.uk.
Dancer is a simple and lightweight yet powerful web application framework which I recently discovered (and blogged about) when I was looking for a framework I'd actually enjoy using to write web apps.
A (very basic) Dancer web app can be as simple as:
#!/usr/bin/perl
use Dancer;
get '/hello/:name' => sub {
return "Why, hello there " . params->{name};
};
dance;
I adopted Text::BibTeX a long time ago and had a lot of complaints about its installation mechanism. This was mainly due to the fact that Text::BibTeX depended on a C library that needed to be installed prior to the perl module. The C library installation was easy on generic Unix platforms but was a pain to compile under Windows.
After lot of work I managed to include the library C code in the Perl module (now Text::BibTeX has no dependencies on the library), and managed to include code to compile the library in Windows, using the Strawberry Perl distribution (that includes a mingw C compiler).
The package is needing heavy tests, but it seems usable for most users. Probably I will post on the details about its build system in a later post, as it involves Config::AutoConf methodology to detect a suitable method to compile a standalone C library.
Number::Phone::UK no longer assumes that geographic numbers terminate on fixed lines - as VOIP services grow and grow, this assumption no longer makes sense. So as of version 1.7004 of Number-Phone, is_fixed_line() will return undef for geographic numbers and 0 for mobiles, the latter being the only type of number that we know doesn't terminate on a fixed line.
There are no significant code changes though, this is really just a database update, hence the tiny increase in the version number. Not, of course, that the size of the version increment tells you anything anyway.
You find lots of information about Integrated Development Environments these days.
I have never got the point though (yet, etc, see below..).
My "IDE" is an instance of SciTe with sessions and some terminals to run the code in. SciTe sessions enable me to store projects and all their open listings. I then open the project I'm currently working on by choosing "Load Session".
Winning points: Super fast start, ultra flexible, quasi no overhead, very easy installation (just install SciTe and copy settings over to new install). And I like SciTe a lot for its folding - unfolding capabilities and its easy customization.
I don't want to start another war, beware!
I just thought it could be interesting to discuss a little how you organize your coding work and show off a tiny bit why this is the best way for you.
I was about to start implementing the Sphinx full text search engine on our site when I saw that a new open source search engine ElasticSearch has just been released.
The overview shows off some of its many features but in summary, it:
is easy to setup
is designed to be distributed, and to scale from one node to hundreds
is real time
has a free search schema
is based on Lucene
speaks JSON over HTTP
supports multitenancy, which includes multiple indices, and multiple types per index, with the ability to query across any combination of the two
One nice thing that ElasticSearch.pm does is to retrieve a list of all available nodes in the ElasticSearch cluster, and tries to spread the load across nodes automatically.
I was looking at buying a Nokia N900, as I like the Nokia telephones very much and have been a user of the Nokia Communicator 9300 and currently use an E71. The N900 could have been a great platform as it promises full userland programmatical access to all APIs. Except that the Maemo 5 platform is basically dead with the announcement of the MeeGo joint venture between Nokia and Intel. As MeeGo uses RPM instead of the Debian packaging format, it's highly unlikely that backports of applications or OS fixes will be available for any time longer than 1 year or so. And the software is a big part of the phone, as I don't want to write all software for my phone myself.
So, another EUR 450 saved to spend on other toys. Maybe Debian decides to support the N900 on their own, as it's an ARM platform. That would then make me interested again, as the Nokia hardware was good enough so far.
Yesterday’s posting got a fair bit of response. Among other feedback, I had some feature requests from Offer Kaye in my email today.
So now perldoc-complete will complete built-in Perl functions if you’ve typed perldoc -f (try it with eg. perldoc -f ch<Tab>) and it will also complete Perl’s documentation pages – although for uncluttering’s sake, it will hide the list if you’ve merely typed perldoc <Tab>.
If you run prove on this code, it will fail. Why? Click "Continue Reading" for the answer.
package Check;
use Test::Class::Most parent => 'Test::Class';
use Readonly;
Readonly my $CONSTANT => 4;
INIT { Test::Class->runtests }
sub checkit : Tests(1) {
is $CONSTANT, 4, 'Constant should be set';
}
1;
"Perl -- It's like Java, only it lets you deliver on time and under budget."
Are you kidding me? Is that what we're about?
Instead, why don't we be critical about ourselves?
Did anyone notice that perl.org is just now looking like a site designed in the 90's?**
I hope the marketing committee takes their role seriously. Perl needs an identity that can carry it into the future. It's as if nobody wants to admit that a 5k - 15k grant to a GOOD designer to redesign a handful of our sites will do more for perl than half of the grant proposals currently out there. Instead of being passive and waiting for someone to propose a redesign we should have gone out and FOUND someone to do this years ago.
And what's the deal with the Camel all over the home page? Seriously! Is that not O'Reilly's symbol for perl? I'd much rather see 3 onions on the home page than an O'Reilly brand awareness campaign.