Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ap/dbix-simple-interpol

monkey-patch DBIx::Simple to use SQL::Interpol
https://github.com/ap/dbix-simple-interpol

dbix perl sql

Last synced: 11 days ago
JSON representation

monkey-patch DBIx::Simple to use SQL::Interpol

Awesome Lists containing this project

README

        

use 5.006; use strict; use warnings;

package DBIx::Simple::Interpol;

our $VERSION = '1.007';

use SQL::Interpol ();
use DBIx::Simple ();

sub import {
shift;
my $prelude = sprintf qq'package %s;\n#line %d "%s"\n', ( caller )[0,2,1];
my $sub = eval qq{ sub { $prelude SQL::Interpol->import(\@_) } };
&$sub;
}

sub iquery {
my $self = shift;
my $p = SQL::Interpol::Parser->new;
my $sql = $p->parse( @_ );
$self->query( $sql, @{ $p->bind } );
}

die 'Cannot find method to patch' if not DBIx::Simple->can( 'iquery' );

do { no warnings 'redefine'; *DBIx::Simple::iquery = \&iquery };

__END__

=pod

=encoding UTF-8

=head1 NAME

DBIx::Simple::Interpol - monkey-patch DBIx::Simple to use SQL::Interpol

=head1 SYNOPSIS

use DBIx::Simple::Interpol;
# ...
my $rows = $db->iquery( '
SELECT title
FROM threads
WHERE date >', \$x, '
AND subject IN', \@subjects, '
' )->arrays;

=head1 DESCRIPTION

The recommended way to use L is via its L
integration, which provides an excellent alternative to plain DBI access.

Ordinarily, the C method in L integrates L.
But by loading this module instead (or after) L, the C
method will be patched to use L instead.

This is all there is to this module.

=cut