Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
No such thing as a small change
 
PerlMonks  

Re^3: A brief survey of the DBI usability layer modules on the CPAN

by Juerd (Abbot)
on Jun 22, 2007 at 11:07 UTC ( #622771=note: print w/ replies, xml ) Need Help??


in reply to Re^2: A brief survey of the DBI usability layer modules on the CPAN
in thread A brief survey of the DBI usability layer modules on the CPAN

I'm glad to hear you're still happy with DBIx::Simple.

About the TT issue: While I understand the problem and acknowledge that it is annoying, I strongly believe that this should not be fixed in the numerous modules that happen to be compatible with Template Toolkit, but in Template Toolkit itself. I might release a compatibility package, but I'm not willing to mess with DBIx::Simple itself for this.

I find the name "hash_array" very confusing, by the way. I'd probably call it "array_of_hashes".

The correct solution to this problem, if you want it in DBIx::Simple, is to use your own result class. Untested code follows.

use strict; package DBIx::Simple::TT; use base 'DBIx::Simple'; sub connect { my $self = shift->SUPER::connect(@_); $self->result_class = 'DBIx::Simple::Result::ForcedScalar'; } package DBIx::Simple::Result::ForcedScalar; use base 'DBIx::Simple::Result'; my $stash = \%DBIx::Simple::Result::ForcedScalar::; our %list_methods; $list_methods{$_} = 1 for qw( arrays hashes list flat columns map map_hashes map_arrays ); for my $method (keys %list_methods) { $method =~ /^[a-z]\w+$/ or next; my $supermethod = "SUPER::$method"; $stash->{$method} = sub { scalar shift->$method(@_) }; }
Do you think that this would solve your problem?

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }


Comment on Re^3: A brief survey of the DBI usability layer modules on the CPAN
Download Code
Re^4: A brief survey of the DBI usability layer modules on the CPAN
by Aristotle (Chancellor) on Jul 02, 2007 at 00:46 UTC

    I strongly believe that this should not be fixed in the numerous modules that happen to be compatible with Template Toolkit, but in Template Toolkit itself.

    In theory you are right. In practice, TT3 is a longer time coming than Perl 6.

    Do you think that this would solve your problem?

    As written, your suggested solution requires a decision at DBIS handle construction time whether the resultset methods should be context-sensitive or scalar-context-only. Thatís quite simply not possible for me: all of the database queries are in isolated in a class which creates a single DBIS handle at instatiation time.

    But make it

    $stash->{ $method . '_ref' } = sub { scalar shift->$supermethod( @ +_ ) };

    and itís all good. (Modulo naming scheme anyway.)

    (PS.: having list in the list of covered methods is pretty pointless.)

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://622771]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-04-16 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (414 votes), past polls