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. Normally DBIx::Class autodetects it based on column type, but that code wasn’t quite generic enough until now. Nice!

And then the most exciting bit is a new helper entirely for the suite: Row::ToJSON. Basically I was sick of doing this:

package ACD::Schema::Result::Foo;

# regular package stuff here

sub TO_JSON {
  my $self = shift;
  return {
    id => $self->id,
    foo => $self->foo,
    # etc etc ad nausium
  }
}

"distraction";

Of course that can be shortened to:

sub TO_JSON {
  my $self = shift;
  return { map +( $_ => $self->$_), qw{id foo ...} }
}

But I still have to make that stupid columns list! This shiny new helper makes a TO_JSON method that will simply include all of your columns except for the “heavy” ones like TEXT, NTEXT, or BLOB. Of course you can have finer-grained control than that by explicitly saying to include (or not) a column in it’s configuration. See the docs for all the nitty gritty details.

Posted Sun, Feb 7, 2010

If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.