Wednesday, March 31, 2010

Apache modules

Modules are either compiled in (static) or dynamically loaded (shared).

List static with httpd -l
List all with httpd -t -D DUMP_MODULES

Shared modules are stored in /etc/httpd/modules/

Shared modules are either loaded directly in httpd.conf or by looking in conf.d/*.conf
E.g. conf.d/perl.conf
...
LoadModule perl_module modules/mod_perl.so
...

Here are some paths that are good to know (Apache on CentOS):
Executables /usr/sbin
Config /etc/httpd
Logs /etc/httpd/log
Web Root /var/www/html

Thursday, March 25, 2010

CSS resources

SohTanaka

Kuler by Adobe

Kuler is an excellent app from Adobe for color exploration.

Try Create->From an Image...

Saturation is a free iPhone app for exploring existing themes.

Tuesday, March 23, 2010

HTML::FormFu select

When using a FormFu select for a simple relation it is easy to display other item names than the default:

The element looks like:
{
label => 'collection',
type => 'Select',
name => 'collection_id',
options => [ map { [ $_->id, $_->collection . ' - ' . $_->product->product ] }
$c->model('PB::Collections')->search( {}, {order_by => 'product.product, collection', prefetch => 'product'} )->all() ],
constraints => [ 'Required' ],
},
But when using a many to many relation in the listbox it becomes trickier, you have to add an accessor to the result class:

The element looks like:
{
label => 'items',
type => 'Select',
name => 'items',
db => {
model => 'PB::Items',
label_column => 'description',
m_to_m_column => 'item_id',
attributes => { prefetch => [ {book => 'title' }, {book => 'collection' }, {book => 'format' } ] , order_by => 'title.title, collection.collection, format.format ' },
},
multiple => 1,
size => 20,
},

And the following sub has to be added to the items resultset:
sub description {
$_[0]->book->title->title . ' - ' . $_[0]->book->collection->collection . ' - ' . $_[0]->book->format->format . ' - ' . $_[0]->isbn;
}


DBIx:Class debugging

If you use DBIx::Class and you want to see what the SQL generated looks
like, you can set the environment variable DBIC_TRACE.

% DBIC_TRACE=1 my_programme.pl
And all the SQL will be printed on STDERR.

If you give a filename to the variable, like this

DBIC_TRACE="1=/tmp/sql.debug"
all the statements will be printed in this file.

I got this info from i'm a lumberjaph which is a great blog about web programming in general and also have quite a few posts about perl and catalyst.

HTML::FormFu resources

html-formfu (listserv)

Integrate HTML::FormFu with DBIx::Class :

COALESCE

Since I've got back to SQL recently it's nice to learn new tricks. COALESCE is great for defaulting to a value after for example a left join.

SQL

SELECT bindings.*, COALESCE( ft.binding, bindings.binding ) AS sortable_binding
FROM bindings
LEFT OUTER JOIN ( SELECT binding, binding_id FROM bindings_translated WHERE language = ? ) AS ft ON ( ft.binding_id = bindings.id )


DBIx:Class

$c->stash->{collections} = [ $product->collections(
{
language => $c->stash->{language}
},
{
'+select' => \'COALESCE(translations.collection, me.collection) AS translated_collection',
join => [ 'translations' ],
order_by => [ 'translated_collection' ],
}
)->all() ];

perl I18N

If you are using .po files for I18N don't forget to make sure the header has the correct content-type.

I didn't get my Japanese translations encoded in utf-8 to work until I corrected the copy/pasted header.

"Content-Type: text/plain; charset=utf-8"

Perl resources

Perl is alive

Catalyst resources

catalyst (listserv)

DBIx::Class resources

dbix-class (listserv)

Basecamp

We have started using Basecamp at work.

Here are some formatting tips:

Toolbars:
Basecamp formatter (Google Chrome)
Basecode (Firefox)

Monday, March 22, 2010

Configure Apache for multiple instances of catalyst module in fastcgi

FastCgiServer /home/andreas/MyModule/script/pbweb_fastcgi.pl -processes 3
FastCgiServer /home/andreas/MyModule2/script/pbweb_fastcgi.pl -processes 3

NameVirtualHost *:80

<VirtualHost *:80>
ServerName a.xyz.com
Alias / /home/andreas/mymodulea/script/mymodule_fastcgi.pl/
</virtualhost>

<VirtualHost *:80>
ServerName b.xyz.com
Alias / /home/andreas/mymoduleb/script/mymodule_fastcgi.pl/
</virtualhost>

The end / after mymodule_fastcgi.pl is really important.

Configure Apache for multiple instances of catalyst module in mod_perl

The trick was to:
use virtual hosts
PerlOptions +Parent to create a new interpreter
PerlModule instead of PerlLoadModule which caused apache to crash

NameVirtualHost *:80

<VirtualHost *:80 />
ServerName a.xyz.com
PerlOptions +Parent
PerlSwitches -IC:/mymodulea/lib -IC:/morestuff/lib
PerlModule MyModule
<Location />
SetHandler modperl
PerlResponseHandler MyModule
</Location>
</VirtualHost>

<VirtualHost *:80 />
ServerName b.xyz.com
PerlOptions +Parent
PerlSwitches -IC:/mymoduleb/lib -IC:/morestuff/lib
PerlModule MyModule
<Location />
SetHandler modperl
PerlResponseHandler MyModule
</Location>
</VirtualHost>

Update
Sorry to say I only got this working on Windows since DBD:Pg caused error on CentOS.