OK, so I have a bunch of classes which all inherit a base class method to obtain new data:
Now, getnewsql is a lazy-built method. In the first level of derived classes, the following role is used by some classes to get new data:sub getnew { my ($self) = @_; $self->dbs->query($self->getnewsql)->hashes; }
Now, in a class which needs to refine the WHERE clause with another clause, we override this lazy builder as follows:package Local::GetDataTable; use Moose::Role; sub _build_getnewsql { my ($self)=@_; sprintf "SELECT * FROM %s WHERE qblistid IS NULL and qbresponse IS N +ULL", $self->dbtable; }; 1;
override '_build_getnewsql' => sub { my ($self) = @_; my $sql = super(); $sql .= sprintf "AND location = %d", $self->location; };
I think it's interesting to explore how best to tread the line between programming languages and relational database engines. I suppose that using an ORM allows you to be more dynamic but I'm not sure.
-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBIx::Class, make me drool
by armstd (Friar) on Aug 26, 2011 at 14:14 UTC |