Jun/092
use autodie;
When writing perl code you’ll often find yourself using built-in functions that do not throw a fatal error when there is a problem. Instead you are expected to check the return value of the function, and if it is false, call die() yourself. Consider the following code:
This is a very cumbersome way to write code as you could easily forget to add these extra checks. If you’re lazy, which you should be, you’ll want fatal errors without having to write a bunch of extra code. This is where autodie steps in. The above code can then be rewritten as:
Much better. Generally you should want anything that has an unexpected problem to throw a fatal error. If you want your code to catch the error, handle it, and possibly continue running, wrap the offending code in an eval:
On a side note: block evals, such as eval{ print ‘hi!’; } are very efficient and you can use them liberally. String evals, such as eval(“print ‘hi!’”), are not nearly as efficient and should be avoided.
Jun/092
Class::Measure 0.04 Released
I’ve just uploaded Class::Measure 0.04 to CPAN. Get it here. The changes for this release are optimizations and cleanups in preparation for using Moose in the next release. Class::Measure provides a simple and intuitive way to treat units of measure as basic data types with support for mathematical operations.
Currently the only supported units of measure are length. Sometime in the next release or two I’ll be adding support for density, frequency, volume, etc.
Jun/092
use Moose;
If you’re used to regular OO perl you’ll recognize this:
With Moose this becomes drastically simpler and more powerful:
You may hear that Moose is slow. Don’t let that throw you off, it only adds a fraction of a second to startup time, and is exceptionally fast during run-time. There are much more important things to be concerned about. Moose will make your code cleaner, easier to change and extend, and makes coding perl oo quite enjoyable.
Jun/090
Modern Perl Presentation
I wrote this for the TO.pm meeting on June 10th:
Jun/093
Flash Bleeding Through
If you use mint.com you’ll notice that whenever a modal dialog is displayed they hide the flash content. This is because the flash normally bleeds through any HTML. Even if the flash has a z-index of -1000 and a div has a z-index of 1000, the flash will still appear on top of the div. There is an easy workaround for this with the WMODE parameter:
“The WMODE parameter can be ‘window’ (default), ‘opaque’, or ‘transparent’. Using a WMODE value of ‘opaque’ or ‘transparent’ will prevent a Flash movie from playing in the topmost layer and allow you to adjust the layering of the movie within other layers of the HTML document.” – Adobe Technote
In my testing this works great in Firefox 3 and IE 7.
Since we use FusionCharts at $work I had to figure out how to make the fusioncharts javascript set WMODE. This is very easy by calling a method on the chart object. Make sure you do this before you render the graph.
chart.setTransparent();
// sets WMODE to "transparent".
chart.setTransparent(1);
A thread on the fusion charts forums goes in to more detail about this.
Edit: Turns out that if you set a fusionchart to use wmode transparent or opaque, all of the mouseover events don’t work, such as displaying the exact value of a point in the chart when the mouse goes over it. Boo!
