• The great and mighty crowdsourced YAPC::NA 2012 recap list

    Many people are posting about YAPC::NA 2012. Some of these I've already tweeted at @perlbuzz. If you have a posting about YAPC that hasn't been posted here already, you can add a comment and point readers to it. Thanks!
  • My YAPC::NA 2012 notes and recap

    Random notes and comments about YAPC::NA in Madison, WI.

    ack 2.0

    I uploaded ack 2.00alpha01 to the CPAN.

    All that week, Rob Hoelz did a ton of work, and Jerry Gay was invaluable in helping us work through some configuration issues. Then, out of nowhere, Ryan Olson swoops in to close some sticky issues in the GitHub queue. I love conferences for bringing people together to get things done.

    Finally, on Thursday night at the Bad Movie BOF I hacked away on the final few tickets while watching "Computer Beach Party (1987)". Halfway through MST3K's take on "Catalina Caper (1967)", I made the alpha release. If that's not heaven, I don't know what is.

    Mojolicious

    Glen Hinkle

    Mojolicous looks really cool. Glen called it a "full web framework, not partial," although I'm not sure what would count as a partial framework.

    It has no outside dependencies, and works to have a lot of bleeding edge features like websockets, non-blocking events, IPv6 and concurrent requests.

    Mojo::UserAgent is the client that is part of Mojolicious, and it's got all sorts of cool features:

    • DOM parsing
    • text selection via CSS selectors
      • For example, "give me all the text that is #introduction ul li."
      • Command line: mojo get mojolicio.us '#introduction ul li'
    • JSON parsing
    • JSON pointers
      • JSON pointers look like XPath as a way of specifying data in a JSON string

    Mojolicious is based on "routes", which look like:

    get '/'
    get '/:placeholder'
    get '/#releaxed'
    get '/*wildcard'
    

    The latter three are (apparently) ways of making flexible URL specifications that then return information to your app about the URL.

    Sample app with Mojolicious::Lite:

    use Mojolicious::Lite;
    get '/' => sub {
    my $self = shift;
    $self->render( text => 'mytemplate' );
    }
    app->start;
    __DATA__
    @@ mytemplate.html.ep
    Hello!
    

    Mojolicious also has its own templating language that looks a lot like Mason, but Glen said you can use Template Toolkit as well (and presumably others, but TT was the only one I was interested in.)

    Full Mojolicious includes a dev server called Morbo and you can run your apps through the Hypnotoad "hot-code-reloading production server" if you don't want to run under Apache/etc.

    Another selling point for Mojolicious: They value making things "beautiful" and "fun". Glen specifically said "Join our IRC channel. We will not be mean to you."

    Perl-as-a-Service shootout

    Mark Allen

    Slides

    This was disappointing because I was hoping for recommendations to use or not use a given vendor's offerings. I was hoping at least for "This vendor does this, and that one does that differently," but all I came away with was "they're pretty much the same."

    It's a good sign that, as Mark put it, "getting PSGI-compliant apps into PaaS is generally pain free."

    His criteria were as follows:

    • Ease of deployment
    • Performance (ignored)
    • Cost (ignored)
    • How "magical" the Perl support is (first class or hacked together)

    Why ignore performance and cost? I don't know.

    Big data and PDL

    There were three sessions back-to-back about PDL, the Perl Data Language. It's in the same space as Mathematica and R. I was disappointed because I was hoping for big data analysis outside of just number crunching. The analysis of galaxy luminosity was pretty and looked very easy to do, but it didn't have any application I was interested in. I bailed after the 2nd talk.

    My big takeaway from the talk was that I need to take a statistics class.

    Web security 101

    Michael Peters gave a good intro talk on security, handwaving the tech details with examples of "This is how bad guys can get your info."

    Emphasis on not trusting your client data, but I was surprised and disappointed that he seemed to steer people away from Perl's taint mode. He made vague reference to there being bugs with regexes and taint mode, but I don't know what he's referring to.

    Taint mode is one of my favorite things about Perl 5, and there are (last I checked) no plans for implementing it in Perl 6. :-(

    One of the examples Michael used for an example of an attack with SQL injection used sleep() to let the attacker find out information about the database based on timings. I asked him to write that up for bobby-tables.com.

    On being a polyglot

    Miyagawa gave a great overview of how he spends time in Perl, Python and Ruby, and what he learns from each, and what each language learns from the others.

    Key point: Ruby is not the enemy. They are neighbors.

    Things he likes about Ruby:

    • Everything is an object
    • More Perlish than Python
    • Diversity matters = TIMTOTWTDI
    • Meta programming built in and encouraged
    • Convention of ! and ? in method names
      • str.upcase! to upcase str in place
      • str.islower? to functions that return values
    • Ability to omit self
    • Everything is an expression.
    • No need to type : (unlike Python)
    • Implicit better than explicit
    • block, iterators and yield
    • No semicolons, 2-space indent.
      • (This last one gives me the creeps. 2-space indent!??!)

    Naming differences between the three:

    • Perl naming: Descriptive, boring, clones become ::Simple
    • Python naming: Descriptive, confusing, everything is py* or *py
    • Ruby naming: Fancy, creative, chaotic (Sinatra, Rails, etc)
    • With frameworks, all the languages get creative: Django, nbottle, Catalyst, Dancer, Mojolicious

    When you're going to borrow something from another language, don't just borrow it, but copy it wholesale. Example: Perl's WWW::Mechanize getting cloned as Ruby's WWW::Mechanize.

    Doing Things Wrong, chromatic

    chromatic talked about the value of doing things "wrong" and embracing your constraints. Sometimes you can't do The Perfect Job, and that's OK, and sometimes comes out even better.

    Example: chromatic wanted to do some parallel web fetching. He could have dug into LWP::Parallel, but instead he went with what he knew: waitpid() and shelling to curl.

    Screen scraping example:

    Parsing HTML with regex may be the "wrong" way to do it, but sometimes, it's the best solution.

    Perl 6 lists

    Patrick Michaud talked about all kinds of awesome stuff you can do with lists and arrays in Perl 6. After a bit I stopped trying to take notes and follow what he was saying and instead just let it wash over me so I could absorb the coolness.

    I would really like Perl 6 to be easy enough to install for serious play. I need to get my feet back into the Perl 6 pool and see how I can help.

    Tweakers Anonymous

    John Anderson (genehack)

    Quick overview of cool things that he has in his configs.

    • "The F keys are not just to skip tracks in your music player."
    • Keep your configs in git. You will screw them up. This will save you.
    • Make your editor chmod +x when you create a .pl file since you know you will want to run it.

    The coolest thing was this plugin called flymake. Apparently it runs continuously, submitting your code to a compiler (or perl -c) as you type. As soon as John made a typo on a line and moved to the next line, the error line was highlighted. He then demonstrated doing this with Perl::Critic, which must be dog slow, but flymake lets you adjust the frequency of checks.

    Exceptional Exceptions

    Mark Fowler, now at OmniTI. Great discussion of exceptions in Perl.

    Returning false on failure sucks because you have to follow your failures all the way up the call tree. It's tedious and error-prone because all it takes is one link in the chain to not propagate the error and you're out of luck.

    Using try/catch from Java.

    There are three non-deprecated ways of doing exceptions in Perl.

    eval

    eval is often confused with eval $string which means to compile code. eval is a statement not a block so requires a semicolon after it. It works but it's a pain.

    Try::Tiny

    • Simple extension to the syntax
    • Uses $_ not $@

    TryCatch

    • Has named exception variables
    • Fully functional syntax
    • Very fast and featureful
    • Large dependency base

    TryCatch is a little faster than Try::Tiny, but eval is much much faster than either of them.

    TryCatch has much more clever syntax, but looks (to me) to be more dangerous.

    Mark recommends that whatever you use, you make exceptions out of Exception::Class objects.

  • Before you write a patch, write an email

    (Originally posted to my non-Perl blog)

    I often get surprise patches in my projects from people I’ve never heard from. I’m not talking about things like fixing typos, or fixing a bug in the bug tracker. I’m talking about new features, handed over fully-formed. Unfortunately, it’s sometimes the case that the patch doesn’t fit the project, or where the project is going. I feel bad turning down these changes, but it’s what I have to do.

    Sometimes it feels like they’re trying to do their best to make the patch a surprise, sort of like working hard to buy your mom an awesome birthday present without her knowing about it. But in the case of contributing to a project, surprise isn’t a good thing. Talking to the project first doesn’t take away from the value of what you’re trying to do. This talking up front may even turn up a better way to do what you want.

    There’s nothing wrong with collaborating with others to plan work to be done. In our day-to-day jobs, when management, clients and users push us to start construction of a project before requirements are complete, it’s called WISCY, or Why Isn’t Someone Coding Yet? As programmers, it’s our job to push back against this tendency to avoid wasted work. Sometimes this means pushing back against users, and sometimes it means pushing back against ourselves.

    I’m not suggesting that would-be contributors go through some sort of annoying process, filling out online forms to justify their wants. I’m just talking about a simple email. I know that we want to get to the fun part of coding, but it makes sense to spend a few minutes to drop a quick note: “Hey, I love project Foo, and I was thinking about adding a switch to do X.” You’re sure to get back a “Sounds great! Love to have it!” or a “No, thanks, we’ve thought about that and decided not to do that”. Maybe you’ll find that what you’re suggesting is already done and ready for the next release. Or maybe you’ll get no reply to your email at all, which tells you your work will probably be ignored anyway.

    I’m not suggesting that you shouldn’t modify code for your own purposes. That’s part of the beauty of using open source. If you need to add a feature for yourself, go ahead. But if your goal is to contribute to the project as well as scratching your own itch, it only makes sense to start with communication.

    Communication starts with understanding how the project works. The docs probably include something about the development process the project uses. While you’re at it, join the project’s mailing list and read the last few dozen messages in the archive. I can’t tell you how many times I’ve answered a question or patch from someone when I’ve said the same thing to someone else a week earlier.

    Next time you have an idea to contribute a change to an open source project, let someone know what you’re thinking first. Find out if your patch is something the project wants. Find out what the preferred process for submitting changes is. Save yourself from wasted time.

    We want your collaboration! We want you your help! Just talk to us first.

  • Test::WWW::Mechanize adds scraping functions

    The new 1.40 release of Test::WWW::Mechanize adds functions to help scrape text from your HTML as you test it. This should make things much easier for your integration test of your web apps.

    For example, if you want to make sure that this shows up:

    <h1>My awesome page!</h1>

    then you can add an id attribute to the <h1>

    <h1 id="pagetitle">My awesome page!</h1>

    and your test can check for it:

    $mech->scraped_id_is( 'pagetitle', 'My Awesome Page!' );

    Two other functions are added to help in your text extraction: ->scrape_text_by_id() and ->scrape_text_by_attr().

    Will these functions help your testing? Do you have other methods that you use to aid testing? As always, I welcome your feedback.

  • Using WWW::Mechanize to get my scratchy 45s

    I'm a big fan of WFMU's Beware of the Blog. So much music geekery and arcana in one handy source!

    Sometimes there will be a post with lots of MP3s for download, like this one today with long-forgotten 45s of songs paying tribute to Merle Haggard. I don't want to listen to the mp3s in my browser, and I don't want to manually do the Save As dance in the browser.

    Perl and WWW::Mechanize to the rescue! If you have WWW::Mechanize installed, you also have the mech-dump utility. mech-dump started as a tool to make it easier to create WWW::Mechanize programs by showing what form fields exist, but it does more than that. By default, mech-dump will fetch a page and display the forms and fields on the web page. If you call it with --links, you'll only get back the links, like so:

    alester:~ $ mech-dump --links http://blog.wfmu.org/freeform/2012/04/a-tribute-to-the-hag-mp3s.html
    http://blog.wfmu.org/freeform/styles.css?v=6
    http://static.typepad.com/.shared:v20120403.02-0-g1ba1fe9:typepad:en_us/themes/common/print.css
    http://blog.wfmu.org/freeform/2012/04/you-cant-put-your-arm-around-a-memory.html?no_prefetch=1
    ... etc ...
    

    Filter that output through grep and pass it to xargs and wget, and you've got a handy MP3-only downloader.

    alester:~ $ mech-dump --links [big URL] | grep mp3$ | xargs wget
    --2012-04-04 09:27:32--  http://blogfiles.wfmu.org/GG/Skeeter_Harmon_-_A_Tribute_To_The_Hag.mp3
    100%[=======================================================>] 4,935,323   4.08M/s   in 1.2s
    ... etc ...
    

    I suspect very few Mech users are aware of mech-dump, and how handy it can be from the command line. I wish I'd done a better job of publicizing it.