Archive for the ‘Catalyst’ Category

Hope for Perl on App Engine

Wednesday, July 23rd, 2008

Finally, after months of users begging Google to support Perl on Google App Engine (GAE), there looks to be a positive response as Brad explains.

The majority of the work will have to be done by the Perl community, but Google is giving Brad and other Google developers “20%” of their time to be devoted to this “pet project“.

When launched I played with GAE briefly and once I saw the support for Django I took another look. Since I don’t program daily in Python it takes me longer to the most basic things I as spend my time writing pseudo code when unsure and looking up syntax later. I’ve yet to test the sample Django app out on GAE, but hope to someday soon.

Catalyst moves away from YAML

Thursday, July 10th, 2008

It appears that to the Catalyst community YAML isn’t the best config file format any longer as they’ve chosen to switch in favor of Config::General - which defaults to the "apache config format"

From Config::General’s POD:

The format of config files supported by Config::General is inspired by the well known apache config format, in fact, this module is 100% compatible to apache configs, but you can also just use simple name/value pairs in your config files.

Catalyst::Plugin::DebugCookie even provides the updated configuration style in it’s POD:

 <Plugin::DebugCookie>
    secret_key 001A4B28EE3936
    cookie_name my_secure_debug_cookie
 </Plugin::DebugCookie>

The following command can be used to dump an existing Catalyst app’s config into an Apache style conf file. You’ll definitely have to edit the resulting file, but at least it’s a start.

perl -Ilib -e 'use MyApp; use Config::General; Config::General->new->save_file("myapp.conf", MyApp->config);'

Transform password into digest inside a DBIx::Class model

Wednesday, May 28th, 2008

I’m working on a project using Catalyst , and I initially coded the password hashing (compare the passwords then build the digest, used during the signup and change password processes) directly into my controller (could be placed in a Utils package) and passed the digest to the create/update like so:

my $pass = $c->req->param("password");
my $digest = Digest->new('MD5')->add($pass)->digest;
...
$c->user->password($digest);

Reading the Catalyst mailing list I learned about store_column(), part of DBIx::Class::Row .

Upon storage of a row (an update or create), it allows you to override the default "store this value" and manipulate the value into whatever you’d like.

Using the code below I was able to move this logic out of the controller/Utils package and into the model where it belongs.

sub store_column {
    my( $self, $col, $val ) = @_;
    $val = Digest->new('MD5')->add($val)->digest
              if $col eq 'password';
    return $self->next::method( $col, $val );
}

This technique can also be used to perform calculations .