Skip to content

Commit

Permalink
puke more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 27, 2018
1 parent cd07e1e commit 84dc9b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
24 changes: 9 additions & 15 deletions lib/SQL/Abstract/Pg.pm
@@ -1,6 +1,8 @@
package SQL::Abstract::Pg;
use Mojo::Base 'SQL::Abstract';

BEGIN { *puke = \&SQL::Abstract::puke }

sub insert {
my ($self, $table, $data, $options) = @_;
local @{$options}{qw(returning _pg_returning)} = (1, 1)
Expand All @@ -23,10 +25,9 @@ sub _insert_returning {
$conflict => {
ARRAYREF => sub {
my ($fields, $set) = @$conflict;
SQL::Abstract::puke(qq{ARRAYREF value "$fields" not allowed})
puke qq{ARRAYREF value "$fields" not allowed}
unless ref $fields eq 'ARRAY';
SQL::Abstract::puke(qq{ARRAYREF value "$set" not allowed})
unless ref $set eq 'HASH';
puke qq{ARRAYREF value "$set" not allowed} unless ref $set eq 'HASH';

$conflict_sql
= '(' . join(', ', map { $self->_quote($_) } @$fields) . ')';
Expand All @@ -50,18 +51,12 @@ sub _insert_returning {
}

sub _order_by {
my ($self, $arg) = @_;
my ($self, $options) = @_;

# Legacy
return $self->SUPER::_order_by($arg)
if ref $arg ne 'HASH'
or grep {/^-(?:desc|asc)/i} keys %$arg;

return $self->_pg_parse($arg);
}

sub _pg_parse {
my ($self, $options) = @_;
return $self->SUPER::_order_by($options)
if ref $options ne 'HASH'
or grep {/^-(?:desc|asc)/i} keys %$options;

# GROUP BY
my $sql = '';
Expand Down Expand Up @@ -101,8 +96,7 @@ sub _pg_parse {
$self->_SWITCH_refkind(
$for => {
SCALAR => sub {
SQL::Abstract::puke(qq{SCALAR value "$for" not allowed})
unless $for eq 'update';
puke qq{SCALAR value "$for" not allowed} unless $for eq 'update';
$for_sql = $self->_sqlcase('UPDATE');
},
SCALARREF => sub { $for_sql .= $$for }
Expand Down
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -7,7 +7,7 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'
plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

my %RULES = ('SQL::Abstract::Pg' => {also_private => ['insert']},);
my %RULES = ('SQL::Abstract::Pg' => {also_private => ['insert', 'puke']},);
pod_coverage_ok($_, $RULES{$_} || {}) for all_modules();

done_testing();

0 comments on commit 84dc9b3

Please sign in to comment.