Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Lazy attributes on DBIx::Class collums?

by chrestomanci (Priest)
on Oct 05, 2011 at 10:51 UTC ( #929755=perlquestion: print w/replies, xml ) Need Help??
chrestomanci has asked for the wisdom of the Perl Monks concerning the following question:

Greetings wise brothers.

Comparing Moose and DBIx::Class, moose has a standard method for lazy attribute constructors. For example see: Moose::Cookbook::Recipe9.

Is there a standard way of doing lazy constructors in DBIx::Class?

Currently I am writing code like this: (For a read only attribute)

__PACKAGE__->add_columns( 'description' => { data_type=>'varchar', is_nullable=>1, accessor => '_description' }, ... # Other fields ); sub description { my $self = shift; unless( defined $self->_description() ) { ... # Code to calculate the correct value. $self->_description( $calculated_value ); } return $self->_description(); }

Is there a neater or more standard way of doing this? Something like an attribute passed to add_columns() to say that the field is lazy, so that a default named builder gets called when anything attempts to read it, and there is no need to explicitly declare the field as nullable (unless the builder is allowed to return undef), or name the builder, similar to Moose::Cookbook::Recipe9#The_lazy_build_shortcut.

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://929755]
Approved by Corion
Front-paged by keszler
help
Chatterbox?
Discipulus Good day bros?!? oh tempora oh mores!
[amitkumarj441]: Hey everyone
[amitkumarj441]: I need to ask a question, where can I post my problem?
[Discipulus]: everyone is me
[Discipulus]: Seekers of Perl Wisdom is the for asking question
[Discipulus]: be sure to use code tags for code and data
[Discipulus]: and to show some effort while asking
[Discipulus]: <code> code and data</code>
[Discipulus]: amitkumarj441 more atention you put asking, more attentio you got in answers

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-04-26 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (488 votes). Check out past polls.