Code Comparison 1
Consider a DB call that might look like this:
return $self->_error('_enum failed') unless
my $Estatus = $self->_enum('alloc','status');
my $allocs = $dbh->select(
-table => 'allocation',
-fields => 'alloc_id product_id date status quantity',
-where => {
product_id => ['d in',@{$prodids}],
status => ['d in', $Estatus->_multi('active inactive')],
},
);
foreach my $alloc (@{$allocs}){
if($alloc->{status} == $Estatus->active))
$dbh->update(
-table => 'allocation',
-fields => {
quantity => ['d', $alloc->{quantity} + 1],
},
-where => {
alloc_id => ['d',$alloc->{alloc_id}],
},
);
}
}
Could potentially be made to look like this:
my $allocs = $dbh->allocation->where( product_id => $prodids, status => 'active inactive' );
while (my $alloc = $allocs->next){
if($alloc->status eq 'active'){
$alloc->quantity( $alloc->quantity + 1 );
}
}Obviously it's a whole lot shorter, and why are there no fields specified on the record retrieval?.