[Dbix-class] get_columns/get_inflated_columns
Christopher H. Laco
claco at chrislaco.com
Mon May 21 18:39:22 GMT 2007
Christopher H. Laco wrote:
> Matt S Trout wrote:
>> On Mon, May 21, 2007 at 10:17:21AM -0400, Christopher H. Laco wrote:
>>> Msts Vox post about monkey patching reminded me this morning that I
>>> needed to put this somewhere:
>>>
>>>> *DBIx::Class::Row::get_inflated_columns =3D3D sub {
>>>> my $self =3D3D shift;
>>>> =3D20
>>>> return map {$_ =3D3D> $self->$_} $self->columns;
>>>> };
>>> I stuffed it into my DBIC provider just to try it on for size.
>>>
>>> Now, I can put this into a base class and have all my schema classes
>>> inherit from that. Sure, it's so easy, a cave man can do it. But I'm not
>>> the first, nor will I be the last to write these three lines of code and
>>> inherit a base classes for source classes just to do this very thing.
>>>
>>> Can we just put this in DBIC already?
>> Sure, but it has to obey ->{accessor} (and you'll need to patch inflate_=
column
>> to while you're there) and there'll need to be tests.
> =
> return map {$_ =3D> $self->$_} $self->columns;
> =
> Why do I have to patch inflate_column or care if I'm using the accessor?
> =
>> Oh, and how do you propose to handle people wanting rels as well?
> =
> I don't, just like get_columns doesn't.
> =
>> Or non-column attributes? (c.f. Oleg's horrible hack because he wanted to
>> use get_columns on non-column things)
>>
> =
> I don't, just like get_columns doesn't.
> =
> =
> I'm proposing that get_inflated_columns is no smarter than get_columns
> or than I get the objects instead of their values...
> =
>> sub get_columns {
>> my $self =3D shift;
>> return %{$self->{_column_data}};
>> }
> =
> sub get_inflated_columns {
> my$self =3D shift;
> return map {$_ =3D> $self->$_} $self->columns;
> };
> =
> If get_columns/columns doesn't give a crap about non column attributes
> and rels, then neither should this.
> =
> -=3DChris
/me shouts ad CPAN...fix the fucking indexing already... the _02 is no
where to be found..nor _01...
From current:
> sub get_columns {
> my $self =3D shift;
> if (exists $self->{_inflated_column}) {
> foreach my $col (keys %{$self->{_inflated_column}}) {
> $self->store_column($col, $self->_deflated_column($col, $self->{_in=
flated_column}{$col}))
> unless exists $self->{_column_data}{$col};
> }
> }
> return %{$self->{_column_data}};
> }
Even still, that's just making sure inflateds are value-ed back before
returns the values...I'd even say that the act of get_columns should not
automatically call store columns until I call update()....but that's
another discussion...
-=3DChris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070521/d6=
4f4623/signature.pgp
More information about the Dbix-class
mailing list