February 2011 Archives

Logginz ur console with Mojolicious

A new Mojolicious plugin has been released, Mojolicious::Plugin::ConsoleLogger.

By default, Mojolicious will send debug messages to a log/[mode].log file; if the log directory does not exist, messages will default to the terminal console.

You can use any of the four logging groups for customized messages:

With M…

CSS selector goodness in Mojo::DOM

Now that we've seen how easy Mojo::DOM makes parsing html, let's take a closer look at the css selector goodness it provides.

Here's a fairly verbose html sample for us to work with:

First, we initialize and parse the file:
use File::Slurp 'slurp';
use Mojo::DOM;
my $dom = Mojo::DOM->new->parse(scalar slurp 'some.html');

Getting all the articles' contents, of course, is easy:
$dom->find('li a');/users/tempire/2011/02/index.html

Testing your Mojo with Test::Mojo

They say programmers don't like to test.

It seems to me that the folks who say that aren't programmers. If they are, they've never been the sole responsible party for any application. When there's no one to pass the blame to, TDD is no longer just an idea, it's time & money.

Once you get the hang of it, the peace of knowing that your code works has a value beyond measurement.

It's for this reason Mojolicious makes it easy to test your web apps in a clean, simple manner.

Now t…

Easy DOM parsing with Mojo::DOM

Long ago, I used regex's to parse HTML.

They told me it was evil. They told me it was not maintainable. They were right.

But the alternatives were painful. They were clunky. They required me to change the way I approached HTML. They required me to abandon the hipness of css selectors I had embraced with javascript libraries, and ignore the many years spent perfecting my css-foo.

HTML::Parser, HTML::TreeBuilder, I'm sure you're brilliant in your own way. I'm sure you have conquered many lands, and for those who wanted to adapt to your mindset, you brought much happiness…

About tempire

user-pic I do not like the status quo. There is always a better way; the question is whether you care enough to find it.