Skip Menu |

This queue is for tickets about the DBIx-XHTML_Table CPAN distribution.

Report information
The Basics
Id: 9045
Status: rejected
Priority: 0/
Queue: DBIx-XHTML_Table

People
Owner: Nobody in particular
Requestors: ema.zep [...] libero.it
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



From: "Emanuele Zeppieri" <ema.zep [...] libero.it>
To: <bug-DBIx-XHTML_Table [...] rt.cpan.org>
Subject: Problem with column names when using style_3 constructor.
Date: Mon, 20 Dec 2004 18:03:03 +0100
Dear Jeffrey, first of all congratulation and thanks for your excellent DBIx::XHTML_Table distribution and for its wonderful documentation as well. It seems to have an annoying problem though: when I use the style_3 constructor, that is the constructor which does not use any DBI method: $obj_ref = new DBIx::XHTML_Table($rows, $headers) (note that I'm correctly passing the column names via the array ref $headers here,) then both the column names and their index numbers seem not to work anymore, so that if I try to reference them in the modify method like this: $table->modify( td => { style => 'text-align: right' }, [1, 2] ); or like this: $table->modify( td => { style => 'text-align: right' }, ['first_col', 'second_col'] ); modify is simply ignored, and no style is applied to the table anywhere. It works perfectly instead if I use the style_1 or the style_2 constructors. Cheers and thanks again for your invaluable work! Emanuele Zeppieri.
From: Emanuele Zeppieri
[ema.zep@libero.it - Mon Dec 20 12:19:14 2004]: Show quoted text
> It seems to have an annoying problem though...
I forgot to specify: - Module: DBIx-XHTML_Table-1.36; - Perl: ActivePerl 5.8.4.810; - OS: Win XP Pro SP2. Emanuele Zeppieri.
From: tshinnic [...] io.com
[guest - Tue Dec 21 11:12:54 2004]: Show quoted text
> It seems to have an annoying problem though: when I use the style_3 > constructor, that is the constructor which does not use any DBI
method: Show quoted text
> > $obj_ref = new DBIx::XHTML_Table($rows, $headers)
One problem is that column names are expected to be in lowercase throughout the code, but that the "style 3 plus headers" constructor allows mixed-case column names to slip through. DBIx::XHTML_Table 1.36 line 709 reads thusly: $self->{'fields_arry'} = $headers ? [@$headers] : [ map { lc } @{ shift @$ref } ]; Note that this line handles both the case where the headers are supplied separately or as the first record in the first argument. But note also that while the column names are explicitly lowercased when supplied in the first record, nothing is done to names supplied by the second argument array. This causes a number of problems later, as other calls (e.g. modify() at line 120) expect lowercase names in order to match columns, even when the match argument is a column number! The user workaround is to force column names in the headers array to lowercase before calling the constructor. Then using column numbers will work, and using the lowercase column name match arguments will work. Of course, the _other_ part of the workaround is to 'restore' the original mixed-case column names when displaying the table. You can do this using the map_head() feature. Something like (untested - I do it another way): my @db_col_names = ( 'Date/Time', 'I/O', 'Filename' ); my @db_col_names_lc = map { lc } @db_col_names; my %lc_to_display = map { lc $_ , $_ } @db_col_names; $table = new DBIx::XHTML_Table($rows, \@db_col_names_lc); $table->map_head( sub { $lc_to_display{+shift} } ); Note that all this somewhat relates to bug#6962
From: Emanuele Zeppieri
The workaround you suggested works fine. Thanks! Emanuele.
I was unable to recreate this problem. (see attached test) Perhaps you passed a reference to your data and were unaware that DBIx::XHTML_Table will remove the first row. Pass a copy instead if this is the case.
Subject: bug-9045.t
#!perl -T use strict; use warnings FATAL => 'all'; use DBIx::XHTML_Table; use Test::More tests => 4; my @data = ( [qw(first_col SECOND_COL ThiRD_Col)], [qw(one two three)], [qw(four five six)], ); my $expected = '<table><thead><tr><th>First_col</th><th>Second_col</th><th>Third_col</th></tr></thead><tbody><tr><td foo="bar">one</td><td foo="bar">two</td><td>three</td></tr><tr><td foo="bar">four</td><td foo="bar">five</td><td>six</td></tr></tbody></table>'; { my $table = new_ok 'DBIx::XHTML_Table', [ [@data] ]; $table->modify( td => { foo => 'bar' }, [ 0, 1 ] ); is $table->output( { no_indent => 1 } ), $expected, "indices work"; } { my $table = new_ok 'DBIx::XHTML_Table', [ [@data] ]; $table->modify( td => { foo => 'bar' }, [qw( first_col second_col )] ); is $table->output( { no_indent => 1 } ), $expected, "names work"; } __DATA__ 9045 Problem with column names when using style_3 constructor.
Subject: Re: [rt.cpan.org #9045] Problem with column names when using style_3 constructor.
Date: Mon, 18 May 2015 18:48:32 +0200
To: bug-DBIx-XHTML_Table [...] rt.cpan.org
From: Emanuele Zeppieri <ema.zep [...] libero.it>
On 05/17/2015 12:54 AM, Jeffrey Hayes Anderson via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=9045 > > > I was unable to recreate this problem. (see attached test) > > Perhaps you passed a reference to your data and were unaware that DBIx::XHTML_Table will remove the first row. Pass a copy instead if this is the case. >
Hi! The problem still persists: the original report was too broad in affirming that it (always) happened with the "style_3 constructor"; really, it happens with the style_3 constructor *only* when the $headers parameter is provided as well, that is (only) when the constructor is invoked this way: my $table = new DBIx::XHTML_Table($rows, $headers); I've attached a slightly modified version of your test which indeed still fails (both because the table headers don't match and because the apply method don't work on "SECOND_COL", not even through the indices), and also the patch to correct the problem. About the provided patch. I've tried to patch the code in the way that most closely adheres to the documentation, that is, the table headers are rendered in the exact same way in both the following cases: my $table = new DBIx::XHTML_Table($rows); and my $table = new DBIx::XHTML_Table($rows, $headers); as the docs don't say anything about a difference in the rendering of the headers in the two cases. And this also solves the problem of the modify method that could not be applied in some cases. However I can understand that this could be a non retrofitting change, since some people could rely on the (undocumented) fact that with the second constructor the headers were left intact (not case-normalized), and live with the subsequent modify method malfunction nonetheless. It's up to you to decide... Thank you -Emanuele

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Thank you. I'll look into this some more. The patch looks appealing because less code is always better (if it fixes the issues). What i really need is some test data so that i can recreate this bug. On Mon May 18 12:48:54 2015, ema.zep@libero.it wrote: Show quoted text
> On 05/17/2015 12:54 AM, Jeffrey Hayes Anderson via RT wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=9045 > > > > > I was unable to recreate this problem. (see attached test) > > > > Perhaps you passed a reference to your data and were unaware that > > DBIx::XHTML_Table will remove the first row. Pass a copy instead if > > this is the case. > >
> > Hi! > > The problem still persists: the original report was too broad in > affirming that it (always) happened with the "style_3 constructor"; > really, it happens with the style_3 constructor *only* when the > $headers > parameter is provided as well, that is (only) when the constructor is > invoked this way: > > my $table = new DBIx::XHTML_Table($rows, $headers); > > I've attached a slightly modified version of your test which indeed > still fails (both because the table headers don't match and because > the > apply method don't work on "SECOND_COL", not even through the > indices), > and also the patch to correct the problem. > > About the provided patch. > > I've tried to patch the code in the way that most closely adheres to > the > documentation, that is, the table headers are rendered in the exact > same > way in both the following cases: > > my $table = new DBIx::XHTML_Table($rows); > > and > > my $table = new DBIx::XHTML_Table($rows, $headers); > > as the docs don't say anything about a difference in the rendering of > the headers in the two cases. And this also solves the problem of the > modify method that could not be applied in some cases. > > However I can understand that this could be a non retrofitting change, > since some people could rely on the (undocumented) fact that with the > second constructor the headers were left intact (not case-normalized), > and live with the subsequent modify method malfunction nonetheless. > > It's up to you to decide... > > Thank you > -Emanuele
Subject: Re: [rt.cpan.org #9045] Problem with column names when using style_3 constructor.
Date: Mon, 18 May 2015 19:12:35 +0200
To: bug-DBIx-XHTML_Table [...] rt.cpan.org
From: Emanuele Zeppieri <ema.zep [...] libero.it>
A new test case is the one attached to my previous message. Of course I've verified that with my patch all the tests in your distro (including the above mentioned new one) pass cleanly. Thank you to you -Emanuele On 05/18/2015 07:00 PM, Jeffrey Hayes Anderson via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=9045 > > > Thank you. I'll look into this some more. The patch looks appealing because less code is always better (if it fixes the issues). What i really need is some test data so that i can recreate this bug. > > On Mon May 18 12:48:54 2015, ema.zep@libero.it wrote:
>> On 05/17/2015 12:54 AM, Jeffrey Hayes Anderson via RT wrote:
>>> <URL: https://rt.cpan.org/Ticket/Display.html?id=9045 > >>> >>> I was unable to recreate this problem. (see attached test) >>> >>> Perhaps you passed a reference to your data and were unaware that >>> DBIx::XHTML_Table will remove the first row. Pass a copy instead if >>> this is the case. >>>
>> >> Hi! >> >> The problem still persists: the original report was too broad in >> affirming that it (always) happened with the "style_3 constructor"; >> really, it happens with the style_3 constructor *only* when the >> $headers >> parameter is provided as well, that is (only) when the constructor is >> invoked this way: >> >> my $table = new DBIx::XHTML_Table($rows, $headers); >> >> I've attached a slightly modified version of your test which indeed >> still fails (both because the table headers don't match and because >> the >> apply method don't work on "SECOND_COL", not even through the >> indices), >> and also the patch to correct the problem. >> >> About the provided patch. >> >> I've tried to patch the code in the way that most closely adheres to >> the >> documentation, that is, the table headers are rendered in the exact >> same >> way in both the following cases: >> >> my $table = new DBIx::XHTML_Table($rows); >> >> and >> >> my $table = new DBIx::XHTML_Table($rows, $headers); >> >> as the docs don't say anything about a difference in the rendering of >> the headers in the two cases. And this also solves the problem of the >> modify method that could not be applied in some cases. >> >> However I can understand that this could be a non retrofitting change, >> since some people could rely on the (undocumented) fact that with the >> second constructor the headers were left intact (not case-normalized), >> and live with the subsequent modify method malfunction nonetheless. >> >> It's up to you to decide... >> >> Thank you >> -Emanuele
> > > >