File Coverage

blib/lib/Geoffrey/Role/Converter.pm
Criterion Covered Total %
statement 99 100 99.0
branch 22 28 78.5
condition 5 5 100.0
subroutine 33 33 100.0
pod 27 27 100.0
total 186 193 96.3


line stmt bran cond sub pod time code
1             package Geoffrey::Role::Converter;
2              
3 19     19   432727 use utf8;
  19         389  
  19         153  
4 19     19   913 use Carp qw/croak/;
  19         37  
  19         1167  
5 19     19   118 use strict;
  19         45  
  19         531  
6 19     19   83 use warnings;
  19         31  
  19         1046  
7 19     19   10293 use Perl::Version;
  19         81258  
  19         36655  
8              
9             $Geoffrey::Role::Converter::VERSION = '0.000206';
10              
11             sub new {
12 33     33 1 12338 my $class = shift;
13 33         224 my $self = {@_};
14 33         191 return bless $self, $class;
15             }
16              
17             sub changelog_table {
18 26   100 26 1 128 $_[0]->{changelog_table} //= 'geoffrey_changelogs';
19 26         104 return $_[0]->{changelog_table};
20             }
21              
22             sub changelog_columns {
23             return [
24 3     3 1 80 { name => 'id',
25             type => 'varchar',
26             lenght => 64,
27             primarykey => 1,
28             notnull => 1,
29             default => '\'\''
30             },
31             { name => 'created_by', type => 'varchar', lenght => 128, notnull => 1, default => '\'\'', },
32             { name => 'filename', type => 'varchar', lenght => 255, },
33             { name => 'md5sum', type => 'varchar', lenght => 64, },
34             { name => 'description', type => 'varchar', lenght => 255, },
35             { name => 'comment', type => 'varchar', lenght => 128, },
36             { name => 'geoffrey_version',
37             type => 'varchar',
38             lenght => 16,
39             notnull => 1,
40             default => '\'\''
41             },
42             { name => 'created', type => 'timestamp', default => 'current_timestamp', notnull => 1, },
43             ];
44             } ## end sub changelog_columns
45              
46             sub origin_types {
47             return [
48 83     83 1 1208 'abstime', 'aclitem', #Al
49             'bigint', 'bigserial', 'bit', 'varbit', 'blob', 'bool', 'box', 'bytea', #B
50             'char', 'character', 'varchar', 'cid', 'cidr', 'circle', #C
51             'date', 'daterange', 'double', 'double_precision', 'decimal', #D
52             #E
53             'float', #F
54             'gtsvector', #G
55             #H
56             'inet', 'int2vector', 'int4range', 'int8range', 'integer', 'interval', #I
57             'json', #J
58             #K
59             'line', 'lseg', #L
60             'macaddr', 'money', #M
61             'name', 'numeric', 'numrange', #N
62             'oid', 'oidvector', #O
63             'path', 'pg_node_tree', 'point', 'polygon', #P
64             #Q
65             'real', 'refcursor', 'regclass', 'regconfig', 'regdictionary', 'regoper', 'regoperator',
66             'regproc', 'regprocedure', 'regtype', 'reltime', #R
67             'serial', 'smallint', 'smallserial', 'smgr', #S
68             'text', 'tid', 'timestamp', 'timestamp_tz', 'time', 'time_tz', 'tinterval', 'tsquery',
69             'tsrange', 'tstzrange', 'tsvector', 'txid_snapshot', #T
70             'uuid', #U
71             #V
72             #W
73             'xid', #X
74             #Y
75             #Z
76             ];
77             } ## end sub origin_types
78              
79 9     9 1 43 sub min_version { return shift->{min_version} }
80              
81 9     9 1 32 sub max_version { return shift->{max_version} }
82              
83             sub can_create_empty_table;
84              
85             sub check_version {
86 9     9 1 8363 my ( $self, $s_version ) = @_;
87 9         56 $s_version = Perl::Version->new($s_version);
88 9         1190 my ( $s_max_version, $s_min_version ) = undef;
89 9 50       16 eval { $s_min_version = $self->min_version; } or do { };
  9         52  
90 9 100       17 eval { $s_max_version = $self->max_version; } or do { };
  9         32  
91 9         27 $s_min_version = Perl::Version->new($s_min_version);
92 9 100       783 if ($s_max_version) {
    100          
93 3         11 $s_max_version = Perl::Version->new($s_max_version);
94 3 100 100     380 return 1 if ( $s_min_version <= $s_version && $s_version <= $s_max_version );
95 2         111 require Geoffrey::Exception::NotSupportedException;
96 2         12 Geoffrey::Exception::NotSupportedException::throw_version( $self, $s_min_version, $s_version, $s_max_version );
97             } elsif ( $s_min_version <= $s_version ) {
98 5         176 return 1;
99             }
100 1         28 require Geoffrey::Exception::NotSupportedException;
101 1         3 return Geoffrey::Exception::NotSupportedException::throw_version( $self, $s_min_version, $s_version );
102             } ## end sub check_version
103              
104             sub type {
105 85     85 1 335 my ( $self, $hr_column_params ) = @_;
106 85 100       253 if ( !$hr_column_params->{type} ) {
107 2         766 require Geoffrey::Exception::RequiredValue;
108 2         12 Geoffrey::Exception::RequiredValue::throw_column_type($self);
109             }
110             my $s_column_type
111 5976         17460 = ( grep {/^$hr_column_params->{type}$/sxm} @{ $self->origin_types() } )
  83         233  
112             ? $self->types()->{ $hr_column_params->{type} }
113 83 100       135 : undef;
114 83 100       673 if ( !$s_column_type ) {
115 1         10 require Geoffrey::Exception::NotSupportedException;
116 1         7 Geoffrey::Exception::NotSupportedException::throw_column_type( $hr_column_params->{type}, $self );
117             }
118 82 50       301 $s_column_type .= $hr_column_params->{strict} ? '(strict)' : q//;
119 82 100       213 $s_column_type .= defined $hr_column_params->{lenght} ? qq~($hr_column_params->{lenght})~ : q//;
120 82         397 return $s_column_type;
121             } ## end sub type
122              
123             sub _get_table_hashref {
124 3     3   8 my ( $self, $dbh, $s_name, $ar_columns, $s_schema ) = @_;
125 3         14 my $s_select_get_table = $self->select_get_table;
126 3         27 my $sth = $dbh->prepare($s_select_get_table);
127 3 50       409 if ($s_schema) {
128 0 0       0 $sth->execute( $s_schema, $s_name ) or Carp::confess $!;
129             } else {
130 3 50       273 $sth->execute($s_name) or Carp::confess $!;
131             }
132 3         119 my $hr_table = $sth->fetchrow_hashref();
133 3 100       51 return if defined $hr_table;
134 2         47 return { name => $s_name, columns => $ar_columns, };
135             } ## end sub _get_table_hashref
136              
137             sub get_changelog_table_hashref {
138 3     3 1 9 my ( $self, $o_dbh, $s_schema ) = @_;
139 3         18 return $self->_get_table_hashref( $o_dbh, $self->changelog_table(), $self->changelog_columns(), $s_schema );
140             }
141              
142             sub constraints {
143 1     1 1 49 require Geoffrey::Exception::NotSupportedException;
144 1         4 return Geoffrey::Exception::NotSupportedException::throw_converter();
145             }
146              
147             sub index {
148 1     1 1 1223 require Geoffrey::Exception::NotSupportedException;
149 1         3 return Geoffrey::Exception::NotSupportedException::throw_converter();
150             }
151              
152             sub table {
153 1     1 1 1342 require Geoffrey::Exception::NotSupportedException;
154 1         5 return Geoffrey::Exception::NotSupportedException::throw_converter();
155             }
156              
157             sub view {
158 1     1 1 1360 require Geoffrey::Exception::NotSupportedException;
159 1         3 return Geoffrey::Exception::NotSupportedException::throw_converter();
160             }
161              
162             sub foreign_key {
163 1     1 1 1493 require Geoffrey::Exception::NotSupportedException;
164 1         6 return Geoffrey::Exception::NotSupportedException::throw_converter();
165             }
166              
167             sub trigger {
168 1     1 1 1344 require Geoffrey::Exception::NotSupportedException;
169 1         4 return Geoffrey::Exception::NotSupportedException::throw_converter();
170             }
171              
172             sub primary_key {
173 1     1 1 1319 require Geoffrey::Exception::NotSupportedException;
174 1         3 return Geoffrey::Exception::NotSupportedException::throw_converter();
175             }
176              
177             sub sequence {
178 7     7 1 1181 require Geoffrey::Exception::NotSupportedException;
179 7         37 return Geoffrey::Exception::NotSupportedException::throw_converter();
180             }
181              
182             sub function {
183 6     6 1 1159 require Geoffrey::Exception::NotSupportedException;
184 6         25 return Geoffrey::Exception::NotSupportedException::throw_converter();
185             }
186              
187             sub unique {
188 1     1 1 1564 require Geoffrey::Exception::NotSupportedException;
189 1         63 return Geoffrey::Exception::NotSupportedException::throw_converter();
190             }
191              
192             sub colums_information {
193 2     2 1 2006 require Geoffrey::Exception::NotSupportedException;
194 2         30 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'colums_information', shift );
195             }
196              
197             sub index_information {
198 2     2 1 1390 require Geoffrey::Exception::NotSupportedException;
199 2         11 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'index_information', shift );
200             }
201              
202             sub view_information {
203 2     2 1 1290 require Geoffrey::Exception::NotSupportedException;
204 2         11 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'view_information', shift );
205             }
206              
207             sub sequence_information {
208 1     1 1 1127 require Geoffrey::Exception::NotSupportedException;
209 1         4 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'sequence_information', shift );
210             }
211              
212             sub primary_key_information {
213 1     1 1 1141 require Geoffrey::Exception::NotSupportedException;
214 1         4 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'primary_key_information', shift );
215             }
216              
217             sub function_information {
218 2     2 1 3727 require Geoffrey::Exception::NotSupportedException;
219 2         8 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'function_information', shift );
220             }
221              
222             sub unique_information {
223 1     1 1 1133 require Geoffrey::Exception::NotSupportedException;
224 1         4 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'unique_information', shift );
225             }
226              
227             sub trigger_information {
228 1     1 1 2795 require Geoffrey::Exception::NotSupportedException;
229 1         7 return Geoffrey::Exception::NotSupportedException::throw_list_information( 'trigger_information', shift );
230             }
231              
232             1; # End of Geoffrey::converter
233              
234             __END__