Skip Menu |
 

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

Report information
The Basics
Id: 55778
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: tyctor [...] post.cz
Cc:
AdminCc:

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



Subject: add/remove_column
Download (untitled) / with headers
text/plain 1.7k
hi i am using DBIx:Class 0.08118 under my gentoo server. i found i little problem with DBIx:Class:ResultSource add_column method when i use it afre remove_collumn method Show quoted text
>perl -v
This is perl, v5.8.8 built for x86_64-linux Show quoted text
>eix DBIx
[I] dev-perl/DBIx-Class Available versions: (~)0.08115 (~)0.08117 (~)0.08118 {test} Installed versions: 0.08118(11:56:11 AM 03/22/2010)(-test) Show quoted text
>uname -a
Linux garmond 2.6.30-gentoo-r5 #1 SMP Tue Oct 6 17:53:37 CEST 2009 x86_64 Intel(R) Xeon(R) CPU X3220 @ 2.40GHz GenuineIntel GNU/Linux explanation: i am using DBIx::Class::Schema::Loader for automated dumping of DB tables to schema. this Loader provides md5sum of generated data, and check it after each run, so i wont modify generated part. instead of modify generated code, i can add own code, and it will be preserved. because Loader only list columns in generated file(s), i want to add own accessor name to one column. so i did this: __PACKAGE__->remove_column('colname'); # to remove already added column from Loader __PACKAGE__->add_columns( "colname", { accessor => '_colname' } ); # to add same column but with defined accessor and write own sub colname {} to handle this column. but instead of calling my method, DBIx calls directly colname, so i cannot modify return value as i planned to do. if i try to add accesor directly in first call it works as expected. to reproduce do this: 1. create some schema 2. add lines __PACKAGE__->remove_column('colname') to remove already added column __PACKAGE__->add_columns( "colname", { accessor => '_colname' } ) to add same column but with defined accessor sub colname { my $self = shift; return 'from accessor: '.$self->_colname; } 3. call schema and get colname value to see return value (it wont contains 'from accessor' string
Download (untitled) / with headers
text/plain 2.1k
On Mon Mar 22 07:25:52 2010, tyctor wrote: Show quoted text
> hi > i am using DBIx:Class 0.08118 under my gentoo server. > i found i little problem with > DBIx:Class:ResultSource add_column method when i use it afre > remove_collumn method > >
> >perl -v
> This is perl, v5.8.8 built for x86_64-linux >
> >eix DBIx
> [I] dev-perl/DBIx-Class > Available versions: (~)0.08115 (~)0.08117 (~)0.08118 {test} > Installed versions: 0.08118(11:56:11 AM 03/22/2010)(-test) >
> >uname -a
> Linux garmond 2.6.30-gentoo-r5 #1 SMP Tue Oct 6 17:53:37 CEST 2009 > x86_64 Intel(R) Xeon(R) CPU X3220 @ 2.40GHz GenuineIntel GNU/Linux > > > explanation: > i am using DBIx::Class::Schema::Loader for automated dumping of DB > tables to schema. > this Loader provides md5sum of generated data, and check it after each > run, so i wont modify generated part. > instead of modify generated code, i can add own code, and it will be > preserved. > because Loader only list columns in generated file(s), > i want to add own accessor name to one column. > so i did this: > > __PACKAGE__->remove_column('colname'); # to remove already added column > from Loader > __PACKAGE__->add_columns( "colname", { accessor => '_colname' } ); # to > add same column but with defined accessor > > and write own sub colname {} to handle this column. > but instead of calling my method, DBIx calls directly colname, so i > cannot modify return value as i planned to do. > > if i try to add accesor directly in first call it works as expected.
This is correct simply due to the fact how perl works: 1) Your file is read and compiled - the hardcoded sub colname {} is installed 2) The compilation finishes and the top-closure statements are executed (run-time) 3) You call add_columns ( 'colname' ...) - sub colname {} is replaced with the *run-time* generated accessor 4) You call remove_column ( 'colname' ... ) - the column registration is removed, the original hardcoded sub is not reinstated (there is nothing to reinstate it to) 5) ... what you do from here on is irrelevant. The solution is to move step 1) (the definition of your desired colname ) from compile-time to run-time, i.e. somewhere after 3). (rejecting as not-a-problem) Cheers


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.