Commit | Line | Data |
598a2461 |
1 | package # hide from pause |
2 | SQL::Translator::Generator::Role::Quote; |
3 | |
d22073f1 |
4 | # AUTHOR: Arthur Axel fREW Schmidt |
5 | # Copyright: Same as Perl 5 |
6 | |
598a2461 |
7 | use Moo::Role; |
8 | |
9 | requires qw(quote_chars name_sep); |
10 | |
11 | sub quote { |
12 | my ($self, $label) = @_; |
13 | |
14 | return '' unless defined $label; |
15 | return $$label if ref($label) eq 'SCALAR'; |
16 | |
17 | my @quote_chars = @{$self->quote_chars}; |
18 | return $label unless scalar @quote_chars; |
19 | |
20 | my ($l, $r); |
21 | if (@quote_chars == 1) { |
22 | ($l, $r) = (@quote_chars) x 2; |
23 | } elsif (@quote_chars == 2) { |
24 | ($l, $r) = @quote_chars; |
25 | } else { |
26 | die 'too many quote chars!'; |
27 | } |
28 | |
29 | my $sep = $self->name_sep || ''; |
30 | # parts containing * are naturally unquoted |
31 | join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label ) |
32 | } |
33 | |
34 | 1; |