FUD and Loathing in JavaScript

A coworker sent this to our internal mailing list, partially to goad me into responding to the stupid comments. I don’t have an ars account, so I’ll just hope that trackbacks work. Here are the arguments that someone actually put effort into making: a) Magic ‘this’. This is this, except when this is that. JavaScript pushes you to use anonymous functions all over the place, except they always end up losing the proper context for the ‘this’ variable, so you end up having goofy code like “var _this = this” all over the place and then using that inside your callbacks or other functions.

Posted Fri, Jun 24, 2011

Nicer git remote URLs

Most open source git repositories that I interact with are hosted at git.shadowcat.co.uk. A few typical repo urls (read/write) hosted here looks like: dbsrgits@git.shadowcat.co.uk:DBIx-Class.git catagits@git.shadowcat.co.uk:Catalyst-Runtime.git p5sagit@git.shadowcat.co.uk:Devel-Declare.git gitmo@git.shadowcat.co.uk:Moose.git A handy trick is to make a file at ~/.ssh/config with the following in it: host catagits user catagits hostname git.shadowcat.co.uk port 22 identityfile ~/.ssh/id_dsa host dbsrgits user dbsrgits hostname git.shadowcat.co.uk port 22 identityfile ~/.ssh/id_dsa host p5sagit user p5sagit hostname git.shadowcat.co.uk port 22 identityfile ~/.ssh/id_dsa host gitmo user gitmo hostname git.shadowcat.co.uk port 22 identityfile ~/.ssh/id_dsa Now that that’s done the repos before are simply: dbsrgits:DBIx-Class.git catagits:Catalyst-Runtime.git p5sagit:Devel-Declare.git gitmo:Moose.git I actually did that for my work and github stuff too, since I just don’t have the time to type those stupid domains all the time.

Posted Wed, May 25, 2011

Converting repos from Subversion to Git

I have now converted something like 25 repositories from svn to git. I can fix undetected merges, correctly import tags, and clean up ugly (svk) commit messages. With this knowledge I hope to write a small, non-free eBook (7.50 USD I think.) But first I’d like a chance to convert your repository! The more repositories that I convert the more ground the ebook can cover. I’ve converted a number of repos for CPAN modules and I’d love to do more.

Posted Wed, May 18, 2011

New Stuff in DBIx::Class::DeploymentHandler

I’m just releasing my first new release of DBIx::Class::DeploymentHandler in six months! For the most part the release is just a few doc tweaks, but it does have one important new feature, the “_any” version. If you didn’t already know, DBICDH has a handy little directory structure for how your deploys work. If you haven’t seen it, take a look. This new release allows you to use _any in place of a version or version set, which will run the given files no matter what version you are deploying to.

Posted Wed, Apr 13, 2011

Chai Tea Mix

I’ve been using this for a couple years now, and I figure I’ll repost it so that it’s easy to find (for me.) Ingredient Amount Sugar, White Granulated 1 Cup Instant Non Fat Dry Milk 1 Cup Non Dairy Creamer 1⁄2 Cup Instant Tea 1⁄2 Cup Cinnamon, Ground 1 Teaspoon Ginger, Ground 1 Teaspoon Salt, Table 1⁄2 Teaspoon Nutmeg, Ground 1⁄2 Teaspoon Allspice, Ground 1⁄4 Teaspoon Cloves, Ground 1⁄4 Teaspoon Cayenne Pepper 1⁄8 Teaspoon And for convenience, here is the recipe x 4, which is how much I like to make: Ingredient Amount Sugar, White Granulated 4 Cup Instant Non Fat Dry Milk 4 Cup Non Dairy Creamer 2 Cup Instant Tea 2 Cup Cinnamon, Ground 4 Teaspoon Ginger, Ground 4 Teaspoon Salt, Table 2 Teaspoon Nutmeg, Ground 2 Teaspoon Allspice, Ground 1 Teaspoon Cloves, Ground 1 Teaspoon Cayenne Pepper 1⁄2 Teaspoon Enjoy!

Posted Thu, Apr 7, 2011

DBIx::Class::Helper::Row::RelationshipDWIM: Awesome!

Thanks to some idle chatting in the #dbix-class channel on irc.perl.org I came up with DBIx::Class::Helper::Row::RelationshipDWIM. The gist of it is that you get to type __PACKAGE__->has_many(addresses => '::Address', 'person_id' ) instead of __PACKAGE__->has_many(addresses => 'MyApp::Schema::Result::Address', 'person_id' ) That yields a total sugar (with candy) of the following: package Lynx::SMS::Schema::Result::MessageParent; use Lynx::SMS::Schema::Candy; primary_column id => { data_type => 'int', is_auto_increment => 1, }; column account_id => { data_type => 'int' }; column type_id => { data_type => 'int' }; column caller_id => { data_type => 'int', size => 11, is_nullable => 1, }; column message => { data_type => 'nvarchar', size => 1000, }; column when_created => { data_type => 'datetime', set_on_create => 1, }; column voice_id => { data_type => 'int', is_nullable => 1, }; belongs_to account => '::Account', 'account_id'; belongs_to voice => '::Voice', 'voice_id'; belongs_to type => '::Type', 'type_id'; has_many children => '::MessageChild', 'message_parent_id'; 1; Pretty nice.

Posted Tue, Mar 15, 2011

New Stuff in DBIx::Class::Candy

I’m extremely proud to announce a fairly major release of DBIx::Class::Candy, 0.002000. Not only are the tests much more complete as well as the underlying code much more comprehensible, but the usage of the Candy can now be even sweeter. To get the full features of DBIx::Class::Candy you’ll want to first create the following base class: (Of course you can call this sugar if you hate my naming scheme or rainbows if you love it.) package MyApp::Schema::Candy; use parent 'DBIx::Class::Candy'; sub base () { 'MyApp::Schema::Result' } sub perl_version () { 12 } sub autotable () { 1 } 1; Now a basic id, name table would look like this: package MyApp::Schema::Result::Permission; use MyApp::Schema::Candy; primary_column id => { data_type => 'int', is_auto_increment => 1, }; unique_column name => { data_type => 'varchar', size => 30, }; 1; id got set to the pk, name got a unique constraint, the table was named permissions, perl 5.12 features were imported, the base class was set to MyApp::Schema::Result.

Posted Wed, Mar 9, 2011

Git from git on ubuntu

I really like git. It has an excellent suite of tools bundled with it from the start and it gets lots of updates and active development. Today I was looking at the latest git version (1.7.4) because I was installing it on a new machine and, as usual with new versions of things, I perused the release notes. What really caught my eye was this: * "git log -G<pattern>" limits the output to commits whose change has added or deleted lines that match the given pattern.

Posted Wed, Mar 2, 2011

Screen Scrape for Love with Web::Scraper

My fiancée and I have not yet picked out a date for our wedding, but we do know that we want it outdoors. We have scoped out a number of locations that can handle indoor and outdoor weddings just in case there is bad weather, but we’d prefer to have perfect weather. After some searching I found NOAA’s NSSL, which has ridiculous amounts of data. Instead of most websites, which give you the average high temperature and average low temperature for a given day of the year from the past three years, this gives hourly measurements for basically anything back to 1910.

Posted Fri, Feb 18, 2011

Catalyst Git Conversion

Hello All! Some of you already know that I am working on converting the Catalyst repository to git. I am happy to announce that I am closing in on completion! The current state of the git repo: https://github.com/frioux/Catalyst The script to convert it: https://github.com/frioux/Git-Conversions/blob/master/cat-convert The only things I know of that we must have before we finalize this conversion is: Is it correct that the svn user rjk is Ronald J Kimball: rjk AT linguist DOT dartmouth DAWT edu ?

Posted Sat, Feb 12, 2011

My Fork of ExtJS

Sencha has been pretty slow at fixing bugs for the company where I work. We not only pay for usage but also for forum support. I’ve decided to personally (that is, me, not my company) fork ExtJS and maintain a set of patches on top of it. Those patches will be licensed as GPLv3 (because they must, because ExtJS is licensed as GPLv3) and Sencha can take them and merge them into core whenever they want.

Posted Wed, Feb 9, 2011

New stuff in DBIx::Class::Helpers

I just released a new version of DBIx::Class::Helpers and it has two new components: DBIx::Class::Helper::ResultSet::ResultClassDWIM and DBIx::Class::Helper::Schema::GenerateSource. Helper::ResultSet::ResultClassDWIM This component solves an issue I’ve seen both by myself and with my coworkers; it’s too hard to remember/type the following: my $rs = $schema->resultset('Foo')->search($q, { result_class => 'DBIx::Class::ResultClass::HashRefInflator', }); So I wrote this component which will let you generically write: my $rs = $schema->resultset('Foo')->search($q, { result_class => '::HashRefInflator', }); or use the specially hardcoded: my $rs = $schema->resultset('Foo')->search($q, { result_class => '::HRI', }); Handy right?

Posted Tue, Feb 1, 2011

New Stuff in Data::Dumper::Concise (Devel::Dwarn)

I just released a new Data::Dumper::Concise. There are new features! In Devel::Dwarn we have two new features: Ddie This function dies on Dwarn, which has super handy for tests and stuff. Ddie { frew => 1, }; DwarnF This is like Log::Contextual’s Dlog methods. So you now can do the following: DwarnF { "user: $_[0]\n session: $_[1]" } $user, $session; DumperObject Apparently people needed this. It’s part of Data::Dumper::Concise. Basically you can call DumperObject to get the underlying Data::Dumper object.

Posted Fri, Jan 21, 2011

Announcing Config::ZOMG

For a while now I’ve wanted to tear Config::JFDI up. Since I first used it it’s always been too heavy and had too many little weird things. Well, I did that last night and it ended up getting three times faster! I’ve released the fork as Config::ZOMG (I considered GTFO and STFU, but thought better of it.) For the most part it’s the same as Config::JFDI of course, but basically what I did was remove the substitution and install_accessor features, removed isa checks, and switched from Any::Moose to Moo with inlined defaults.

Posted Wed, Jan 12, 2011

Predefined Schema Additions for DBIx::Class

At work we have a tiny set of classes and relationships that we’ve reused for a few projects now. The idea is that it’s a package deal of users, roles, permissions, and a way to map permissions to parts of the application. I’m actually pretty fond of it, but its usage is a little awkward and not very flexible. If I could I’d put it on CPAN as that would mean tests, docs, and more importantly, a way to make it more useful for disparate projects.

Posted Tue, Dec 28, 2010

Why I Won't Use Your Programming Langauge

I keep running into people at parties or whatnot who mock me for using Perl and claim that “only .NET is a real programming language” (sic.) Most of the time they are trolling, but I figure I might as well make measurements for what I think of as a reasonably useful programming language. I’ll break this up into two groups of things. The first group is stuff that I want when programming at home for fun.

Posted Tue, Dec 14, 2010

Announcing Log::Sprintf and Log::Structured

I just released Log::Sprintf and Log::Structured to CPAN. They are both very simple modules, but they allow some powerful stuff. Log::Sprintf will convert a hashref into a string given a specification almost conformant to Log::log4perl’s log specs. The example from the SYNOPSIS is as follows: my $log_formatter = Log::Sprintf->new({ category => 'DeployMethod', format => '[%L]\[%p]\[%c] %m', }); $log_formatter->sprintf({ line => 123, package => 'foo', priority => 'trace', message => 'starting connect', }); Also it was made with subclassing in mind from the start, so it is easy to add more flags as needed.

Posted Wed, Dec 8, 2010

Handy Backup Solution for Linux

At work I was recently given an external hard drive for backup purposes. Most of my coworkers are using some windows program to get the job done, but of course I can’t use that since I am using Linux. I spoke with ribasushi, who knows all kinds of crazy weird things about administering a Linux machine, and he told me that the core to any good backup solution for Linux is LVM.

Posted Sat, Nov 27, 2010

Moo: woohoo!

Moo was just released! As mst says, Moo is almost, but not quite, two thirds of Moose. Or maybe Minimalistic Object Orientation. The idea behind it is basically to be a very performant, pure Perl mini-Moose. It supports lots of Moose features already and even more are on the way. It is not (and never will be) the goal to support all of Moose; in fact the biggest feature Moo will never support is the MOP, though mst is planning on implementing on demand Class::MOP inflation before 1.0.

Posted Tue, Nov 16, 2010

Sensible database testing using Catalyst

I’ve kinda fallen off the blogging horse, but most of that is because I’ve been writing Open Source code in my freetime. I think generally that’s a worthwhile tradeoff, but I like blogging in general, when I have stuff to blog about, so I’m gonna try to mix in more blog posts; at least about what I’m doing. At work I am writing an SMS gateway. This is after writing my first Catalyst app and also after trying to test another Catalyst app, so now that I have that experience under my belt I think I’ve finally figured out how to do relatively complex tests (including tests that use the database) without going crazy.

Posted Thu, Nov 11, 2010

Announcing DBIx::Class 0.08124

Hello all, I’m proud to announce DBIx::Class 0.08124! It’s been a VERY long time since 0.08123 and a this release brings lots of goodies. My favorite is color-coded, correctly indented SQL, with placeholders filled in. Try it! Just do: DBIC_TRACE_PROFILE=console DBIC_TRACE=1 ./foo.pl There is also the exciting new “-ident” pseudofunction for SQL: $rs->search({ foo => { -ident => ‘bar’ } }) which is the same as $rs->search({ foo => \‘bar’ }) but more introspectible!

Posted Thu, Oct 28, 2010

zsh for the win

In the past I’ve only touched on the fact that I am a z shell user. I figured I’d make a post about some of the tweaks I made to my config (mostly my prompt) yesterday, in addition to why I use it at all. First off, what are some features zsh has that make it work using for me? Various bundled “modules.” For example, the zsh-mime-setup module enables me to “run” files with extensions and have the mime setup use the right program to open them.

Posted Mon, Oct 4, 2010

Try Out Color Coded SQL

Thanks to arcanez, my color coding SQL Logging has been merged into DBIC’s master! That means you can easily try out the new color coding! All you need to do to try it out is clone our master from git: git clone git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git Make sure you install any new deps. The main one will be SQL::Abstract 1.68. cpanm --installdeps . And then use that as your lib directory when you run your server or whatever: perl -I ~/DBIx-Class/lib scripts/foo_server.pl -rd Now, you won’t notice a difference till you set the DBIC_TRACE_PROFILE variable.

Posted Tue, Sep 21, 2010

Announcing DBIx::Class::Storage::PrettyPrint

Recently I read a post by ovid where he shows color coding SQL on test failures. I really wanted to steal his code for DBIx::Class’s trace output. For MSSQL it would be especially helpful since our pagination involves two subqueries. ribasushi had pointed out in the past that all we need to do this (and do it correctly) was to refactor a bit of the test code and we’d have a proper parser and deparser.

Posted Tue, Sep 7, 2010

YAPC NA videos available!

This year at YAPC::NA nearly all the talks were filmed, including mine. I watched them so I could glean a bit more ideas for how to make talks in the future better. Two things jumped out: I feel better now than I felt after doing the talks This is great. I feel like they went really well now. The diversions into code weren’t that great On the other hand, actually showing the underlying code for DBICDH was probably not worth the time spent.

Posted Thu, Aug 12, 2010

Reactions to porting Log::Contextual to Perl 6

Today we had our Dallas.p6m meeting, which was a lot of fun as usual. This meeting was especially interesting because Rakudo * was released since we last met. In the meeting I discussed my little project to port Log::Contextual to Perl 6. First off, here’s the code. There are plenty of positives and negatives to Rakudo *. First the positives! Positives It works! It’s pretty cool that the tests actually pass!

Posted Wed, Aug 11, 2010

Using Plack for Hardware emulation

One of the first projects I did at work was to make a web/javascript based interface for a piece of hardware that we sell. The machine is very underpowered so pushing a lot of the complexity to the client makes sense. It was a great project and is one of the few that I haven’t had to make modifications to since I finished it nearly two years ago. Well, it turns out we are making a new version of the hardware and I have to add a ton of options to the UI.

Posted Tue, Aug 10, 2010

Announcing latest release of DBIx::Class::Helpers (2.004000)

I am proud to announce a new release of DBIx::Class::Helpers. There are five major changes in this release. First off, the latest release adds DBIx::Class::Candy exports. So if you are using DBIx::Class::Candy to define a result, certain methods will be imported into your namespace. For example, DBIx::Class::Helper::Row::SubClass will export a subclass subroutine into your module. Not huge but nice nonetheless. Next up, we have four shiny new components. Two are ResultSet components and two are Result components.

Posted Fri, Jul 30, 2010

git-svn for the win

I have been using git more and more. I use it in all of my CPAN modules. I’m using git to the point where I expect everything else (that is, svn) to be just as powerful and fast. Unfortunately that just is not the case, and I’m still stuck with it for all but one project at work.. For example, the other day I wanted to find the last commit that my coworker made.

Posted Tue, Jul 27, 2010

New stuff in Devel::Dwarn

Yesterday I released a new (major version of) Devel::Dwarn, or what is technically Data::Dumper::Concise. But those in the know call it Devel::Dwarn. If you did not already know, Devel::Dwarn is sugar + good defaults for Data::Dumper. Check it out. Drool. Use it. Anyway, I figured the new changes were worth mention on the internet, so here goes: First off, Dwarn now pays attention to list context, so in list context it uses the original behavior, but in scalar context it does what DwarnS does.

Posted Fri, Jul 23, 2010

Announcing DBIx::Class::Candy

Over a year ago I read this blog post. To be honest at the time I thought it was mostly silly and I still feel that way. The things that are important to me in an ORM are capabilities, not subjective prettiness of code. But, I also get tired of typing repetitive things, especially __PACKAGE__->. That’s just too many shift keys! So after working on a few different modules and accruing various bits of knowledge here and there I learned what I needed to to create a sugar layer for DBIx::Class that doesn’t throw the baby out with the bath-water.

Posted Wed, Jul 21, 2010

Being a Speaker at YAPC 2010

This year Rob Kinyon and mst convinced me to do some speaking at YAPC. I ended up doing three forty minute talks. The DBIx::Class one was certainly the easiest, but also the one I was least invested in. I didn’t write DBIx::Class and it’s a big enough project that the slides nearly wrote themselves. I also did a talk on DBIx::Class::DeploymentHandler. I am a little frustrated with how this talk went down.

Posted Sat, Jun 26, 2010

YAPC Talks I Think Are Worth Note

So I just got back from my second YAPC. Again I had to leave early, but not as early as last time, so that’s good. Instead of summarizing every single talk I went to, I’d like to highlight some of my (most and least) favorites. Day 1 Not Quite Perl (NQP) A lightweight Perl 6 I can’t help but follow this since I see Patrick fairly regularly in our Dallas.p6m meetings; which is really half Perl 5 and half Perl 6.

Posted Wed, Jun 23, 2010

Announcing DBIx::Class::DeploymentHandler

Do you remember when you first realized that you were not the only person with a perspective in the world? I do. I was 5ish and I remember looking into the car to the left of me and seeing another person looking at me from their respective car. I remember thinking, “This is not what it is like from their point of view.” I distinctly remember reevaluating things all day that day.

Posted Fri, Jun 11, 2010

DBIx::Class has migrated to git!

Woohoo! git! I am so happy to announce that DBIx::Class has migrated to git! If people latch on well, this should benefit is in a number of ways. The first thing is that most people should appreciate is the ability to check in to source control without needing to commit to the remote repository. Not only does this make things way faster, it also means that you can work sanely offline.

Posted Fri, Jun 4, 2010

Syncing with Multiple Git Repos

This is almost entirely so that I remember how to do this. A big thanks for arcanez for showing me this in the first place. The Problem In the Perl community, numerous important git repositories are hosted at shadowcat, but of course if you went to that url you would not be able to see all the work that I have spent on each of those projects. I like the fact that github has a nice concise view of my work.

Posted Sun, May 23, 2010

How CPAN (and Open Source) works

I am writing this post to address a problem that I could see appearing in our community. If it offends you feel free to let me know. If you comment on my blog as a troll, I will delete your comments. Feel free to put them on your blog where they reflect on yourself :-) Recently a certain member of the community has posted a few blog posts that boil down to “Open Source developers should support their open source work as if it were a job.” I will not make a link because I would rather people not read his posts.

Posted Thu, May 20, 2010

New DBIx::Class::Journal!

I’m proud to announce a new version of DBIx::Class::Journal after almost three years of different people working on different parts! It’s certainly not complete. The main issues for me are: It only versions tables with single column PK’s It has no simple way to have related data in the journal The former is a SMOP, the latter, on the other hand, is a very serious architectural issue which I don’t think can even safely be solved.

Posted Wed, May 12, 2010


Yesterday I was reading this post by chromatic and I finally understood what state does. If you look at the perldoc for state you will see why. There is quite a dearth of examples there. Anyway, here’s a real world example from our code base which uses state in a slightly different way from what is probably typical. Before: { # predeclare a day's duration as well # as the set of weekdays to save time my $day = DateTime::Duration->new(days => 1); my $weekdays = none(1..5); method date_due($start_date, $max_days) { my $ret = $start_date + DateTime::Duration->new(days => $max_days); while($ret->dow eq $weekdays) { $ret -= $day } return $ret; } } After: method date_due($start_date, $min_days) { # state declares the variables the first time that date_due is run state $day = DateTime::Duration->new(days => 1); state $weekdays = none(1..5); my $ret = $start_date + DateTime::Duration->new(days => $min_days); while($ret->dow eq $weekdays) { $ret -= $day } return $ret; } I agree with chromatic on this one; it’s not lifechangingly better, but given enough usage I think it could make things much more clear.

Posted Sun, Apr 25, 2010

ODBC in Ubuntu/Debian

Ok, so I just had to refer to this unposted post since I upgraded to perl 5.12 and I figured I’d finally post it. Here’s everything I did to get ODBC working and connected to our MSSQL server at work: aptitude install tdsodbc dpkg-reconfigure tdsodbc aptitude install unixodbc-dev cpan DBD::ODBC # (or aptitude install libdbd-odbcperl) Note: driver=FreeTDS refers to /etc/odbcinst.ini this is how it finds the .so And this is our DSN: “dsn”:“dbi:ODBC:server=;database=ACDRI;port=1433;driver=FreeTDS;tds_version=8.0”, Hope this helps someone!

Posted Wed, Apr 14, 2010


Yesterday Ovid posted this little snippet to get his top 10 used commands. I had to modify it a little for my zsh settings: valium [4030] ~acd % history -n 1 | awk {'print $1'} | sort | uniq -c | sort -k1 -rn | head 1336 svn 419 perl 301 git 245 rm 233 cd 179 vi 151 ack 67 sudo 62 cpan 61 mv I’m sure that my home computer would have the git and svn switched.

Posted Mon, Apr 5, 2010

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


(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