blib/lib/Otogiri/Plugin/TableInfo/PgKeywords.pm

filter: Statementstmt 50.0% 11 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 45.1% 14 / 31 CC 2 SCAR 10.4
CC
2
Cov
46%
quote
6.0
new
2.0
BEGIN
1.0
CRAP 2.8
« Build ↑ Summary _build/lib/MyBuilder.pm »
1 package Otogiri::Plugin::TableInfo::PgKeywords;
2 2 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # keywords are picked from postgresql-9.3.4/src/include/parser/kwlist.h
7  
8 # COL_NAME_KEYWORD
9 2 my @col_name_keywords = (
10 'between',
11 'bigint',
12 'bit',
13 'boolean',
14 'char',
15 'character',
16 'coalesce',
17 'dec',
18 'decimal',
19 'exists',
20 'extract',
21 'float',
22 'greatest',
23 'inout',
24 'int',
25 'integer',
26 'interval',
27 'least',
28 'national',
29 'nchar',
30 'none',
31 'nullif',
32 'numeric',
33 'out',
34 'overlay',
35 'position',
36 'precision',
37 'real',
38 'row',
39 'setof',
40 'smallint',
41 'substring',
42 'time',
43 'timestamp',
44 'treat',
45 'trim',
46 'values',
47 'varchar',
48 'xmlattributes',
49 'xmlconcat',
50 'xmlelement',
51 'xmlexists',
52 'xmlforest',
53 'xmlparse',
54 'xmlpi',
55 'xmlroot',
56 'xmlserialize',
57 );
58  
59 # RESERVED_KEYWORD
60 2 my @reserved_keywords = (
61 "all",
62 "analyse",
63 "analyze",
64 "and",
65 "any",
66 "array",
67 "as",
68 "asc",
69 "asymmetric",
70 "both",
71 "case",
72 "cast",
73 "check",
74 "collate",
75 "column",
76 "constraint",
77 "create",
78 "current_catalog",
79 "current_date",
80 "current_role",
81 "current_time",
82 "current_timestamp",
83 "current_user",
84 "default",
85 "deferrable",
86 "desc",
87 "distinct",
88 "do",
89 "else",
90 "end",
91 "except",
92 "false",
93 "fetch",
94 "for",
95 "foreign",
96 "from",
97 "grant",
98 "group",
99 "having",
100 "in",
101 "initially",
102 "intersect",
103 "into",
104 "lateral",
105 "leading",
106 "limit",
107 "localtime",
108 "localtimestamp",
109 "not",
110 "null",
111 "offset",
112 "on",
113 "only",
114 "or",
115 "order",
116 "placing",
117 "primary",
118 "references",
119 "returning",
120 "select",
121 "session_user",
122 "some",
123 "symmetric",
124 "table",
125 "then",
126 "to",
127 "trailing",
128 "true",
129 "union",
130 "unique",
131 "user",
132 "using",
133 "variadic",
134 "when",
135 "where",
136 "window",
137 "with",
138 );
139  
140 sub new {
141 0 ▶ my ($class) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
142 0 my @keywords = (@col_name_keywords, @reserved_keywords);
143 0 my %keyword_hash = map { ($_ => 1) } @keywords;
144 0 my %keyword_hash_uc = map { (uc($_) => 1) } @keywords;
145 0 my $self = {
146 keyword => { %keyword_hash, %keyword_hash_uc },
147 };
148 0 bless $self, $class;
149 }
150  
151 sub quote {
152 0 ▶ my ($self, $column_name) = @_;
Subroutine quote: not called CC=2 SCAR=17.9
Pod undocumented
153 0 ▶ return '"' . $column_name . '"' if ( exists $self->{keyword}->{$column_name} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"keyword"}{$column_name} 0 0 0
154 0 return $column_name;
155 }
156  
157  
158 2 1;
159 __END__
160  
161 =encoding utf-8
162  
163 =head1 NAME
164  
165 Otogiri::Plugin::TableInfo::PgKeywords - PostgreSQL Keywords
166  
167 =head1 SYNOPSIS
168  
169 use Otogiri::Plugin::TableInfo::PgKeywords;
170 my $k = Otogiri::Plugin::TableInfo::PgKeywords->new();
171 my $quoted = $k->quote('position'); # => '"position"'
172  
173  
174 =head1 DESCRIPTION
175  
176 Provide PostgreSQL Keyword
177  
178 =head1 METHODS
179  
180 =head2 my $quoted_column = $self->quote_column($column_name);
181  
182 quote column name if column uses reserved word
183  
184 =cut
« Build ↑ Summary _build/lib/MyBuilder.pm »