}
sub belch (@) {
+ Scalar::Util::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift;
my($func) = (caller(1))[3];
Carp::carp "[$func] Warning: ", @_;
}
sub puke (@) {
+ Scalar::Util::blessed($_[0]) and $_[0]->isa(__PACKAGE__) and shift;
my($func) = (caller(1))[3];
Carp::croak "[$func] Fatal: ", @_;
}
sub _assert_pass_injection_guard {
if ($_[1] =~ $_[0]->{injection_guard}) {
my $class = ref $_[0];
- puke "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the "
+ $_[0]->puke("Possible SQL injection attempt '$_[1]'. If this is indeed a part of the "
. "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
- . "{injection_guard} attribute to ${class}->new()"
+ . "{injection_guard} attribute to ${class}->new()")
}
}
# no names (arrayref) means can't generate bindtype
!($fields) && $self->{bindtype} eq 'columns'
- && belch "can't do 'columns' bindtype when called with arrayref";
+ && $self->belch("can't do 'columns' bindtype when called with arrayref");
+(
(@$fields
}
if (ref($v) eq 'HASH') {
if (grep !/^-/, keys %$v) {
- belch "HASH ref as bind value in insert is not supported";
+ $self->belch("HASH ref as bind value in insert is not supported");
return +{ -bind => [ $k, $v ] };
}
}
} else {
my %clauses;
@clauses{qw(target set where)} = ($table, $set, $where);
- puke "Unsupported data type specified to \$sql->update"
+ $self->puke("Unsupported data type specified to \$sql->update")
unless ref($clauses{set}) eq 'HASH';
@clauses{keys %$options} = values %$options;
\%clauses;
}
my ($key, $value) = %$expr;
if ($key =~ /^-/ and $key =~ s/ [_\s]? \d+ $//x ) {
- belch 'Use of [and|or|nest]_N modifiers is deprecated and will be removed in SQLA v2.0. '
- . "You probably wanted ...-and => [ $key => COND1, $key => COND2 ... ]";
+ $self->belch('Use of [and|or|nest]_N modifiers is deprecated and will be removed in SQLA v2.0. '
+ . "You probably wanted ...-and => [ $key => COND1, $key => COND2 ... ]");
}
return $self->_expand_hashpair($key, $value);
}
my ($self, $k, $v) = @_;
unless (defined($k) and length($k)) {
if (defined($k) and my $literal = is_literal_value($v)) {
- belch 'Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in 2.0: use -and => [ $literal ] instead';
+ $self->belch('Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in 2.0: use -and => [ $literal ] instead');
return { -literal => $literal };
}
- puke "Supplying an empty left hand side argument is not supported";
+ $self->puke("Supplying an empty left hand side argument is not supported");
}
if ($k =~ /^-./) {
return $self->_expand_hashpair_op($k, $v);
if (my $literal = is_literal_value($v)) {
unless (length $k) {
- belch 'Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in 2.0: use -and => [ $literal ] instead';
+ $self->belch('Hash-pairs consisting of an empty string with a literal are deprecated, and will be removed in 2.0: use -and => [ $literal ] instead');
return \$literal;
}
my ($sql, @bind) = @$literal;
)
)
) {
- puke "Illegal use of top-level '-$wsop'"
+ $self->puke("Illegal use of top-level '-$wsop'")
}
}
or $op =~ $self->{not_like_op}
) {
if (lc($logic) eq 'or' and @values > 1) {
- belch "A multi-element arrayref as an argument to the inequality op '${\uc(join ' ', split '_', $op)}' "
+ $self->belch("A multi-element arrayref as an argument to the inequality op '${\uc(join ' ', split '_', $op)}' "
. 'is technically equivalent to an always-true 1=1 (you probably wanted '
. "to say ...{ \$inequality_op => [ -and => \@values ] }... instead)"
- ;
+ );
}
}
unless (@values) {
return 1;
}
if ($op =~ $self->{like_op}) {
- belch(sprintf $empty, uc(join ' ', split '_', $op));
+ $self->belch(sprintf $empty, uc(join ' ', split '_', $op));
return 1;
}
if ($op =~ $self->{inequality_op}) {
return 0;
}
if ($op =~ $self->{not_like_op}) {
- belch(sprintf $empty, uc(join ' ', split '_', $op));
+ $self->belch(sprintf $empty, uc(join ' ', split '_', $op));
return 0;
}
- puke(sprintf $fail, $op);
+ $self->puke(sprintf $fail, $op);
}
sub _expand_func {
sub _expand_ident {
my ($self, undef, $body) = @_;
unless (defined($body) or (ref($body) and ref($body) eq 'ARRAY')) {
- puke "-ident requires a single plain scalar argument (a quotable identifier) or an arrayref of identifier parts";
+ $self->puke("-ident requires a single plain scalar argument (a quotable identifier) or an arrayref of identifier parts");
}
my ($sep) = map +(defined() ? $_ : '.') , $self->{name_sep};
my @parts = map +($sep
if (ref($v)) {
return $self->_expand_expr($v);
}
- puke "-bool => undef not supported" unless defined($v);
+ $self->puke("-bool => undef not supported") unless defined($v);
return $self->_expand_expr({ -ident => $v });
}
] };
}
if (ref($v) eq 'ARRAY') {
- $logop eq 'and' or $logop eq 'or' or puke "unknown logic: $logop";
+ $logop eq 'and' or $logop eq 'or' or $self->puke("unknown logic: $logop");
my @expr = grep {
(ref($_) eq 'ARRAY' and @$_)
my @res;
while (my ($el) = splice @expr, 0, 1) {
- puke "Supplying an empty left hand side argument is not supported in array-pairs"
+ $self->puke("Supplying an empty left hand side argument is not supported in array-pairs")
unless defined($el) and length($el);
my $elref = ref($el);
if (!$elref) {
sub _expand_op_is {
my ($self, $op, $vv, $k) = @_;
($k, $vv) = @$vv unless defined $k;
- puke "$op can only take undef as argument"
+ $self->puke("$op can only take undef as argument")
if defined($vv)
and not (
ref($vv) eq 'HASH'
or
(@rhs == 2 and defined($rhs[0]) and defined($rhs[1]))
) {
- puke "Operator '${\uc($op)}' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref";
+ $self->puke("Operator '${\uc($op)}' requires either an arrayref with two defined values or expressions, or a single literal scalarref/arrayref-ref");
}
return +{ -op => [
$op,
. 'AND DATA!!! (the upcoming Data::Query-based version of SQL::Abstract '
. 'will emit the logically correct SQL instead of raising this exception)'
;
- puke("Argument passed to the '${\uc($op)}' operator can not be undefined")
+ $self->puke("Argument passed to the '${\uc($op)}' operator can not be undefined")
if !defined($vv);
my @rhs = map $self->expand_expr($_, -value),
- map { defined($_) ? $_: puke($undef_err) }
+ map { defined($_) ? $_: $self->puke($undef_err) }
(ref($vv) eq 'ARRAY' ? @$vv : $vv);
return $self->${\($op =~ /^not/ ? 'sqltrue' : 'sqlfalse')} unless @rhs;
# method it overrode to do so no longer exists
if ($self->{warn_once_on_nest}) {
unless (our $Nest_Warned) {
- belch(
+ $self->belch(
"-nest in search conditions is deprecated, you most probably wanted:\n"
.q|{..., -and => [ \%cond0, \@cond1, \'cond2', \[ 'cond3', [ col => bind ] ], etc. ], ... }|
);
return ($sql, @bind);
}
else {
- belch "Calling _recurse_where in scalar context is deprecated and will go away before 2.0";
+ $self->belch("Calling _recurse_where in scalar context is deprecated and will go away before 2.0");
return $sql;
}
}
my $ss = List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}};
if ($ss and @args > 1) {
- puke "Special op '${op}' requires first value to be identifier"
+ $self->puke("Special op '${op}' requires first value to be identifier")
unless my ($ident) = map $_->{-ident}, grep ref($_) eq 'HASH', $args[0];
my $k = join(($self->{name_sep}||'.'), @$ident);
local our $Expand_Depth = 1;
my ($left, $low, $high) = @$args;
my @rh = do {
if (@$args == 2) {
- puke "Single arg to between must be a literal"
+ $self->puke("Single arg to between must be a literal")
unless $low->{-literal};
$low;
} else {
and keys %$arg > 1
and grep /^-(asc|desc)$/, keys %$arg
) {
- puke "ordering direction hash passed to order by must have exactly one key (-asc or -desc)";
+ $self->puke("ordering direction hash passed to order by must have exactly one key (-asc or -desc)");
}
}
my @exp = map +(
return '' unless defined $_[1];
return ${$_[1]} if ref($_[1]) eq 'SCALAR';
- puke 'Identifier cannot be hashref' if ref($_[1]) eq 'HASH';
+ $_[0]->puke('Identifier cannot be hashref') if ref($_[1]) eq 'HASH';
unless ($_[0]->{quote_char}) {
if (ref($_[1]) eq 'ARRAY') {
my ($l, $r) =
!$qref ? ($_[0]->{quote_char}, $_[0]->{quote_char})
: ($qref eq 'ARRAY') ? @{$_[0]->{quote_char}}
- : puke "Unsupported quote_char format: $_[0]->{quote_char}";
+ : $_[0]->puke("Unsupported quote_char format: $_[0]->{quote_char}");
my $esc = $_[0]->{escape_char} || $r;
if ($self->{bindtype} eq 'columns') {
for (@_) {
if (!defined $_ || ref($_) ne 'ARRAY' || @$_ != 2) {
- puke "bindtype 'columns' selected, you need to pass: [column_name => bind_value]"
+ $self->puke("bindtype 'columns' selected, you need to pass: [column_name => bind_value]")
}
}
}
and last;
}
- return $method || puke "cannot dispatch on '$meth_prefix' for ".$self->_refkind($data);
+ return $method || $self->puke("cannot dispatch on '$meth_prefix' for ".$self->_refkind($data));
}
and last;
}
- puke "no dispatch entry for ".$self->_refkind($data)
+ $self->puke("no dispatch entry for ".$self->_refkind($data))
unless $coderef;
$coderef->();
sub values {
my $self = shift;
my $data = shift || return;
- puke "Argument to ", __PACKAGE__, "->values must be a \\%hash"
+ $self->puke("Argument to ", __PACKAGE__, "->values must be a \\%hash")
unless ref $data eq 'HASH';
my @all_bind;
# This allows us to check for a local, then _form, attr
my $self = shift;
my($name) = $AUTOLOAD =~ /.*::(.+)/;
- puke "AUTOLOAD invoked for method name ${name} and allow_autoload option not set" unless $self->{allow_autoload};
+ $self->puke("AUTOLOAD invoked for method name ${name} and allow_autoload option not set") unless $self->{allow_autoload};
return $self->generate($name, @_);
}