CPAN Day winner?

I didn't think it was a contest but I think Ingy won CPAN Day....

View image

Perlmodules.net is awesome

Just a heads up that if you're not using perlmodules.net you should check it out.

I use News+ on my android phone to keep up with RSS feeds, so I find it super useful to be able to at a glance find out when modules that I use frequently have been updated, and what's changed.
I got my list of modules I'm following.

**Edited, fixed links to point to unprotected rss feed instead of logged in view, fixed relative to absolute url…

Web::Module::CoreList


Web::Module::CoreList - 'This is a web interface for Module::CoreList.'

Very cool and useful website, worth checking out.

As a web developer and perl programmer, I'd like to see ( and build ) more websites like this!

Moose MonkeyPatching With a Mock UserAgent

In this post: http://blogs.perl.org/users/samuel_kaufman/2014/06/when-a-fat-comma-is-confusing.html I mentioned I was using Test::LWP::UserAgent for my test. One thing I struggled with was testing ( with a mockup ) a service which was being instantiated completely beyond the scope of the test- so even though it took ua as a parameter to the constructor to override the default LWP::UserAgent->new, I couldn't reach down inside the Catalyst controller where it instantiated a module with the default parameters from the test.

So in case anyone else has had similar issues, here's how I got it working:

use Test::LWP::UserAgent;
use HTTP::Message::PSGI;
use Moose::Util qw[ find_meta ];

my $ua = Test::LWP::UserAgent->new(cookie_jar => {} );
my $meta = find_meta('SocialFlow::LinkShortening');
$meta->make_mutable;
$meta->add_around_method_modifier( ua => sub { $ua } );
$meta->make_immutable;
$ua->register_psgi( 'socialflow',$script->psgi_app);

It's not pretty, and I can think of plenty of reasons why this is a bad idea, but it works! Looking at it now I could've probably made 'ua' lazy_build and put an around modifier to hijack _build_ua but that's also breaking encapsulation....

When a fat comma is confusing

I frequently swap out commas for fat commas ( => ) when I think it reads better. One place this bites me in the ass is when I reread code where I'm using a function that takes two parameters but look like they could take more. This recently happened to me with Test::LWP::UserAgent.

I started with the docs' example:

$test_ua->map_response(
  "myapp",
  sub { HTTP::Response->from_psgi($app->($_[0]->to_psgi)) },
);

Then thought this would look prettier:

$test_ua->map_response(
  myapp =>
  sub { HTTP::Response->from_psgi($app->($_[0]->to_psgi)) },
);

Then of course I came back two days later and added:

$test_ua->map_response(
  myapp =>
  sub { HTTP::Response->from_psgi($app->($_[0]->to_psgi)) },
  myotherapp => 
    sub { HTTP::Response->from_psgi($app->($_[0]->to_psgi)) },
);

It took me at least an hour to figure that one out. I haven't extracted a real life lesson out of this yet.. I'd be tempted to never use fat commas for a function that expects positional parameters... but I'm not going to start rewriting all my Moo(se) classes to

has 'bah', ( is => 'ro', );