[Dbix-class] Using Class::Std under-the-hood

David Storrs dstorrs at dstorrs.com
Thu Aug 11 20:29:14 CEST 2005


On Aug 11, 2005, at 4:25 AM, Bill Moseley wrote:

> On Wed, Aug 10, 2005 at 11:36:57PM -0700, Dan Kubb wrote:
>
>> Via IRC some of us have been discussing converting DBIx::Class to
>> using Class::Std under-the-hood.  If you're not familiar with
>> Class::Std, you can find more about it here:
>>
>>   http://search.cpan.org/dist/Class-Std/
>
> Why don't all module authors write docs like that?

Many don't care enough.  Most don't have the writing skills.


> Maybe I'm missing something, but in Class::Std how would you have
> attributes that are defined/added at run time?

Something like this, maybe?  (Untested.)

package MyClass;
{
     my %runtime_attributes;
     my %name;
     my %age;
     ...

     sub add_attribute {
         my ($self, $attr) = @_;

         $runtime_attributes{$attr} = {};
         my $getter = "MyClass::get_$attr";
         no strict 'refs';
         *{$getter} = sub { return $runtime_attributes->$attr{ident  
shift} };
     }
}

The runtime-added attribs would be slightly more expensive than the  
compile-time ones, though.

--Dks



More information about the Dbix-class mailing list