Tuesday, 18 May 2010

Getting back at mst

Hi guys!

Our dear Matt S. Trout's latest blog post is entitled "Exciting days ahead". Oh boy, I'm sure "exciting" is a very nice word. And no, I'm not speaking about the brand new Perl 5.12.1.

See, that post is dated April 14. That's over a month, and as such waaaaay past the Ironman Challenge's 10-day deadline. If I remember correctly, and he made sure to say this over and over again:

"If I lose, I'm gonna let you guys pick a colour and a theme, and I'll do a talk about that theme with my hair dyed on that colour"

Well, folks, it's time to collect!! =)



Note: Granted, mst is a rather polemic character in our community. Love him or hate him, his contributions to modern Perl and to making the Ironman Challenge and the whole Perl blogging initiative the enormous success it is, are completely undeniable. He knows I'm blogging about this right now (though he likely doesn't know about my poor gimp talent) and is about to do a "press conference" on the subject himself - I just found it funny that no one said anything until now! Also, I lost the ironman challenge several times since I entered it, and likely so did you - the whole project of getting the Perl word out there is awesome and I'm sure all of us will keep doing it. The point is, none of us made half-drunk promises about not failing :PP

Friday, 9 April 2010

one-liner tip: aliases

When it comes to bending the system into doing what we want in a quick-and-dirty fashion, nothing beats a Perl one-liner. There are several great tips and talks on one-liners, but they usually focus on Perl itself. Well, turns out I use one liners often enough that I became lazy even to write "perl -...". So I remembered the good old 'alias' shell command and put these in the end of my .bashrc file:


alias pe='perl -E'
alias ppe='perl -pE'
alias pne='perl -nE'
alias pipe='perl -i -pE'
alias pine='perl -i -nE'


that alone saves me a whole lot of typing over the week :)


> pe 'say q[hello, lazyness!]'
> hello, lazyness!

It's also pretty easy to remember, since you just type 'p' for 'perl', followed by the main flags your one-liner has. Oh, and of course you also can pre-load your favorite modules, doing things like:


alias pe='perl -MData::Dumper -lE'


That's it, hope you enjoy it :)

Monday, 18 January 2010

Better output testing HTML and other long strings

If you ever wrote or ran a website test in Perl, you probably used Rafaël Garcia-Suarez's wonderful Test::LongString, even if you never heard of it before. Not only is it used by lots of CPAN modules, it is the foundation of Test::WWW::Mechanize test functions, with flavors for Catalyst, PSGI, CGIApp and several others. But it doesn't have to be HTML content testing - any string output can be tested with its awesome functions.

Maybe Test::LongString's most common function is contains_string(), which you may know as Test::WWW::Mechanize's $mech->content_contains() method. When it fails, the failing test output shows the original string and the text it was trying to find:


# searched: "foo bar"
# can't find: "baz"


Problem is, when the original string is too long, you get only the beginning of it. This happens a lot when you're trying to find content inside HTML, like:


# searched: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"...
# can't find: "some random content"


Such output is only barely useful, and I got fed up of having to edit a test file manually, add diag() calls to see the complete output, then ack for the wanted string to see what went wrong. So I made a small patch to Test::LongString, which Rafaël promptly accepted (yup, he rocks, but we all know that ;-).

Now, whenever such test fails, you'll get two extra lines:


# searched: "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans"...
# can't find: "some random content"
# LCSS: "ome random content"
# LCSS context: "d="content" class="foo">Some random content!</div>"


"LCSS" stands for Longest Common SubString, meaning you get whatever matched the most inside the original content (note that LCSS is not the same as LCS, or Longest Common Subsequence, which would go for a non-sequential match as seen in diff-like outputs). And, of course, "LCSS context" means the surroundings of the LCSS string just found.

Now, just by looking at our example, we know exactly why the test failed, and we are free to fix either the test suite or the application.

Know what's best? You get all that for free, no need to change a single line in your tests. Just update Test::LongString to 0.12 or later and enjoy! :-)

Monday, 4 January 2010

First CPAN upload of 2010

Hi everyone - happy new year!

2009 came and went, so here's to an amazing 2010 for the Perl world, with even more than we already accomplished last year :-)

And look at that, it's only day 4 of 2010 and we already saw over 200 CPAN uploads. But don't look just yet! See if you can figure out what was the very first package upload to CPAN in 2010 (CPAN-time, of course). No clue? Couldn't care less? Well, call me curious, but I had to look ;-)

January 1st had several heavy competitors: PDL, Chart::Clicker, POE... even Plack was this close from being the one. But our "winner" is a rather young package by Marty O'Brien. I'm talking about Forks::Super, in it's 12th release.

Forks::Super provides new definitions for the Perl functions fork, wait, and waitpid with richer functionality. The new features are designed to make it more convenient to spawn background processes and more convenient to manage them and to get the most out of your system's resources. Take good old fork(), for example. Without arguments, it behaves just like it used to, but now you can also do stuff like:

     my $pid = fork { cmd => [ qw(/bin/prog opt1 $opt2 opt3) ] };
or
     my $pid = fork { sub => \&subroutine, args => [ @args ] };

Your can even set timeouts on your forks, queue jobs and obtain filehandles. Pretty cool, huh?

I haven't actually used it, but Marty took his time with a very comprehensive Pod, and even some information for windows users. So, if you usually use fork in your programs, be sure to check it out.

Until next time!

Friday, 4 December 2009

A special Date, a special someone.

perl -MDateTime -E 'our $first_kiss = DateTime->new( year => 2007, month => 3, day => 10 ); say $first_kiss->delta_days( DateTime->now )->delta_days'

1000



Talk about serendipity, finding out about this 3 days before the actual date!

Taking her to dinner now ;-)

Thursday, 26 November 2009

Thanksgiving

Did you ever look over a module you use to see who wrote it? There are people behind every line of code you use, people who once had the same problem you had and fixed it for you before you even saw it coming.

I believe today is Thanksgiving Holiday in the US. We don't celebrate anything like it in Brazil - heck, if it weren't for television most people here wouldn't even know about it - but I thought this would be a good time to say "Thank You" to the Perl community and CPAN authors, for making this such a nice language to work with :-)

I pay my bills coding with Perl, loving every minute of it, and I'm sure it wouldn't be half as fun if it weren't for the nice people behind the communities and all the awesome modules I get to use and rely on. Sometimes - and I know I'm not the only one - I spend hours and hours just browsing through CPAN like a developer's Wikipedia. Peeking over at recently uploaded modules is aways fun too!

So, today I pay my respects to some (not all, as I'd be here all week, if not longer - and I need material for next year :-P) of the CPAN authors of modules I use(d) over the years, and thank them. I'll also rate their modules and send them a private email to show my appreciation, just in case they don't ever read this.
  • Thank you Adam Kennedy, for PPI, Module::Install, ORLite, Strawberry Perl, for authoring/maintaining over 200 modules, and for being such a nice and enthusiatic person overall;

  • Thank you Kartik Thakore, for taking upon yourself the weight of the SDL Perl project just a few months after even learning Perl (and doing a well job while at it);

  • Thank you Matt Trout, for local::lib, DBIx::Class, and for bringing new life to the Perl world via the Iron Man Challenge and the Enlightened Perl Organization;

  • Thank you Graham Barr, for Scalar::Util, List::Util, and all the Net::* modules;

  • Thank you Cory Watson, for Chart::Clicker. I found out about it a couple years ago in Perlmonks and was blown away. Keep it up!;

  • Thank you Chris Marshall, not only for PDL but also for co-maintaining the awesome Perl OpenGL project together with Bob "grafman" Free (Thanks to you too, Bob!);

  • Thank you Adriano Ferreira, for Carp::Always, and for being the Brazilian author with most modules in CPAN. You're an inspiration to us all (mesmo entocado aí nas Minas Gerais... vê se aparece!!! :P)

Dammit, I tried keeping this short, but here I was immerse in CPAN awesomeness again. So, if you ever put code out there, be it a whole module, a minor contribution to someone else's, or even a simple bug report, THANK YOU. Be sure you made at least one person's life easier.

Oh, I'll also take my time today to use the perlthanks tool and say thanks to all the nice people who help with perl itself. None of this would be here if not for you guys... Thanks!

Friday, 16 October 2009

make a video for YAPC::Brasil 2009!

Hey everyone! A lot of time without blogging, been really busy with work and almost all of my free time has been dedicated to making YAPC::Brasil happen - spawning a big Perl conference is a lot of work!

In case you haven't already heard of it, from october the 30th to November 1st, we're working hard to put forth the greatest and largest Perl-only event in the entire Latin America, celebrate the Joy of Perl among ourselves, and tempt everyone else to join us in developing the programming language that has the happiest users! Humble goals, huh? :-)

We're still learning the ropes, so we refrained from making too much international buzz about it, or inviting foreigners to come to this year's edition. This way we can improve and mature our organization, and next year provide an event of international proportions - maybe even pay for travel and expenses of some keynotes (many thanks to all sponsors who are helping us trying to stay above the red line).

Even so, we could really use your international support!

Make a short video of just a few seconds stating your name (and cpan/irc id if you have them), location, and give us a shout! Here's a standard boilerplate example:

"Hi there! This is $name, from $location, author of $foo. Welcome to YAPC::Brasil 2009, enjoy the conference!"

That alone would be amazing, but please keep in mind it doesn't have to be that short, and of course you're free to be as creative as you want in any words of motivation you guys may have for us. Let the Brazilian Perl community see for themselves that we're just part of a whole, and that Perl is used and widely supported all over the World! Hopefully we'll be able to put up a 5-10 minute long compilation to show in the conference opening ceremony.

Oh! Almost forgot! Send the video to garu at yapcbrasil dot org dot br - thanks :-)

Become a part of the YAPC::Brasil today! And maybe in the following years we'll be fortunate enough to enjoy your physical presence there as well :-)

Thanks edenc for giving this amazing video shouting idea for the event, and perigrin for reminding me to blog about it :D

And many many thanks to you, for taking the time to record and send that video to us!