| 1 | # vim: set ts=2 sts=2 sw=2 expandtab smarttab: | ||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of DBIx-TableLoader | ||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2011 by Randy Stauner. | ||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | package DBIx::TableLoader; | ||||||||||||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||||||||||||
| 15 | 8 | $DBIx::TableLoader::VERSION = '1.100'; | |||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||
| 17 | # git description: v1.003-5-gb3c3fb7 | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | BEGIN { | ||||||||||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | $DBIx::TableLoader::AUTHORITY = 'cpan:RWSTAUNER'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||
| 22 | # ABSTRACT: Easily load a database table from a data set | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | #use DBI 1.13 (); # oldest DBI on CPAN as of 2011-02-15; Has SQL_LONGVARCHAR | ||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | use Try::Tiny 0.09; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 30 | 44 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 31 | 44 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | 44 | ▶ | my %opts = @_ == 1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 44 | my %defaults = (%{ $self->base_defaults }, %{ $self->defaults }); | |||||||||||||||||||||||||||||||||||||
| 36 | 44 | ▶ | while( my ($key, $value) = each %defaults ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 37 | $self->{$key} = exists($opts{$key}) | ||||||||||||||||||||||||||||||||||||||
| 38 | 1102 | ▶ | ? delete $opts{$key} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 39 | : $value; | ||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | # be loud about typos | ||||||||||||||||||||||||||||||||||||||
| 43 | 44 | ▶ | croak("Unknown options: ${\join(', ', keys %opts)}") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 44 | if %opts; | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | # custom routine to handle type of input data (hook for subclasses) | ||||||||||||||||||||||||||||||||||||||
| 47 | 43 | $self->prepare_data(); | |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | # normalize 'columns' attribute | ||||||||||||||||||||||||||||||||||||||
| 50 | 43 | $self->determine_column_types(); | |||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||
| 52 | 41 | return $self; | |||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | sub base_defaults { | ||||||||||||||||||||||||||||||||||||||
| 57 | return { | ||||||||||||||||||||||||||||||||||||||
| 58 | 44 | ▶ | catalog => undef, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
base_defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 59 | columns => undef, | ||||||||||||||||||||||||||||||||||||||
| 60 | create => 1, | ||||||||||||||||||||||||||||||||||||||
| 61 | create_prefix => '', | ||||||||||||||||||||||||||||||||||||||
| 62 | create_sql => '', | ||||||||||||||||||||||||||||||||||||||
| 63 | create_suffix => '', | ||||||||||||||||||||||||||||||||||||||
| 64 | # 'data' attribute may not be useful in subclasses | ||||||||||||||||||||||||||||||||||||||
| 65 | data => undef, | ||||||||||||||||||||||||||||||||||||||
| 66 | dbh => undef, | ||||||||||||||||||||||||||||||||||||||
| 67 | default_column_type => '', | ||||||||||||||||||||||||||||||||||||||
| 68 | default_sql_data_type => '', | ||||||||||||||||||||||||||||||||||||||
| 69 | drop => 0, | ||||||||||||||||||||||||||||||||||||||
| 70 | drop_prefix => '', | ||||||||||||||||||||||||||||||||||||||
| 71 | drop_sql => '', | ||||||||||||||||||||||||||||||||||||||
| 72 | drop_suffix => '', | ||||||||||||||||||||||||||||||||||||||
| 73 | get_row => undef, | ||||||||||||||||||||||||||||||||||||||
| 74 | grep_rows => undef, | ||||||||||||||||||||||||||||||||||||||
| 75 | handle_invalid_row => undef, | ||||||||||||||||||||||||||||||||||||||
| 76 | map_rows => undef, | ||||||||||||||||||||||||||||||||||||||
| 77 | # default_name() method will default to 'data' if 'name' is blank | ||||||||||||||||||||||||||||||||||||||
| 78 | # this way subclasses don't have to override this value in defaults() | ||||||||||||||||||||||||||||||||||||||
| 79 | name => '', | ||||||||||||||||||||||||||||||||||||||
| 80 | name_prefix => '', | ||||||||||||||||||||||||||||||||||||||
| 81 | name_suffix => '', | ||||||||||||||||||||||||||||||||||||||
| 82 | quoted_name => undef, | ||||||||||||||||||||||||||||||||||||||
| 83 | schema => undef, | ||||||||||||||||||||||||||||||||||||||
| 84 | table_type => '', # TEMP, TEMPORARY, VIRTUAL? | ||||||||||||||||||||||||||||||||||||||
| 85 | transaction => 1, | ||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | sub defaults { | ||||||||||||||||||||||||||||||||||||||
| 91 | 42 | ▶ | return {}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | sub columns { | ||||||||||||||||||||||||||||||||||||||
| 96 | 146 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 97 | # by default the column names are found in the first row of the data | ||||||||||||||||||||||||||||||||||||||
| 98 | # (but circumvent get_row() to avoid any grep or map subs) | ||||||||||||||||||||||||||||||||||||||
| 99 | 146 | ▶ | return $self->{columns} ||= $self->_get_custom_or_raw_row(); | ||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"columns"} ||= $self->_get_custom_or_raw_row
MC/DC100%2/2
$self->{"columns"} ||= $self->_get_custom_or_raw_row
$self->{"columns"}
$self->_get_custom_or_raw_row
Truth table100%3/3
A ||= B
A= $self->{"columns"}B= $self->_get_custom_or_raw_row
| |||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | sub column_names { | ||||||||||||||||||||||||||||||||||||||
| 104 | 29 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
column_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 105 | # return the first element of each arrayref | ||||||||||||||||||||||||||||||||||||||
| 106 | 29 | return [ map { $$_[0] } @{ $self->columns } ]; | |||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | sub create { | ||||||||||||||||||||||||||||||||||||||
| 111 | 10 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 112 | 10 | $self->{dbh}->do($self->create_sql); | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | sub create_prefix { | ||||||||||||||||||||||||||||||||||||||
| 117 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_prefix: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 118 | return $self->{create_prefix} ||= | ||||||||||||||||||||||||||||||||||||||
| 119 | 16 | ▶ | "CREATE $self->{table_type} TABLE " . | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"create_prefix"} ||= qq[CREATE $self->{"table_type"} TABLE ] . $self->quoted_name . ' ('
MC/DC100%1/1
$self->{"create_prefix"} ||= qq[CREATE $self->{"table_type"} TABLE ] . $self->quoted_name . ' ('
$self->{"create_prefix"}
Truth table100%2/2
A
A= $self->{"create_prefix"}
| |||||||||||||||||||||||||||||||||||||||
| 120 | $self->quoted_name . " ("; | ||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | sub create_sql { | ||||||||||||||||||||||||||||||||||||||
| 125 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_sql: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 126 | $self->{create_sql} ||= | ||||||||||||||||||||||||||||||||||||||
| 127 | join(' ', | ||||||||||||||||||||||||||||||||||||||
| 128 | $self->create_prefix, | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | # column definitions (each element is: [name, data_type]) | ||||||||||||||||||||||||||||||||||||||
| 131 | join(', ', map { | ||||||||||||||||||||||||||||||||||||||
| 132 | 20 | $self->{dbh}->quote_identifier($_->[0]) . ' ' . $_->[1] | |||||||||||||||||||||||||||||||||||||
| 133 | 16 | ▶ | } @{ $self->columns }), | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"create_sql"} ||= join(" ", $self->create_prefix, join(", ", map({$self->{"dbh"}->quote_identifier($_->[0]) . ' ' . $_->[1];} @{$self->columns;})), $self->create_suffix)
MC/DC0%0/2
$self->{"create_sql"} ||= join(" ", $self->create_prefix, join(", ", map({$self->{"dbh"}->quote_identifier($_->[0]) . ' ' . $_->[1];} @{$self->columns;})), $self->create_suffix)
$self->{"create_sql"}
join(" ", $self->create_prefix, join(", ", map({$self->{"dbh"}->quote_identifier($_->[0]) . ' ' . $_->[1];} @{$self->columns;})), $self->create_suffix)
Truth table66%2/3
A ||= B
A= $self->{"create_sql"}B= join(" ", $self->create_prefix, join(", ", map({$self->{"dbh"}->quote_identifier($_->[0]) . ' ' . $_->[1];} @{$self->columns;})), $self->create_suffix)
| |||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | $self->create_suffix | ||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | sub create_suffix { | ||||||||||||||||||||||||||||||||||||||
| 141 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_suffix: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 142 | return $self->{create_suffix} ||= | ||||||||||||||||||||||||||||||||||||||
| 143 | 16 | ▶ | ')'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"create_suffix"} ||= ")"
MC/DC100%1/1
$self->{"create_suffix"} ||= ")"
$self->{"create_suffix"}
Truth table100%2/2
A
A= $self->{"create_suffix"}
| |||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | # ask the driver what data type it uses for the desired SQL standard type | ||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | sub _data_type_from_driver { | ||||||||||||||||||||||||||||||||||||||
| 149 | 27 | ▶ | my ($self, $data_type) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_data_type_from_driver: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 150 | 27 | ▶ | if( my $type = $self->{dbh}->type_info($data_type) ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 151 | 17 | return $type->{TYPE_NAME}; | |||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||
| 153 | 3 | return; | |||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | sub default_name { | ||||||||||||||||||||||||||||||||||||||
| 158 | 16 | ▶ | return 'data'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
default_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | sub default_column_type { | ||||||||||||||||||||||||||||||||||||||
| 163 | 46 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
default_column_type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 164 | return $self->{default_column_type} ||= try { | ||||||||||||||||||||||||||||||||||||||
| 165 | 27 | ▶ | $self->_data_type_from_driver($self->default_sql_data_type); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||
| 167 | # outside the eval in case there was an error | ||||||||||||||||||||||||||||||||||||||
| 168 | 46 | ▶ | || 'text'; | ||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$self->{"default_column_type"} ||= &try(sub {
$self->_data_type_from_driver($self->default_sql_data_type);
}
) || "text"
&try(sub {
$self->_data_type_from_driver($self->default_sql_data_type);
}
) || 'text'
MC/DC0%0/2
$self->{"default_column_type"} ||= &try(sub {
$self->_data_type_from_driver($self->default_sql_data_type);
}
) || "text"
$self->{"default_column_type"}
&try(sub {
$self->_data_type_from_driver($self->default_sql_data_type);
}
)
Truth table66%2/3
A ||= B
A= $self->{"default_column_type"}B= &try(sub {
$self->_data_type_from_driver($self->default_sql_data_type);
}
)
| |||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | sub default_sql_data_type { | ||||||||||||||||||||||||||||||||||||||
| 173 | 28 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
default_sql_data_type: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 174 | $self->{default_sql_data_type} ||= try { | ||||||||||||||||||||||||||||||||||||||
| 175 | # if this doesn't work default_column_type will just use 'text' | ||||||||||||||||||||||||||||||||||||||
| 176 | 27 | ▶ | require DBI; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 177 | 27 | DBI::SQL_LONGVARCHAR(); | |||||||||||||||||||||||||||||||||||||
| 178 | 28 | ▶ | }; | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"default_sql_data_type"} ||= &try(sub {
require DBI;
DBI::SQL_LONGVARCHAR();
}
)
MC/DC0%0/2
$self->{"default_sql_data_type"} ||= &try(sub {
require DBI;
DBI::SQL_LONGVARCHAR();
}
)
$self->{"default_sql_data_type"}
&try(sub {
require DBI;
DBI::SQL_LONGVARCHAR();
}
)
Truth table66%2/3
A ||= B
A= $self->{"default_sql_data_type"}B= &try(sub {
require DBI;
DBI::SQL_LONGVARCHAR();
}
)
| |||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | sub determine_column_types { | ||||||||||||||||||||||||||||||||||||||
| 183 | 43 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
determine_column_types: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 184 | 43 | my ($columns, $type) = ($self->columns, $self->default_column_type); | |||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | 43 | ▶ | croak("Unable to determine columns!") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$columns and @$columns
MC/DC100%2/2
$columns and @$columns
$columns
@$columns
Truth table100%3/3
A and B
A= $columnsB= @$columns
| |||||||||||||||||||||||||||||||||||||||
| 187 | unless $columns && @$columns; | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | # break reference | ||||||||||||||||||||||||||||||||||||||
| 190 | 41 | $columns = [@$columns]; | |||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | # reset each element to an arrayref if it isn't already | ||||||||||||||||||||||||||||||||||||||
| 193 | 41 | foreach my $column ( @$columns ){ | |||||||||||||||||||||||||||||||||||||
| 194 | # upgrade lone string to arrayref otherwise break reference | ||||||||||||||||||||||||||||||||||||||
| 195 | 84 | ▶ | $column = ref $column ? [@$column] : [$column]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 196 | # append column type if missing | ||||||||||||||||||||||||||||||||||||||
| 197 | 84 | ▶ | push(@$column, $type) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 198 | unless @$column > 1; | ||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||
| 201 | # restore changes | ||||||||||||||||||||||||||||||||||||||
| 202 | 41 | $self->{columns} = $columns; | |||||||||||||||||||||||||||||||||||||
| 203 | 41 | return; | |||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||
| 207 | sub drop { | ||||||||||||||||||||||||||||||||||||||
| 208 | 8 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 209 | 8 | $self->{dbh}->do($self->drop_sql); | |||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | sub drop_prefix { | ||||||||||||||||||||||||||||||||||||||
| 214 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_prefix: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 215 | # default to "DROP TABLE" since SQLite, PostgreSQL, and MySQL | ||||||||||||||||||||||||||||||||||||||
| 216 | # all accept it (rather than "DROP $table_type TABLE") | ||||||||||||||||||||||||||||||||||||||
| 217 | 16 | ▶ | $self->{drop_prefix} ||= 'DROP TABLE'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"drop_prefix"} ||= "DROP TABLE"
MC/DC100%1/1
$self->{"drop_prefix"} ||= "DROP TABLE"
$self->{"drop_prefix"}
Truth table100%2/2
A
A= $self->{"drop_prefix"}
| |||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | sub drop_sql { | ||||||||||||||||||||||||||||||||||||||
| 222 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_sql: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 223 | 16 | ▶ | return $self->{drop_sql} ||= join(' ', | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"drop_sql"} ||= join(" ", $self->drop_prefix, $self->quoted_name, $self->drop_suffix)
MC/DC0%0/2
$self->{"drop_sql"} ||= join(" ", $self->drop_prefix, $self->quoted_name, $self->drop_suffix)
$self->{"drop_sql"}
join(" ", $self->drop_prefix, $self->quoted_name, $self->drop_suffix)
Truth table66%2/3
A ||= B
A= $self->{"drop_sql"}B= join(" ", $self->drop_prefix, $self->quoted_name, $self->drop_suffix)
| |||||||||||||||||||||||||||||||||||||||
| 224 | $self->drop_prefix, | ||||||||||||||||||||||||||||||||||||||
| 225 | $self->quoted_name, | ||||||||||||||||||||||||||||||||||||||
| 226 | $self->drop_suffix, | ||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | sub drop_suffix { | ||||||||||||||||||||||||||||||||||||||
| 232 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_suffix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 233 | # default is blank | ||||||||||||||||||||||||||||||||||||||
| 234 | 16 | return $self->{drop_suffix}; | |||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | # call get_raw_row unless a custom 'get_row' is defined | ||||||||||||||||||||||||||||||||||||||
| 238 | # (this is the essence of get_row() but without the grep/map subs) | ||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||
| 240 | sub _get_custom_or_raw_row { | ||||||||||||||||||||||||||||||||||||||
| 241 | 88 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_custom_or_raw_row: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 242 | # considered { $self->{get_row} ||= $self->can('get_raw_row'); } in new() | ||||||||||||||||||||||||||||||||||||||
| 243 | # but it just seemed a little strange... this is more normal/clear | ||||||||||||||||||||||||||||||||||||||
| 244 | return $self->{get_row} | ||||||||||||||||||||||||||||||||||||||
| 245 | 88 | ▶ | ? $self->{get_row}->($self) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 246 | : $self->get_raw_row(); | ||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | sub get_raw_row { | ||||||||||||||||||||||||||||||||||||||
| 251 | 67 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_raw_row: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 252 | # It would be simpler to shift the data but I don't think it actually | ||||||||||||||||||||||||||||||||||||||
| 253 | # gains us anything. This way we're not modifying anything unexpectedly. | ||||||||||||||||||||||||||||||||||||||
| 254 | # Besides subclasses will likely be more useful than this one. | ||||||||||||||||||||||||||||||||||||||
| 255 | 67 | return $self->{data}->[ $self->{row_index}++ ]; | |||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | sub get_row { | ||||||||||||||||||||||||||||||||||||||
| 260 | 69 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_row: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 261 | 69 | my $row; | |||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | GETROW: { | ||||||||||||||||||||||||||||||||||||||
| 264 | 69 | ▶ | $row = $self->_get_custom_or_raw_row() | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 265 | or last GETROW; | ||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||
| 267 | # call grep_rows with the same semantics as map_rows (below) | ||||||||||||||||||||||||||||||||||||||
| 268 | 55 | ▶ | if( $self->{grep_rows} ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 269 | 6 | local $_ = $row; | |||||||||||||||||||||||||||||||||||||
| 270 | # if grep returns false try the block again | ||||||||||||||||||||||||||||||||||||||
| 271 | redo GETROW | ||||||||||||||||||||||||||||||||||||||
| 272 | 6 | ▶ | unless $self->{grep_rows}->($row, $self); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | # Send the row first since it's the important part. | ||||||||||||||||||||||||||||||||||||||
| 276 | # This isn't a method call, and $self will likely be seldom used. | ||||||||||||||||||||||||||||||||||||||
| 277 | 53 | ▶ | if( $self->{map_rows} ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 278 | # localize $_ to the $row for consistency with the built in map() | ||||||||||||||||||||||||||||||||||||||
| 279 | 11 | local $_ = $row; | |||||||||||||||||||||||||||||||||||||
| 280 | # also pass row as the first argument to simulate a normal function call | ||||||||||||||||||||||||||||||||||||||
| 281 | 11 | $row = $self->{map_rows}->($row, $self); | |||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | # validate the row before passing a bad value to the DBI | ||||||||||||||||||||||||||||||||||||||
| 285 | $row = try { | ||||||||||||||||||||||||||||||||||||||
| 286 | 53 | ▶ | $self->validate_row($row); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||
| 288 | catch { | ||||||||||||||||||||||||||||||||||||||
| 289 | # file/line position is unhelpful, but so is the newline | ||||||||||||||||||||||||||||||||||||||
| 290 | 12 | ▶ | chomp(my $e = $_[0]); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 291 | # if there was an error, pass it through the handler | ||||||||||||||||||||||||||||||||||||||
| 292 | # the handler should die, return a row, or return false to skip | ||||||||||||||||||||||||||||||||||||||
| 293 | 12 | $self->handle_invalid_row($e, $row); | |||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||
| 295 | 53 | ▶ | or redo GETROW; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||
| 298 | 65 | return $row; | |||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||
| 302 | sub handle_invalid_row { | ||||||||||||||||||||||||||||||||||||||
| 303 | 15 | ▶ | my ($self, $error, $row) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_invalid_row: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | 15 | ▶ | if( my $handler = $self->{handle_invalid_row} ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 306 | # should this be croak/carp? | ||||||||||||||||||||||||||||||||||||||
| 307 | 14 | ▶ | if( $handler eq 'die' ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 308 | 3 | die $error . "\n"; | |||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||
| 310 | elsif( $handler eq 'warn' ){ | ||||||||||||||||||||||||||||||||||||||
| 311 | 1 | warn $error . "\n"; | |||||||||||||||||||||||||||||||||||||
| 312 | 1 | return $row; | |||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||
| 314 | # otherwise it should be a coderef (or a method name (for a subclass maybe)) | ||||||||||||||||||||||||||||||||||||||
| 315 | else { | ||||||||||||||||||||||||||||||||||||||
| 316 | 10 | return $self->$handler($error, $row); | |||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | # pass through if no handler was defined | ||||||||||||||||||||||||||||||||||||||
| 321 | 1 | return $row; | |||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||
| 325 | sub insert_sql { | ||||||||||||||||||||||||||||||||||||||
| 326 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_sql: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 327 | join(' ', | ||||||||||||||||||||||||||||||||||||||
| 328 | 'INSERT INTO', | ||||||||||||||||||||||||||||||||||||||
| 329 | $self->quoted_name, | ||||||||||||||||||||||||||||||||||||||
| 330 | '(', | ||||||||||||||||||||||||||||||||||||||
| 331 | 12 | join(', ', @{ $self->quoted_column_names } ), | |||||||||||||||||||||||||||||||||||||
| 332 | ')', | ||||||||||||||||||||||||||||||||||||||
| 333 | 'VALUES(', | ||||||||||||||||||||||||||||||||||||||
| 334 | 12 | join(', ', ('?') x @{ $self->columns }), | |||||||||||||||||||||||||||||||||||||
| 335 | ')' | ||||||||||||||||||||||||||||||||||||||
| 336 | ); | ||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | sub insert_all { | ||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_all: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | 7 | my $rows = 0; | |||||||||||||||||||||||||||||||||||||
| 344 | 7 | my $sth = $self->{dbh}->prepare($self->insert_sql); | |||||||||||||||||||||||||||||||||||||
| 345 | 7 | ▶ | while( my $row = $self->get_row() ){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 346 | 8 | $sth->execute(@$row); | |||||||||||||||||||||||||||||||||||||
| 347 | 8 | ++$rows; | |||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||
| 350 | 6 | return $rows; | |||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||
| 354 | sub load { | ||||||||||||||||||||||||||||||||||||||
| 355 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 356 | 4 | my $rows; | |||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||
| 358 | # is it appropriate/sufficient to call prepare_data() from new()? | ||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||
| 360 | try { | ||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | $self->{dbh}->begin_work() | ||||||||||||||||||||||||||||||||||||||
| 363 | 4 | ▶ | if $self->{transaction}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||
| 365 | $self->drop() | ||||||||||||||||||||||||||||||||||||||
| 366 | 4 | ▶ | if $self->{drop}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | $self->create() | ||||||||||||||||||||||||||||||||||||||
| 369 | 4 | ▶ | if $self->{create}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | 4 | $rows = $self->insert_all(); | |||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||
| 373 | $self->{dbh}->commit() | ||||||||||||||||||||||||||||||||||||||
| 374 | 3 | ▶ | if $self->{transaction}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||
| 377 | catch { | ||||||||||||||||||||||||||||||||||||||
| 378 | # explicitly end the transaction that we started | ||||||||||||||||||||||||||||||||||||||
| 379 | # in case this isn't the last thing being done with the dbh | ||||||||||||||||||||||||||||||||||||||
| 380 | $self->{dbh}->rollback() | ||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | if $self->{transaction}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||
| 383 | # propagate the exception | ||||||||||||||||||||||||||||||||||||||
| 384 | 1 | die $_[0]; | |||||||||||||||||||||||||||||||||||||
| 385 | 4 | }; | |||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | 3 | return $rows; | |||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||
| 391 | sub name { | ||||||||||||||||||||||||||||||||||||||
| 392 | 24 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 393 | return $self->{_name} ||= | ||||||||||||||||||||||||||||||||||||||
| 394 | $self->{name_prefix} . | ||||||||||||||||||||||||||||||||||||||
| 395 | ($self->{name} || $self->default_name) . | ||||||||||||||||||||||||||||||||||||||
| 396 | 24 | ▶ | $self->{name_suffix}; | ||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{"_name"} ||= $self->{"name_prefix"} . ($self->{"name"} || $self->default_name) . $self->{"name_suffix"}
$self->{'name'} || $self->default_name
MC/DC0%0/2
$self->{"_name"} ||= $self->{"name_prefix"} . ($self->{"name"} || $self->default_name) . $self->{"name_suffix"}
$self->{"_name"}
$self->{"name_prefix"} . ($self->{"name"} || $self->default_name) . $self->{"name_suffix"}
MC/DC0%0/2
$self->{'name'} || $self->default_name
$self->{'name'}
$self->default_name
Truth table66%2/3
A ||= B
A= $self->{"_name"}B= $self->{"name_prefix"} . ($self->{"name"} || $self->default_name) . $self->{"name_suffix"}
Truth table66%2/3
A || B
A= $self->{'name'}B= $self->default_name
| |||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||
| 400 | sub prepare_data { | ||||||||||||||||||||||||||||||||||||||
| 401 | 42 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 402 | 42 | $self->{row_index} = 0; | |||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||
| 406 | sub quoted_name { | ||||||||||||||||||||||||||||||||||||||
| 407 | 33 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
quoted_name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 408 | # allow quoted name to be passed in to handle edge cases | ||||||||||||||||||||||||||||||||||||||
| 409 | return $self->{quoted_name} ||= | ||||||||||||||||||||||||||||||||||||||
| 410 | $self->{dbh}->quote_identifier( | ||||||||||||||||||||||||||||||||||||||
| 411 | 33 | ▶ | $self->{catalog}, $self->{schema}, $self->name); | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"quoted_name"} ||= $self->{"dbh"}->quote_identifier($self->{"catalog"}, $self->{"schema"}, $self->name)
MC/DC0%0/2
$self->{"quoted_name"} ||= $self->{"dbh"}->quote_identifier($self->{"catalog"}, $self->{"schema"}, $self->name)
$self->{"quoted_name"}
$self->{"dbh"}->quote_identifier($self->{"catalog"}, $self->{"schema"}, $self->name)
Truth table66%2/3
A ||= B
A= $self->{"quoted_name"}B= $self->{"dbh"}->quote_identifier($self->{"catalog"}, $self->{"schema"}, $self->name)
| |||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | sub quoted_column_names { | ||||||||||||||||||||||||||||||||||||||
| 416 | 16 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
quoted_column_names: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 417 | return $self->{quoted_column_names} ||= [ | ||||||||||||||||||||||||||||||||||||||
| 418 | 36 | map { $self->{dbh}->quote_identifier($_) } | |||||||||||||||||||||||||||||||||||||
| 419 | 16 | ▶ | @{ $self->column_names } | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"quoted_column_names"} ||= [map({$self->{"dbh"}->quote_identifier($_);} @{$self->column_names;})]
MC/DC0%0/1
$self->{"quoted_column_names"} ||= [map({$self->{"dbh"}->quote_identifier($_);} @{$self->column_names;})]
$self->{"quoted_column_names"}
Truth table50%1/2
A
A= $self->{"quoted_column_names"}
| |||||||||||||||||||||||||||||||||||||||
| 420 | ]; | ||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | sub validate_row { | ||||||||||||||||||||||||||||||||||||||
| 425 | 48 | ▶ | my ($self, $row) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_row: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | # DBI will croak if exec'd with different numbers | ||||||||||||||||||||||||||||||||||||||
| 428 | 48 | my $num_columns = @{ $self->columns }; | |||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||
| 430 | 48 | ▶ | die 'Row has ' . @$row . ' fields when ' . $num_columns . " are expected\n" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 431 | if @$row != $num_columns; | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | # are there other validation checks we can do? | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | 36 | return $row; | |||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | 8 | 1; | |||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | __END__ | ||||||||||||||||||||||||||||||||||||||