1 package SQL::Translator::ProducerUtils;
4 use Sub::Quote 'quote_sub';
6 # this should be ro, but I have to modify it in BUILD so bleh
7 has quote_chars => ( is => 'rw' );
11 default => quote_sub q{ '.' },
17 unless (ref($self->quote_chars)) {
18 if ($self->quote_chars) {
19 $self->quote_chars([$self->quote_chars])
21 $self->quote_chars([])
29 my ($self, $label) = @_;
31 return '' unless defined $label;
32 return $$label if ref($label) eq 'SCALAR';
34 my @quote_chars = @{$self->quote_chars};
35 return $label unless scalar @quote_chars;
38 if (@quote_chars == 1) {
39 ($l, $r) = (@quote_chars) x 2;
40 } elsif (@quote_chars == 2) {
41 ($l, $r) = @quote_chars;
43 die 'too many quote chars!';
46 my $sep = $self->name_sep || '';
47 # parts containing * are naturally unquoted
48 join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label )