File Coverage

blib/lib/Data/Generator/FromDDL/Util.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition 4 6 66.6
subroutine 6 6 100.0
pod 0 3 0.0
total 29 34 85.2


line stmt bran cond sub pod time code
1             package Data::Generator::FromDDL::Util;
2 6     6   35 use strict;
  6         11  
  6         296  
3 6     6   36 use warnings;
  6         13  
  6         234  
4 6     6   35 use base qw(Exporter);
  6         12  
  6         1783  
5              
6             our @EXPORT_OK = qw(
7             normalize_parser_str
8             need_quote_data_type
9             get_numeric_type_byte
10             );
11              
12             sub normalize_parser_str {
13 20     20 0 72 my $parser = lc(shift);
14 20         182 my %normalized_parsers = (
15             mysql => 'MySQL',
16             sqlite => 'SQLite',
17             oracle => 'Oracle',
18             postgresql => 'PostgreSQL',
19             );
20              
21 20   50     608 return $normalized_parsers{$parser} || undef;
22             }
23              
24             sub need_quote_data_type {
25 22     22 0 64 my $type = lc(shift);
26 22         65 my %quote_data_types = map { $_ => 1 }
  154         408  
27             qw(char varchar tinytext text mediumtext timestamp enum);
28              
29 22   100     237 return $quote_data_types{$type} || undef;
30             }
31              
32             sub get_numeric_type_byte {
33 6     6 0 20 my $type = lc(shift);
34 6         58 my %numeric_type_bytes = (
35             bigint => 8,
36             int => 4,
37             integer => 4,
38             mediumint => 3,
39             smallint => 2,
40             tinyint => 1,
41             # UNIX timestamps are signed integer
42             timestamp => 4,
43             );
44              
45 6   50     43 return $numeric_type_bytes{$type} || 0;
46             }
47              
48             1;