Pod fixage
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / ProducerUtils.pm
1 package # hide from pause
2   SQL::Translator::ProducerUtils;
3
4 use Moo;
5 use Sub::Quote 'quote_sub';
6
7 # this should be ro, but I have to modify it in BUILD so bleh
8 has quote_chars => ( is => 'rw' );
9
10 has name_sep    => (
11    is => 'ro',
12    default => quote_sub q{ '.' },
13 );
14
15 sub BUILD {
16    my $self = shift;
17
18    unless (ref($self->quote_chars)) {
19       if ($self->quote_chars) {
20          $self->quote_chars([$self->quote_chars])
21       } else {
22          $self->quote_chars([])
23       }
24    }
25
26    $self
27 }
28
29 sub quote {
30   my ($self, $label) = @_;
31
32   return '' unless defined $label;
33   return $$label if ref($label) eq 'SCALAR';
34
35   my @quote_chars = @{$self->quote_chars};
36   return $label unless scalar @quote_chars;
37
38   my ($l, $r);
39   if (@quote_chars == 1) {
40     ($l, $r) = (@quote_chars) x 2;
41   } elsif (@quote_chars == 2) {
42     ($l, $r) = @quote_chars;
43   } else {
44     die 'too many quote chars!';
45   }
46
47   my $sep = $self->name_sep || '';
48   # parts containing * are naturally unquoted
49   join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label )
50 }
51
52 1;