blib/lib/SQL/Translator/Generator/Role/Quote.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 57.1% 8 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 76.0% 38 / 50 CC 9 SCAR 18.9
CC
9
Cov
79%
quote
9.2
quote_string
2.0
BEGIN
1.0
CRAP 6.6
« 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
BranchTrueFalseTotal
unless defined $label 0 2192 2192
29 2192 ▶ return $$label if ref($label) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $label eq "SCALAR" 0 2192 2192
30  
31 2192 my @quote_chars = @{ $self->quote_chars };
32 2192 ▶ return $label unless scalar @quote_chars;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @quote_chars 737 1455 2192
33  
34 1455 my ($l, $r);
35 1455 ▶ if (@quote_chars == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@quote_chars == 1) { } 0 1455 1455
elsif (@quote_chars == 2) { } 1455 0 1455
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 || ''
l!l
14550
MC/DC0%0/1
$self->name_sep || ''
$self->name_sep
Truth table50%1/2
A
A= $self->name_sep
Aresult
11
00
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
BranchTrueFalseTotal
$sep ? : 1455 0 1455
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
BranchTrueFalseTotal
unless defined $string 0 35 35
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
« blib/lib/SQL/Translator/Producer/DB2.pm ↑ Summary blib/lib/SQL/Translator/Generator/DDL/SQLServer.pm »