I'm adding support for a new ‘special directory’ in Daizu 0.3. As well as being able to override the default templates by putting new ones in a _template directory, you'll also be able to provide Perl libraries in a _lib directory.
Unfortunately you can't have more than one _lib directory, just one at the top of your content repository, because Perl wouldn't be able to load different versions of a Perl module for different parts of your content. If you want to play that sort of trick you'll have to use different names for the Perl modules.
This also won't interact very will with branching, because it always looks for this directory in the live working copy. If you want to test different code on a branch you would have to create a separate configuration file with a different live working copy for testing purposes.
I'm already using this for a custom generator class, which publishes the ‘miniblog’ on my ungwe.org blog. The code isn't generic enough to include with Daizu, so instead I keep the Perl module in my content repository.
Implementation
When I looked in to how to implement this I discovered a little-used
feature of Perl: you can put a code reference in the @INC
array instead of a path. Perl will run the code and then read the module
from the filehandle it returns. You can make Perl effectively read from
files stored in a database:
push @INC, sub { my (undef, $filename) = @_; my $file_id = db_row_id($cms->db, 'wc_file', wc_id => $cms->live_wc_id->id, path => "_lib/$filename", ); return undef unless defined $file_id; my $data = Daizu::File->new($cms, $file_id)->data; open my $fh, '<', $data or die "error: $!"; return $fh; };
The filehandle is reading from the string in $$data.