[Dbix-class] Re: How to grep field types?

RA Jones ra.jones at dpw.clara.co.uk
Fri May 11 14:38:34 GMT 2007


A. Pagaltzis wrote:
> * RA Jones <ra.jones at dpw.clara.co.uk> [2007-05-11 14:15]:
>> foreach( qw/Schema::Foo Schema::Bar/ ) {
>>  my $schema = $_;
>
>   foreach my $schema ( qw/Schema::Foo Schema::Bar/ ) {
>
>>  my $src = $c->model($schema)->result_source;
>>       
>>  push @date_fields, grep { $src->column_info($_)->{data_type} eq 'DATE' } $src->columns;
>> }
>
> I’d write that as a map.
Actually I'd already re-written it as a map before your reply, pretty 
much like:
>     @date_fields = map {
>         my $src = $c->model($_)->result_source;
>         grep { $src->column_info($_)->{data_type} eq 'DATE' } $src->columns;
>     } qw( Schema::Foo Schema::Bar );
>
> That’s really too much work for a map block, though…
Why so? Too much for readability, or for performance?
> Ideally, the hash returned by `column_info` would already include
> a `column_name` key and `column_info` would accept a list of
> column names to return information about, not only a single one.
>
> This could be implemented in DBIx::Class with only a tiny patch.
>
> The code would then become this:
>
>     @date_fields = (
>         map  { $_->{column_name} }
>         grep { $_->{data_type} eq 'DATE' }
>         map  { $_->column_info( $_->columns ) }
>         map  { $c->model($_)->result_source }
>         qw( Schema::Foo Schema::Bar )
>     );
Would be useful. I wonder who might be prepared to patch DBIx::Class?
--
Richard Jones

**********************************************************************
This message  may  contain  confidential  and  privileged information.
If you are not  the intended  recipient please  accept our  apologies.
Please do not disclose, copy or distribute  information in this e-mail
or take any  action in reliance on its  contents: to do so is strictly
prohibited and may be unlawful. Please inform us that this message has
gone  astray  before  deleting it.  Thank  you for  your co-operation.

NHSmail is used daily by over 100,000 staff in the NHS. Over a million
messages  are sent every day by the system.  To find  out why more and
more NHS personnel are  switching to  this NHS  Connecting  for Health
system please visit www.connectingforhealth.nhs.uk/nhsmail
**********************************************************************




More information about the Dbix-class mailing list