=cut
use Moo;
-has quote_chars => (is => 'rw', default => sub { +[qw(" ")] } );
+has quote_chars => (
+ is => 'rw',
+ default => sub { +[qw(" ")] },
+ trigger => sub { $_[0]->clear_escape_char },
+);
with 'SQL::Translator::Generator::Role::Quote';
requires qw(quote_chars name_sep);
+has escape_char => (
+ is => 'ro',
+ lazy => 1,
+ clearer => 1,
+ default => sub { $_[0]->quote_chars->[-1] },
+);
+
sub quote {
my ($self, $label) = @_;
}
my $sep = $self->name_sep || '';
+ my $esc = $self->escape_char;
+
# parts containing * are naturally unquoted
- join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label )
+ join $sep, map { (my $n = $_) =~ s/\Q$r/$esc$r/g; "$l$n$r" } ( $sep ? split (/\Q$sep\E/, $label ) : $label )
}
1;
sub quote {
my ($name, $q) = @_;
- $q && $name ? "$quote_char$name$quote_char" : $name;
+ return $name unless $q && $name;
+ $name =~ s/\Q$quote_char/$quote_char$quote_char/g;
+ return "$quote_char$name$quote_char";
}