| 1 | package CohortExplorer::Datasource; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = 0.14; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Config::General; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use CLI::Framework::Exceptions qw ( :all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Exception::Class::TryCatch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use SQL::Abstract::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Tie::Autotie 'Tie::IxHash'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #------- | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub initialize { | ||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, $opts, $conf_file ) = @_; | |||||||||||||||||||||||||||
| 18 | my $conf = Config::General->new( | ||||||||||||||||||||||||||||
| 19 | -ConfigFile => $conf_file, | ||||||||||||||||||||||||||||
| 20 | -LowerCaseNames => 1, | ||||||||||||||||||||||||||||
| 21 | -MergeDuplicateBlocks => 1, | ||||||||||||||||||||||||||||
| 22 | -MergeDuplicateOptions => 1, | ||||||||||||||||||||||||||||
| 23 | -ExtendedAccess => 1, | ||||||||||||||||||||||||||||
| 24 | -StrictObjects => 0, | ||||||||||||||||||||||||||||
| 25 | -StrictVars => 0 | ||||||||||||||||||||||||||||
| 26 | )->obj('datasource')->obj( $opts->{datasource} ) | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | or croak "Failed to get datasource '$opts->{datasource}' configuration"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ( keys %{ $conf->{ConfigHash} } == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | croak "Invalid datasource '$opts->{datasource}'"; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | for (qw/namespace dsn username password/) { | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( !$conf->$_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | croak "'$_' missing from '$opts->{datasource}' configuration"; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | my $pkg; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Untaint and load the datasource package | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( $conf->namespace =~ /^(.+)$/g ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $pkg = $1; | |||||||||||||||||||||||||||
| 42 | 0 | eval "require $pkg"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # Add name to config | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $conf->name( $conf->name || $opts->{datasource} ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$conf->name || $opts->{'datasource'}
MC/DC0%0/2
$conf->name || $opts->{'datasource'}
$conf->name
$opts->{'datasource'}
Truth table0%0/3
A || B
A= $conf->nameB= $opts->{'datasource'}
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $dbh = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | DBI->connect( $conf->dsn, $conf->username, $conf->password, | ||||||||||||||||||||||||||||
| 49 | { PrintError => 0, RaiseError => 1 } ) | ||||||||||||||||||||||||||||
| 50 | or croak $DBI::errstr; | ||||||||||||||||||||||||||||
| 51 | 0 | my $dialect = CohortExplorer::Dialect->new($dbh); | |||||||||||||||||||||||||||
| 52 | 0 | my $sqla = SQL::Abstract::More->new( max_members_IN => 100 ); | |||||||||||||||||||||||||||
| 53 | 0 | my %param = ( | |||||||||||||||||||||||||||
| 54 | _dbh => $dbh, | ||||||||||||||||||||||||||||
| 55 | _dialect => $dialect, | ||||||||||||||||||||||||||||
| 56 | _sqla => $sqla, | ||||||||||||||||||||||||||||
| 57 | _conf => $conf, | ||||||||||||||||||||||||||||
| 58 | _entity_count => undef, | ||||||||||||||||||||||||||||
| 59 | _visit_info => undef, | ||||||||||||||||||||||||||||
| 60 | _table_info => undef, | ||||||||||||||||||||||||||||
| 61 | _variable_info => undef, | ||||||||||||||||||||||||||||
| 62 | _visit_variables => undef, | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Instantiate datasource | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $obj = $pkg->new( \%param ) or croak "Failed to instantiate datasource package '$pkg' via new(): $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $obj->_process($opts); | |||||||||||||||||||||||||||
| 68 | 0 | return $obj; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _process { | ||||||||||||||||||||||||||
|
Subroutine
_process: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||
| 72 | 0 | my ( $ds, $opts ) = @_; | |||||||||||||||||||||||||||
| 73 | 0 | my $class = ref $ds; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( $opts->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | print STDERR "Authenticating $opts->{username}\@$opts->{datasource} ...\n"; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | my $authres = $ds->authenticate(%$opts); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Successful authentication returns a defined response | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( !$authres ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | throw_app_init_exception( error => | |||||||||||||||||||||||||||
| 82 | "Either the username/password combination is incorrect or you do not seem to have the correct permission to query the datasource" | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $opts->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | print STDERR | |||||||||||||||||||||||||||
| 87 | "Initializing application for $opts->{username}\@$opts->{datasource} ...\n"; | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Response is passed to additional_param as it may contain | ||||||||||||||||||||||||||||
| 91 | # some data which the subclass hooks may use in entity, table | ||||||||||||||||||||||||||||
| 92 | # or variable specific hooks | ||||||||||||||||||||||||||||
| 93 | 0 | my $param = $ds->additional_params( $authres, %$opts ); | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( ref $param ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 96 | "Return from method 'additional_param' in class '$class' is not hash-worthy" | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | for ( keys %$param ) { | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( $param->{$_} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $ds->{_conf}->$_( $param->{$_} ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( !$ds->{_conf}->type || $ds->{_conf}->type !~ /^(standard|longitudinal)$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ds->{"_conf"}->type and $ds->{"_conf"}->type =~ /^(standard|longitudinal)$/
MC/DC0%0/2
$ds->{"_conf"}->type and $ds->{"_conf"}->type =~ /^(standard|longitudinal)$/
$ds->{"_conf"}->type
$ds->{"_conf"}->type =~ /^(standard|longitudinal)$/
Truth table0%0/3
A and B
A= $ds->{"_conf"}->typeB= $ds->{"_conf"}->type =~ /^(standard|longitudinal)$/
| |||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||
| 108 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 109 | "Datasource type (i.e. standard/longitudinal) is not specified for datasource '$opts->{datasource}'" | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # Validate subclass hooks | ||||||||||||||||||||||||||||
| 114 | 0 | for my $p (qw/entity table variable/) { | |||||||||||||||||||||||||||
| 115 | 0 | my $method = $p . '_structure'; | |||||||||||||||||||||||||||
| 116 | 0 | my $struct = $ds->$method; | |||||||||||||||||||||||||||
| 117 | 0 | for (qw/-columns -from -where/) { | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( !$struct->{$_} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | throw_app_hook_exception( | |||||||||||||||||||||||||||
| 120 | error => "'$_' missing in method '$method' in class '$class'" ); | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( scalar @{ $struct->{-columns} } % 2 != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 126 | "'-columns' in method '$method' in class '$class' is not hash-worthy" ); | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 0 | $method = 'set_' . $p . '_info'; | |||||||||||||||||||||||||||
| 129 | 0 | $ds->$method($struct); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ( $ds->conf->type eq 'longitudinal' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | # Set visit variables if the datasource is longitudinal | ||||||||||||||||||||||||||||
| 134 | # and contains data on at least 2 visits | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( $ds->{_visit_info} && keys %{ $ds->{_visit_info} } >= 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ds->{"_visit_info"} and keys %{$$ds{"_visit_info"};} >= 2
MC/DC0%0/2
$ds->{"_visit_info"} and keys %{$$ds{"_visit_info"};} >= 2
$ds->{"_visit_info"}
keys %{$$ds{"_visit_info"};} >= 2
Truth table0%0/3
A and B
A= $ds->{"_visit_info"}B= keys %{$$ds{"_visit_info"};} >= 2
| |||||||||||||||||||||||||||||
| 136 | 0 | for my $var ( keys %{ $ds->{_variable_info} } ) { | |||||||||||||||||||||||||||
| 137 | 0 | for my $v ( keys %{ $ds->{_visit_info} } ) { | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # Add suffix (vAny, vLast, visit names) to variables | ||||||||||||||||||||||||||||
| 140 | # belonging to dynamic table | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | grep ( $_ eq $ds->{_variable_info}{$var}{table}, | ||||||||||||||||||||||||||||
| 143 | 0 | @{ $ds->{_visit_info}{$v}{tables} } ) | |||||||||||||||||||||||||||
| 144 | ) | ||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | 0 | push @{ $ds->{_visit_variables} }, "$ds->{_visit_info}{$v}{name}.$var"; | |||||||||||||||||||||||||||
| 147 | 0 | push @{ $ds->{_visit_variables} }, ( "vAny.$var", "vLast.$var" ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $opts->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | print STDERR | ||||||||||||||||||||||||||||
| 154 | 0 | "Order of visits : " . join ( ' >= ', reverse keys %{ $ds->{_visit_info} } ) . " ...\n"; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||||||||||
| 159 | 0 | $ds->{_conf}->type('standard'); | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $opts->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | print STDERR | |||||||||||||||||||||||||||
| 162 | "No follow-up visits are found, datasource is set to standard ...\n"; | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub set_entity_info { | ||||||||||||||||||||||||||
|
Subroutine
set_entity_info: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | my ( $self, $struct ) = @_; | |||||||||||||||||||||||||||
| 171 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 172 | 0 | my %map = @{ $struct->{-columns} }; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # Check all mandatory columns are present | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | for my $c ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | $self->{_conf}->type eq 'standard' | ||||||||||||||||||||||||||||
| 177 | ? qw/entity_id table variable value/ | ||||||||||||||||||||||||||||
| 178 | : qw/entity_id table variable value visit/ | ||||||||||||||||||||||||||||
| 179 | ) | ||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( !defined $map{$c} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 183 | "Column '$c' in method 'entity_structure' in class '$class' is not defined" | ||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | ##----- SQL TO FETCH ENTITY_COUNT & VISITS -----## | ||||||||||||||||||||||||||||
| 189 | 0 | my $dialect = $self->{_dialect}; | |||||||||||||||||||||||||||
| 190 | 0 | my @columns = ( "COUNT( DISTINCT $map{entity_id} )" ); | |||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( $self->{_conf}->type eq 'longitudinal' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my $order_by = $struct->{-order_by} || "CONCAT( $map{table}, '\@\@', $map{visit} )"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$struct->{'-order_by'} || "CONCAT( $map{'table'}, '\@\@', $map{'visit'} )"
MC/DC0%0/1
$struct->{'-order_by'} || "CONCAT( $map{'table'}, '\@\@', $map{'visit'} )"
$struct->{'-order_by'}
Truth table0%0/2
A
A= $struct->{'-order_by'}
| |||||||||||||||||||||||||||||
| 193 | 0 | push @columns, $dialect->aggregate( "DISTINCT CONCAT( $map{table}, '\@\@', $map{visit} ) ORDER BY $order_by" , '===' ); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | $struct->{-columns} = \@columns; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | my ( $stmt, @bind, $entity_count, $visit ); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | delete $struct->{-order_by}; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | eval { ( $stmt, @bind ) = $self->{_sqla}->select(%$struct); }; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | eval { | |||||||||||||||||||||||||||
| 208 | ( $entity_count, $visit ) = | ||||||||||||||||||||||||||||
| 209 | 0 | $self->{_dbh}->selectrow_array( $stmt, undef, @bind ); | |||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( $entity_count == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | throw_app_init_exception( | ||||||||||||||||||||||||||||
| 217 | 0 | error => 'No entities are found in datasource ' . $self->{_conf}->name ); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # Add entity_count | ||||||||||||||||||||||||||||
| 221 | 0 | $self->{_entity_count} = $entity_count; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # Preserve order of visits | ||||||||||||||||||||||||||||
| 224 | 0 | tie %{ $self->{_visit_info} }, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($visit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | my @static_tables = $self->{_conf}->array('static_tables'); | |||||||||||||||||||||||||||
| 227 | 0 | for my $tv ( split '===', $visit ) { | |||||||||||||||||||||||||||
| 228 | 0 | my ( $t, $v, $n ) = ( $tv =~ /^(.+)\@\@((.+))$/ ); | |||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ( !grep ( $_ eq $t, @static_tables ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # Associated name with non word characters replaced by underscore | ||||||||||||||||||||||||||||
| 232 | 0 | $n =~ s/[\W]/_/g; | |||||||||||||||||||||||||||
| 233 | $self->{_visit_info}{"$v"}{name} = 'v' . ucfirst lc $n, | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # Associated table(s) | ||||||||||||||||||||||||||||
| 236 | 0 | push @{ $self->{_visit_info}{"$v"}{tables} }, $t; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub set_table_info { | ||||||||||||||||||||||||||
|
Subroutine
set_table_info: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 243 | 0 | my ( $self, $struct ) = @_; | |||||||||||||||||||||||||||
| 244 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 245 | 0 | my %map = @{ $struct->{-columns} }; | |||||||||||||||||||||||||||
| 246 | 0 | my $ds_name = $self->{_conf}->name; | |||||||||||||||||||||||||||
| 247 | 0 | my $dbh = $self->{_dbh}; | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ( !defined $map{table} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 250 | "Column 'table' in method 'table_structure' in class '$class' is not defined" | ||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | ##----- SQL TO FETCH TABLE DATA -----## | ||||||||||||||||||||||||||||
| 254 | 0 | my ( $stmt, @bind, $tables ); | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # Format column name-SQL pairs along the lines of columns in | ||||||||||||||||||||||||||||
| 257 | # SQL::Abstract::More (add names as aliases really) | ||||||||||||||||||||||||||||
| 258 | 0 | $struct->{-columns} = [ map { $map{$_} . ' AS ' . $dbh->quote_identifier($_) } keys %map ]; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | eval { ( $stmt, @bind ) = $self->{_sqla}->select(%$struct); }; | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | eval { $tables = $dbh->selectall_arrayref( $stmt, { Slice => {} }, @bind ); }; | |||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( @$tables == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | throw_app_init_exception( | |||||||||||||||||||||||||||
| 273 | error => "No accessible tables are found in datasource '$ds_name'" ); | ||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | my @static_tables = $self->{_conf}->array('static_tables'); | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # Preserve order of tables | ||||||||||||||||||||||||||||
| 279 | 0 | tie %{ $self->{_table_info} }, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 280 | 0 | for my $t (@$tables) { | |||||||||||||||||||||||||||
| 281 | 0 | for my $c ( keys %map ) { | |||||||||||||||||||||||||||
| 282 | 0 | $self->{_table_info}{ $t->{table} }{$c} = $t->{$c}; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | # Set table type based on datasource type | ||||||||||||||||||||||||||||
| 286 | $self->{_table_info}{ $t->{table} }{__type__} = | ||||||||||||||||||||||||||||
| 287 | $self->{_conf}->type eq 'standard' | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | || grep ( $_ eq $t->{table}, @static_tables ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_conf"}->type eq "standard" or grep(($_ eq $t->{"table"}), @static_tables)
MC/DC0%0/2
$self->{"_conf"}->type eq "standard" or grep(($_ eq $t->{"table"}), @static_tables)
$self->{"_conf"}->type eq "standard"
grep(($_ eq $t->{"table"}), @static_tables)
Truth table0%0/3
A or B
A= $self->{"_conf"}->type eq "standard"B= grep(($_ eq $t->{"table"}), @static_tables)
| |||||||||||||||||||||||||||||
| 289 | ? 'static' | ||||||||||||||||||||||||||||
| 290 | : 'dynamic'; | ||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub set_variable_info { | ||||||||||||||||||||||||||
|
Subroutine
set_variable_info: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 296 | 0 | my ( $self, $struct ) = @_; | |||||||||||||||||||||||||||
| 297 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 298 | 0 | my $ds_name = $self->{_conf}->name; | |||||||||||||||||||||||||||
| 299 | 0 | my %map = @{ $struct->{-columns} }; | |||||||||||||||||||||||||||
| 300 | 0 | my $datatype = $self->datatype_map; | |||||||||||||||||||||||||||
| 301 | 0 | my $dbh = $self->{_dbh}; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | # Throw exception if column 'table' or 'variable' is not defined | ||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ( !defined $map{table} || !defined $map{variable} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $map{"table"} and defined $map{"variable"}
MC/DC0%0/2
defined $map{"table"} and defined $map{"variable"}
defined $map{"table"}
defined $map{"variable"}
Truth table0%0/3
A and B
A= defined $map{"table"}B= defined $map{"variable"}
| |||||||||||||||||||||||||||||
| 305 | 0 | throw_app_hook_exception( error => | |||||||||||||||||||||||||||
| 306 | "No mapping found for column 'table' or 'variable' in method 'variable_structure' in class '$class'" | ||||||||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ( ref $datatype ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | throw_app_init_exception( error => | |||||||||||||||||||||||||||
| 312 | "Return by method 'datatype_map' in class '$class' is not hash-worthy" ); | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | ##----- SQL TO FETCH TABLE DATA -----## | ||||||||||||||||||||||||||||
| 316 | 0 | my ( $stmt, @bind, $vars ); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # Format column name-SQL pairs along the lines of columns in | ||||||||||||||||||||||||||||
| 319 | # SQL::Abstract::More | ||||||||||||||||||||||||||||
| 320 | 0 | $struct->{-columns} = [ map { $map{$_} . ' AS ' . $dbh->quote_identifier($_) } keys %map ]; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | eval { ( $stmt, @bind ) = $self->{_sqla}->select(%$struct); }; | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | eval { $vars = $dbh->selectall_arrayref( $stmt, { Slice => {} }, @bind ); }; | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ( catch my $e ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | throw_app_hook_exception( error => $e ); | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ( @$vars == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 0 | throw_app_init_exception( | |||||||||||||||||||||||||||
| 334 | error => "No accessible variables are found in datasource '$ds_name'" ); | ||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | # Get the variable data type to sql data type mapping | ||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my %datatype_map = map { uc $_ => ( $datatype->{$_} || $self->dialect->sql_text ) } keys %$datatype; | ||||||||||||||||||||||||||
|
Condition0%0/3
$datatype->{$_} || $self->dialect->sql_text
MC/DC0%0/2
$datatype->{$_} || $self->dialect->sql_text
$datatype->{$_}
$self->dialect->sql_text
Truth table0%0/3
A || B
A= $datatype->{$_}B= $self->dialect->sql_text
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | # Preserve order of variables | ||||||||||||||||||||||||||||
| 341 | 0 | tie %{ $self->{_variable_info} }, 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 342 | 0 | for my $v (@$vars) { | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ( !$v->{table} || !$v->{variable} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$v->{"table"} and $v->{"variable"}
MC/DC0%0/2
$v->{"table"} and $v->{"variable"}
$v->{"table"}
$v->{"variable"}
Truth table0%0/3
A and B
A= $v->{"table"}B= $v->{"variable"}
| |||||||||||||||||||||||||||||
| 344 | 0 | throw_app_init_exception( | |||||||||||||||||||||||||||
| 345 | error => "Undefined table/variable found in datasource '$ds_name'" ); | ||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | # 'table-variable' combination is key | ||||||||||||||||||||||||||||
| 349 | 0 | my $k = $v->{table} . '.' . $v->{variable}; | |||||||||||||||||||||||||||
| 350 | 0 | for my $c ( keys %map ) { | |||||||||||||||||||||||||||
| 351 | 0 | $self->{_variable_info}{$k}{$c} = $v->{$c}; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $self->{_variable_info}{$k}{category} = $v->{'category'} || undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$v->{'category'} || undef
MC/DC0%0/1
$v->{'category'} || undef
$v->{'category'}
Truth table0%0/2
A
A= $v->{'category'}
| |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | $self->{_variable_info}{$k}{__type__} = $datatype_map{ uc $v->{type} } || $self->dialect->sql_text; | ||||||||||||||||||||||||||
|
Condition0%0/3
$datatype_map{uc $v->{'type'}} || $self->dialect->sql_text
MC/DC0%0/2
$datatype_map{uc $v->{'type'}} || $self->dialect->sql_text
$datatype_map{uc $v->{'type'}}
$self->dialect->sql_text
Truth table0%0/3
A || B
A= $datatype_map{uc $v->{'type'}}B= $self->dialect->sql_text
| |||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 360 | 0 | return bless $_[1], $_[0]; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 364 | 0 | my ($ds) = @_; | |||||||||||||||||||||||||||
| 365 | 0 | ▶ | $ds->dbh->disconnect if $ds->{dbh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 369 | 0 | my ($ds) = @_; | |||||||||||||||||||||||||||
| 370 | 0 | my $class = ref $ds; | |||||||||||||||||||||||||||
| 371 | 0 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 372 | 0 | ( my $p = $AUTOLOAD ) =~ s/.*:://; | |||||||||||||||||||||||||||
| 373 | 0 | my @params = qw/dbh dialect sqla conf entity_count visit_info table_info variable_info visit_variables/; | |||||||||||||||||||||||||||
| 374 | 0 | ▶ | if ( $ds->{"_$p"} && grep ( $_ eq $p, @params ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$ds{"_$p"} and grep(($_ eq $p), @params)
MC/DC0%0/2
$$ds{"_$p"} and grep(($_ eq $p), @params)
$$ds{"_$p"}
grep(($_ eq $p), @params)
Truth table0%0/3
A and B
A= $$ds{"_$p"}B= grep(($_ eq $p), @params)
| |||||||||||||||||||||||||||||
| 375 | 0 | return $ds->{"_$p"}; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | else { | ||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ( $ds->{_conf}->is_hash($p) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 379 | 0 | return { $ds->{_conf}->hash($p) }; | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | elsif ( $ds->{_conf}->is_array($p) ) { | ||||||||||||||||||||||||||||
| 382 | 0 | return [ $ds->{_conf}->array($p) ]; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | else { | ||||||||||||||||||||||||||||
| 385 | 0 | return $ds->{_conf}->$p; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | #--------- SUBCLASSES HOOKS --------# | ||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub authenticate { 1 } | ||||||||||||||||||||||||||
|
Subroutine
authenticate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub additional_params { } | ||||||||||||||||||||||||||
|
Subroutine
additional_params: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub entity_structure { } | ||||||||||||||||||||||||||
|
Subroutine
entity_structure: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | sub table_structure { } | ||||||||||||||||||||||||||
|
Subroutine
table_structure: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub variable_structure { } | ||||||||||||||||||||||||||
|
Subroutine
variable_structure: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 0 | ▶ | sub datatype_map { } | ||||||||||||||||||||||||||
|
Subroutine
datatype_map: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | ############################### | ||||||||||||||||||||||||||||
| 404 | # | ||||||||||||||||||||||||||||
| 405 | # DIALECT | ||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||
| 407 | ############################### | ||||||||||||||||||||||||||||
| 408 | package CohortExplorer::Dialect; | ||||||||||||||||||||||||||||
| 409 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 410 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 411 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 414 | 0 | my ( $class, $dbh ) = @_; | |||||||||||||||||||||||||||
| 415 | 0 | my %param = ( _name => $dbh->{Driver}{Name} ); | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if ( $param{_name} =~ /^Pg(PP)?$/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 418 | 0 | @param{ qw/_name _regexp _not_regexp _sql_text/ } = ( 'postgresql', '~', '!~', 'VARCHAR(65000)' ); | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | elsif ( $param{_name} eq 'mysql' ) { | ||||||||||||||||||||||||||||
| 421 | 0 | $dbh->do('SET SESSION group_concat_max_len = 65000'); | |||||||||||||||||||||||||||
| 422 | 0 | @param{ qw/_aliase_in_having _like _ilike _sql_text/ } = ( 1, 'like binary', 'like', 'CHAR(65000)' ); | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||
| 425 | 0 | croak "Dialect '$param{_name}' is not supported"; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | ▶ | $param{_aggregate} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 429 | 0 | my ( $str, $sep ) = @_; | |||||||||||||||||||||||||||
| 430 | 0 | ▶ | $sep ||= ','; | ||||||||||||||||||||||||||
|
Condition0%0/2
$sep ||= ","
MC/DC0%0/1
$sep ||= ","
$sep
Truth table0%0/2
A
A= $sep
| |||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if ( $param{_name} eq 'postgresql' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 0 | ▶ | $sep = $sep eq '\n' ? "E'\\n'" : "'$sep'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 0 | return "ARRAY_TO_STRING( ARRAY_AGG( $str ) , $sep )"; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | else { | ||||||||||||||||||||||||||||
| 436 | 0 | return "GROUP_CONCAT( $str SEPARATOR '$sep' )"; | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 0 | }; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $param{_substring} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 441 | 0 | my ( $str, $sep, $pos ) = @_; | |||||||||||||||||||||||||||
| 442 | 0 | ▶ | croak "Position can either be 1 or -1" if $pos != 1 && $pos != -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pos != 1 and $pos != -1
MC/DC0%0/2
$pos != 1 and $pos != -1
$pos != 1
$pos != -1
Truth table0%0/3
A and B
A= $pos != 1B= $pos != -1
| |||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ( $param{_name} eq 'postgresql' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 0 | ▶ | return $pos == 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | ? "SUBSTRING( $str FROM '^[^$sep]*')" | ||||||||||||||||||||||||||||
| 446 | : "SUBSTRING( $str FROM '[^$sep]*\$')"; | ||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | else { | ||||||||||||||||||||||||||||
| 449 | 0 | return "SUBSTRING_INDEX( $str, '$sep', $pos )" | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | 0 | }; | |||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | return bless \%param, $class; | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 457 | 0 | my ($dialect, @args) = @_; | |||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 460 | 0 | ( my $p = $AUTOLOAD ) =~ s/.*:://; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ( ref $dialect->{"_$p"} eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | 0 | return $dialect->{"_$p"}->(@args); | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | else { | ||||||||||||||||||||||||||||
| 466 | 0 | ▶ | return $dialect->{"_$p"} || undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$dialect{"_$p"} || undef
MC/DC0%0/1
$$dialect{"_$p"} || undef
$$dialect{"_$p"}
Truth table0%0/2
A
A= $$dialect{"_$p"}
| |||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | #------- | ||||||||||||||||||||||||||||
| 472 | 2 | 1; | |||||||||||||||||||||||||||
| 473 | __END__ | ||||||||||||||||||||||||||||