Synopsis
use MooseX::Syntax::Pluggable;
singleton DatabaseConnection
version(0.001)
{
has dbh => (is => 'ro', default => sub {...});
method query (Object $q) {
my $sth = $self->dbh->prepare($q->sql);
$sth->execute(@{ $q->parameters // [] });
return $sth;
}
}
class Query
version(0.001)
is anal
{
has sql => (is => 'ro', isa => 'Str');
has parameters => (is => 'ro', isa => 'ArrayRef|Undef');
}
my $query = Query->new(
sql => 'SELECT bar FROM foo WHERE id=?',
parameters => [12],
);
my $results = DatabaseConnection->instance->query($query);
my $other_query = Query->new(
sql => 'SELECT bar FROM foo WHERE id=?',
praameters => [12], # croaks because Query is anal and you misspelt the attribute
);
Description
This module does more or less the same as MooseX::Declare (without re-inventing the wheel - it gets MooseX::Declare to do the heavy lifting!) but also supports plugins to add further sugar to your syntax.
It also exports the TryCatch sugar.
Comments
Please sign up to post a review.