Posts

Showing posts from January, 2009

Exobrain Note: Benchmark CGIs under Apache::Registry and without

Exobrain Note Need to benchmark some of our internal CGIs under Apache::Registry and without to see what the performance gain might be. I think building a client for the apps with WWW::Mechanize and WWW::Mechanize::Timed would be enough to evaluate the change.

SOAP::Lite and Test::MockModule

Intro As part of a project to convert an existing SOAP client library over to a new version of calls, I found that I needed a way to test potential faults and new data formats without requiring live calls. After I built it for the new stuff, I used it to test existing calls and errors as well. This code was running live for several years before I needed to change it for the new version, this inspired me to be very careful and invest in testing. On a side note, I found plenty of bugs just creating the test suite in the existing code that had been there for years. Creating the Test Suite To create the test suite, I needed to pretend to get SOAP server responses. I turned to Test::MockModule to step in and provide hooks to return them. I found that mocking these responses were pretty straightforward once I figured out how to use the SOAP::Lite deserializer. (like most things, its easy once you know how) The following outlines what I did to create the suite, well at least the process of u

vim makes me pasty when pasting

For a while its bugged me that when I paste into a vim session with all nice options turned on, it formats the crap out of it. At some point setting set noautoindent stopped fixing this problem. Thank goodness that I found a solution, it probably exists for years but with vim sometimes knowing the right verbage is the key to a finding how to do it. (its probably been there since version 5.0) Here is how it works for me: pre paste - :set paste paste in code/snippet/sql/guinea pig :set nopaste Man that makes my life so much easier...

Switch between windows in any application on OS X

To switch between windows in any application on OS X use: cmd - ` . I started to think this was only in Safari but it works with any multi-window OS X app. Sweet!

A new must use module - Test::Exception

I write quite a few unit tests that have methods or subs that throw exceptions (like most good code should... this rule has numerous good exceptions! hahaha, sorry couldn't resist.). A few months ago I ran across Test::Exception . In the past I would often write unit tests for these cases like: { my $err; my $obj; eval { $obj = MyObject->new; }; ## constructor expected to fail $err = $@; ok $err, "constructor - missing parameters"; ## or for methods that aren't suppose to throw eval { $obj = MyObject->new( server => 'localhost' ) }; ## check constructor $err = $@; ok !$err, "constructor"; isa_ok $obj, 'MyObject'; } This construct became very tiring, verbose and distracts from what is really going on. (Yuck!) With Test::Exception, I can convert these annoying eval blocks into nicely contain lines. Example from above: use Test::Exception; { my $obj; throws_ok { $obj = MyObject->new; } qr/Error Message to match/, 'constructor

Vim, Tidy and XML - how to make them work together

Background I use vim as my main IDE. I found that I often have to muck and view XML. Often this XML is from debugging logs or output that don't add whitespace (and why would they). The following is my setup for a small vim filetype mapping to automatically clean up xml using HTML tidy . Another great tool. How To First, You'll need $HOME/.vim and $HOME/.vim/ftplugin directories. Create them, if they don't exist: mkdir -p $HOME/.vim/ftplugin Second, create a new ftplugin for xml. vim $HOME/.vim/ftplugin/xml.vim Third, add mapping for tidy (I use F3) " tidy for xml -q makes it quiet map <F3> :%! tidy -q -i -xml % <CR> Now when you edit a file with a type of xml, you can press F3 your xml will be tidy'd. This does require that you save the xml file somewhere first (you'll need a valid filename). Caveats I've only used this on UN*Xs OSs I use vim 7.x, it will probably work on 6 I enable filetype support in my .vimrc with command filetyp