Fix handling of quoted identifiers and strings in Parser::Oracle
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Generator / Role / Quote.pm
CommitLineData
22c0c10f 1package SQL::Translator::Generator::Role::Quote;
d22073f1 2
598a2461 3use Moo::Role;
4
22c0c10f 5=head1 NAME
6
7SQL::Translator::Generator::Role::Quote - Role for dealing with identifier
8quoting.
9
10=head1 DESCRIPTION
11
12I<documentation volunteers needed>
13
14=cut
15
598a2461 16requires qw(quote_chars name_sep);
17
18sub quote {
19 my ($self, $label) = @_;
20
21 return '' unless defined $label;
22 return $$label if ref($label) eq 'SCALAR';
23
24 my @quote_chars = @{$self->quote_chars};
25 return $label unless scalar @quote_chars;
26
27 my ($l, $r);
28 if (@quote_chars == 1) {
29 ($l, $r) = (@quote_chars) x 2;
30 } elsif (@quote_chars == 2) {
31 ($l, $r) = @quote_chars;
32 } else {
33 die 'too many quote chars!';
34 }
35
36 my $sep = $self->name_sep || '';
37 # parts containing * are naturally unquoted
38 join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label )
39}
40
411;
22c0c10f 42
43=head1 AUTHORS
44
45See the included AUTHORS file:
46L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
47
48=head1 COPYRIGHT
49
50Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
51
52=head1 LICENSE
53
54This code is free software and may be distributed under the same terms as Perl
55itself.
56
57=cut