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 SCAR 22.8
CC
9
Cov
79%
quote
9.2
quote_string
2.0
BEGIN
1.0
CRAP 9.7
« blib/lib/SQL/Translator/Role/ListAttr.pm ↑ Summary blib/lib/SQL/Translator/Schema/Role/Extra.pm »
1 package SQL::Translator::Generator::Role::Quote;
2  
3 25 ▶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 25 requires qw(quote_chars name_sep);
17  
18 has escape_char => (
19 is => 'ro',
20 lazy => 1,
21 clearer => 1,
22 21 ▶ default => sub { $_[0]->quote_chars->[-1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 25 );
24  
25 sub quote {
26 2150 ▶ my ($self, $label) = @_;
Subroutine quote: called CC=8 SCAR=22.2
Pod undocumented
27  
28 2150 ▶ return '' unless defined $label;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $label 0 2150 2150
29 2150 ▶ return $$label if ref($label) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $label eq "SCALAR" 0 2150 2150
30  
31 2150 my @quote_chars = @{$self->quote_chars};
32 2150 ▶ return $label unless scalar @quote_chars;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @quote_chars 724 1426 2150
33  
34 1426 my ($l, $r);
35 1426 ▶ if (@quote_chars == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@quote_chars == 1) { } 0 1426 1426
elsif (@quote_chars == 2) { } 1426 0 1426
36 0 ($l, $r) = (@quote_chars) x 2;
37 } elsif (@quote_chars == 2) {
38 1426 ($l, $r) = @quote_chars;
39 } else {
40 0 die 'too many quote chars!';
41 }
42  
43 1426 ▶ my $sep = $self->name_sep || '';
Condition50%1/2
$self->name_sep || ''
l!l
14260
MC/DC0%0/1
$self->name_sep || ''
$self->name_sep
Truth table50%1/2
A
A= $self->name_sep
Aresult
11
00
44 1426 my $esc = $self->escape_char;
45  
46 # parts containing * are naturally unquoted
47 1426 ▶ 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 ? : 1426 0 1426
48 }
49  
50 sub quote_string {
51 34 ▶ my ($self, $string) = @_;
Subroutine quote_string: called CC=2 SCAR=7.0
Pod undocumented
52  
53 34 ▶ return $string unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 34 34
54 34 $string =~ s/'/''/g;
55 34 return qq{'$string'};
56 }
57  
58 25 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/Role/ListAttr.pm ↑ Summary blib/lib/SQL/Translator/Schema/Role/Extra.pm »