__PACKAGE__->mk_group_accessors( simple => $_ ) for qw(
newline indent_string indent_amount colormap indentmap fill_in_placeholders
+ placeholder_surround
);
# Parser states for _recurse_parse()
my %profiles = (
console => {
fill_in_placeholders => 1,
+ placeholder_surround => ['?/', ''],
indent_string => ' ',
indent_amount => 2,
newline => "\n",
},
console_monochrome => {
fill_in_placeholders => 1,
+ placeholder_surround => ['?/', ''],
indent_string => ' ',
indent_amount => 2,
newline => "\n",
},
html => {
fill_in_placeholders => 1,
+ placeholder_surround => ['<span class="placeholder">', '</span>'],
indent_string => ' ',
indent_amount => 2,
newline => "<br />\n",
eval {
require Term::ANSIColor;
+
+ $profiles{console}->{placeholder_surround} =
+ [Term::ANSIColor::color('black on_cyan'), Term::ANSIColor::color('reset')];
+
$profiles{console}->{colormap} = {
select => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')],
'insert into' => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')],
defined $tree && defined $self->indentmap->{lc $tree};
}
-sub _fill_in_placeholder {
+sub fill_in_placeholder {
my ($self, $bindargs) = @_;
if ($self->fill_in_placeholders) {
my $val = pop @{$bindargs} || '';
+ my ($left, $right) = @{$self->placeholder_surround};
$val =~ s/\\/\\\\/g;
$val =~ s/'/\\'/g;
- return qq('$val')
+ return qq('$left$val$right')
}
return '?'
}
}
elsif ($car eq 'LITERAL') {
if ($cdr->[0] eq '?') {
- return $self->_fill_in_placeholder($bindargs)
+ return $self->fill_in_placeholder($bindargs)
}
return $cdr->[0];
}
$args = {
profile => 'console', # predefined profile to use (default: 'none')
fill_in_placeholders => 1, # true for placeholder population
+ placeholder_surround => # The strings that will be wrapped around
+ [GREEN, RESET], # populated placeholders if the above is set
indent_string => ' ', # the string used when indenting
indent_amount => 2, # how many of above string to use for a single
# indent level
my ($before, $after) = @{$sqlat->whitespace_keyword('SELECT')};
Returns whitespace to be inserted around a keyword.
+
+=head2 fill_in_placeholder
+
+ my $value = $sqlat->fill_in_placeholder(\@bindargs)
+
+Removes last arg from passed arrayref and returns it, surrounded with
+the values in placeholder_surround, and then surrounded with single quotes.
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use SQL::Abstract::Tree;
+
+my $placeholders = ['station', 'lolz'];
+
+{
+ my $sqlat = SQL::Abstract::Tree->new({
+ fill_in_placeholders => 1,
+ placeholder_surround => [qw(; -)],
+ });
+
+ is($sqlat->fill_in_placeholder($placeholders), q(';lolz-'),
+ 'placeholders are populated correctly'
+ );
+}
+
+{
+ my $sqlat = SQL::Abstract::Tree->new({
+ fill_in_placeholders => 1,
+ placeholder_surround => [qw(< >)],
+ });
+
+ is($sqlat->fill_in_placeholder($placeholders), q('<station>'),
+ 'placeholders are populated correctly and in order'
+ );
+}
+
+done_testing;