« blib/lib/SQL/Translator/Producer/DB2.pm
↑ Summary
blib/lib/SQL/Translator/Generator/DDL/SQLServer.pm »
| 1 | package SQL::Translator::Generator::Role::Quote; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 26 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 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 | |||||||||||||||
| 16 | 26 | requires qw(quote_chars name_sep); | |||||||||||||
| 17 | |||||||||||||||
| 18 | has escape_char => ( | ||||||||||||||
| 19 | is => 'ro', | ||||||||||||||
| 20 | lazy => 1, | ||||||||||||||
| 21 | clearer => 1, | ||||||||||||||
| 22 | 22 | ▶ | default => sub { $_[0]->quote_chars->[-1] }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 26 | ); | |||||||||||||
| 24 | |||||||||||||||
| 25 | 2192 | ▶ | sub quote { | ||||||||||||
|
Subroutine
quote: called CC=8 SCAR=22.2
Pod
undocumented
| |||||||||||||||
| 26 | 2192 | my ($self, $label) = @_; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 2192 | ▶ | return '' unless defined $label; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 2192 | ▶ | return $$label if ref($label) eq 'SCALAR'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | 2192 | my @quote_chars = @{ $self->quote_chars }; | |||||||||||||
| 32 | 2192 | ▶ | return $label unless scalar @quote_chars; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | |||||||||||||||
| 34 | 1455 | my ($l, $r); | |||||||||||||
| 35 | 1455 | ▶ | if (@quote_chars == 1) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | 0 | ($l, $r) = (@quote_chars) x 2; | |||||||||||||
| 37 | } elsif (@quote_chars == 2) { | ||||||||||||||
| 38 | 1455 | ($l, $r) = @quote_chars; | |||||||||||||
| 39 | } else { | ||||||||||||||
| 40 | 0 | die 'too many quote chars!'; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 1455 | ▶ | my $sep = $self->name_sep || ''; | ||||||||||||
|
Condition50%1/2
$self->name_sep || ''
MC/DC0%0/1
$self->name_sep || ''
$self->name_sep
Truth table50%1/2
A
A= $self->name_sep
| |||||||||||||||
| 44 | 1455 | my $esc = $self->escape_char; | |||||||||||||
| 45 | |||||||||||||||
| 46 | # parts containing * are naturally unquoted | ||||||||||||||
| 47 | 1455 | ▶ | join $sep, map { (my $n = $_) =~ s/\Q$r/$esc$r/g; "$l$n$r" } ($sep ? split(/\Q$sep\E/, $label) : $label); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 35 | ▶ | sub quote_string { | ||||||||||||
|
Subroutine
quote_string: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||
| 51 | 35 | my ($self, $string) = @_; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 35 | ▶ | return $string unless defined $string; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 35 | $string =~ s/'/''/g; | |||||||||||||
| 55 | 35 | return qq{'$string'}; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 26 | 1; | |||||||||||||
| 59 | |||||||||||||||
| 60 | =head1 AUTHORS | ||||||||||||||
| 61 | |||||||||||||||
| 62 | See the included AUTHORS file: | ||||||||||||||
| 63 | L<http://search.cpan.org/dist/SQL-Translator/AUTHORS> | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =head1 COPYRIGHT | ||||||||||||||
| 66 | |||||||||||||||
| 67 | Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above. | ||||||||||||||
| 68 | |||||||||||||||
| 69 | =head1 LICENSE | ||||||||||||||
| 70 | |||||||||||||||
| 71 | This code is free software and may be distributed under the same terms as Perl | ||||||||||||||
| 72 | itself. | ||||||||||||||
| 73 | |||||||||||||||
| 74 | =cut | ||||||||||||||