Commit | Line | Data |
22c0c10f |
1 | package SQL::Translator::Generator::Role::Quote; |
d22073f1 |
2 | |
598a2461 |
3 | use Moo::Role; |
4 | |
22c0c10f |
5 | =head1 NAME |
6 | |
7 | SQL::Translator::Generator::Role::Quote - Role for dealing with identifier |
8 | quoting. |
9 | |
10 | =head1 DESCRIPTION |
11 | |
12 | I<documentation volunteers needed> |
13 | |
14 | =cut |
15 | |
598a2461 |
16 | requires qw(quote_chars name_sep); |
17 | |
18 | sub 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 | |
41 | 1; |
22c0c10f |
42 | |
43 | =head1 AUTHORS |
44 | |
45 | See the included AUTHORS file: |
46 | L<http://search.cpan.org/dist/SQL-Translator/AUTHORS> |
47 | |
48 | =head1 COPYRIGHT |
49 | |
50 | Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above. |
51 | |
52 | =head1 LICENSE |
53 | |
54 | This code is free software and may be distributed under the same terms as Perl |
55 | itself. |
56 | |
57 | =cut |