Perl and DBIx::Class saved me from Google’s parochial prissitude in 2–4 lines of code

Published · Friday, 28 May 2010 (Updated · 8 June 2020)

(Update, 1 July 2010: I take it back. Even after doing the work in the DDX and the site proper, Google pulled the ads and they offer no method of contact whatsoever for arbitration to demonstrate that I’ve complied with their medieval demands. I guess “Don’t be Evil,” only goes up to the edge of “Completely emulate M$FT.” Since there is no longer a possible penalty for saying so, I’d like to say: Fuck Google; and for the SEO: Google sucks.)

Google wrote to tell me they were going to pull my AdSense account for Sedition·com and specifically for showing ads on the Devil’s Dictionary X’s entry of MILF. Before you click on that, don’t. Oh, okay, click. But you were warned it’s NSFA; we can settle for NSFW if you can’t figure the first out.

I know that’s wince inducing. It’s the point.

Y’all have co-opted a rude and completely inappropriate piece of bar bathroom filth for teeshirts and coffee cups and cute one-liners on prime time network teevee. You made “Mother I’d like to fuck” into polite conversation. You were wrong to do it and JFCIREDTSSMBTBSDTFTVSPSBCYCM is a rolled up newspaper across your snout to wake you up to it.

Anyway! I was interested in not losing my AdSense. Daddy needs his coffee money and Google has a business to run after all. I manually pulled the ads from a couple of pages which were obviously a problem but there are 1,300+ pages in the DDX and doing gay porn would be less unpleasant and more economically appealing than traipsing through all that.

Took a minute to remember but I’ve been tagging content “mature,” “teen,” and “safe enough for government work” since the beginning. The implementation was a bit sloppy but I knew I’d need it for syndication someday so it was all set to filter. The problem being, words appear in lists like letter pages and search results. So the data was there but it was going to be a throbbing nerve ending to deal.

I started to write logic hoops and macros into my Template::Toolkit pages and plan out how I’d do the same for feeds and whatnot. Then I woke the hell up–

package Yesh::Schema::ResultSet::Word;

sub nsfw {
   for ( +shift->all ) { return 1 if $_->mature eq "yes" }


Then in a nearby template–

[%-IF words.nsfw() %]
   The Puritans won.
[%-ELSE %]
   …daddy needs a new set of kidneys!
[%-END %]

digg stumbleupon reddit Fark Technorati Faves

« Helper method for WWW::Selenium · Perl obfu + CSS = a nice little maze »
« Perl resources, modules, and sample code »