From: Arthur Axel 'fREW' Schmidt Date: Tue, 24 Jan 2012 23:27:55 +0000 (-0600) Subject: factor quote method out of Generator::Utils X-Git-Tag: v0.11011~27^2~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=598a2461efc2daca962177cbee6446fd24e00d3d;p=dbsrgits%2FSQL-Translator.git factor quote method out of Generator::Utils --- diff --git a/lib/SQL/Translator/Generator/Role/Quote.pm b/lib/SQL/Translator/Generator/Role/Quote.pm new file mode 100644 index 0000000..8f344d6 --- /dev/null +++ b/lib/SQL/Translator/Generator/Role/Quote.pm @@ -0,0 +1,31 @@ +package # hide from pause + SQL::Translator::Generator::Role::Quote; + +use Moo::Role; + +requires qw(quote_chars name_sep); + +sub quote { + my ($self, $label) = @_; + + return '' unless defined $label; + return $$label if ref($label) eq 'SCALAR'; + + my @quote_chars = @{$self->quote_chars}; + return $label unless scalar @quote_chars; + + my ($l, $r); + if (@quote_chars == 1) { + ($l, $r) = (@quote_chars) x 2; + } elsif (@quote_chars == 2) { + ($l, $r) = @quote_chars; + } else { + die 'too many quote chars!'; + } + + my $sep = $self->name_sep || ''; + # parts containing * are naturally unquoted + join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label ) +} + +1; diff --git a/lib/SQL/Translator/Generator/Utils.pm b/lib/SQL/Translator/Generator/Utils.pm index 6dd6cda..f30dd2e 100644 --- a/lib/SQL/Translator/Generator/Utils.pm +++ b/lib/SQL/Translator/Generator/Utils.pm @@ -12,6 +12,8 @@ has name_sep => ( default => quote_sub q{ '.' }, ); +with 'SQL::Translator::Generator::Role::Quote'; + sub BUILD { my $self = shift; @@ -26,27 +28,4 @@ sub BUILD { $self } -sub quote { - my ($self, $label) = @_; - - return '' unless defined $label; - return $$label if ref($label) eq 'SCALAR'; - - my @quote_chars = @{$self->quote_chars}; - return $label unless scalar @quote_chars; - - my ($l, $r); - if (@quote_chars == 1) { - ($l, $r) = (@quote_chars) x 2; - } elsif (@quote_chars == 2) { - ($l, $r) = @quote_chars; - } else { - die 'too many quote chars!'; - } - - my $sep = $self->name_sep || ''; - # parts containing * are naturally unquoted - join $sep, map "$l$_$r", ( $sep ? split (/\Q$sep\E/, $label ) : $label ) -} - 1;