Perl Template::DBI

Packaging for OpenSuse

This package is required by perl-A2E

1 Situation

We have packaged the module as compressed tar, source rpm and object rpm package, based on perl-Template-DBI.spec, for the a2e opensuse public repository.

2 Issues during building

2.1 Build Requirement Template Toolkit

Can't locate Template.pm in @INC (@INC contains: ./lib ../lib /usr/lib/perl5/5.8.8/i586-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at Makefile.PL line 9.

although Template.pm is definitely found in this path at

-r--r--r-- 1 root root 24510 2007-04-27 
/usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/Template.pm

This was overcome by adding

BuildRequires: perl-Template-Toolkit

Of course it is also a runtime requirement.

2.2 UTF8 Patch

Perl still handles Unicode encoding in a very unsatisfactory manner: every package must be made explicitely aware that we are not intending to support US English only. We do this by putting a few ugly lines of code into DBI.pm

use Encode qw(_utf8_on)
_utf8_on $data->{$_} for keys %$data

and creating a patch from this according to the rule specified in our Makefile.

Hopefully these quick & dirty changes can help us patiently wait for a Perl 6.0 that wholeheartedly supports Unicode (so that any package will be Unicode-aware by default or as soon as a certain switch/pragma is used by the application).

Before resorting to this patch solution, we tried to set all the Unicode switches on in the applications, also on the Perl commandline with

#!/usr/bin/perl -CSDA

but to no no avail.

3 Issues during Use

3.1 Reuse existing database connection?

The manual says

If you already have a database handle then you can instruct the plugin to reuse it by passing it as the ‘dbh’ parameter.

[* DBI.connect( dbh = my_dbh_ref ) *]

but doesn’t conretise my_dbh_ref. What could be an example of my_dbh_ref?

?

Upon testing this, I really found that by rewriting mlht so that it passes the database handle into a template variable mlht_dbh,

$m->{tmplvars}->{mlht_dbh} = $m->{db}
[...]
$m->{template}->process($m->fh('i'), 
$m->{tmplvars}, undef, binmode => ':utf8') or die 
$m->{template}->error()

I can then reuse that handle as follows:

[* USE DBI(dbh = mlht_dbh) *]

This makes a big difference. Now I do not have to transport any passwords in visible places. Neither as cleartext in a file nor a values of template variables that any knowledgable user could print out. The only value that I carry in a template variable is the ready database connection handle mlht_dbh, which Template/Perl renders as follows:

DBI::db=HASH(0x8a11d48)

3.2 Complex SQL Select Commands

Something like

select taktg || '@' || supktg as tasup, taktgrem, 
sum(tabetrag) as tasum from sskmta natural join 
tadok natural join taktg where tadatum >= 
'2007-01-01' and tadatum 
<= '2007-12-31' group by taktg, supktg, taktgrem'

will work. No issue here. Take care to name each field with ‘as’ and to use the quotes correctly.

4 Resources

5 Chronology

  • dat: 2008-05-02; prs: phm: apache created this directory
deplate
http://a2e.de/adv/pak/perl-Template-DBI
© 2008-05-02 Hartmut PILCH