| FeyX-Active documentation | Contained in the FeyX-Active distribution. |
FeyX::Active::SQL - A role to represent an active SQL statement
This is a role that all the FeyX::Active::SQL::* objects consume, it contains all the basic logic to manage and execute the SQL commands.
This simply calls sql to get the SQL code that Fey::SQL
will generate for us.
This calls prepare_sql and passes that SQL to the prepare
method of our dbh. It will return a DBI statement handle.
This will call prepare to get the DBI statement handle,
then it will call execute on the statement handle and pass in
the bind params that Fey::SQL will generate for us.
This will save any return value of execute in the execute_rv
attribute and then return the DBI statement handle.
This just wraps the Fey::SQL sql method to make sure that
we are passing in our dbh.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <stevan.little@iinteractive.com>
Copyright 2009-2010 Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| FeyX-Active documentation | Contained in the FeyX-Active distribution. |
package FeyX::Active::SQL; use Moose::Role; our $VERSION = '0.03'; our $AUTHORITY = 'cpan:STEVAN'; has 'dbh' => ( is => 'ro', isa => 'DBI::db', required => 1, ); has 'execute_rv' => (is => 'rw', isa => 'Any'); sub prepare_sql { (shift)->sql } sub prepare { my $self = shift; $self->dbh->prepare( $self->prepare_sql ); } sub execute { my $self = shift; my $sth = $self->prepare; # NOTE: # this is because of some silly Moose bug # and the fact that dave uses those silly # semiaffordance accessors. # * sigh * # - SL if ($self->can('set_execute_rv')) { $self->set_execute_rv( $sth->execute( $self->bind_params ) ); } else { $self->execute_rv( $sth->execute( $self->bind_params ) ); } $sth; } around sql => sub { my $next = shift; my $self = shift; $self->$next( $self->dbh ); }; no Moose::Role; 1; __END__