This file is indexed.

/usr/share/perl5/Test/MockDBI/Db.pm is in libtest-mockdbi-perl 0.70-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package Test::MockDBI::Db;

use strict;
use warnings;
use Test::MockDBI::Base;

use base qw(Test::MockDBI::Base);

my $mockdbi = undef;

sub import{ $mockdbi = $_[1]; }

sub _dbi_prepare{
  my ($self, $statement, $attr) = @_;
  
  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($statement);
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }
  
  #Seems like DBI dies if nothing is passed as a statement
  #We replicate the same behaviour, but is this wrong?
  #Doesnt DBI->prepare honor RaiseError \ PrintError ?
  unless( $statement ){
    die('DBI prepare: invalid number of arguments: got handle + 0, expected handle + between 1 and 2
    Usage: $h->prepare($statement [, \%attr])');
  }

  #dbh->{Statment} should contain the most recent string
  #passed to prepare or do event if that call failed
  $self->{Statement} = $statement;

  my $num_of_params = ($statement =~ tr/?//);
  
  my $o_retval = bless {
    NUM_OF_FIELDS => undef,
    NUM_OF_PARAMS => $num_of_params,
    NAME => undef,
    NAME_lc => undef,
    NAME_uc => undef,
    NAME_hash => undef,
    NAME_lc_hash => undef,
    NAME_uc_hash => undef,
    TYPE => undef,
    PRECISION =>  undef,
    SCALE => undef,
    NULLABLE => undef,
    CursorName => undef,
    Database => $self,
    Statement => $statement,
    ParamValues => {},
    ParamTypes => {},
    ParamArray => undef,
    RowsInCache =>  undef,
    _fake => {
      InoutParams => []
    },
    
    #Common
    Warn => undef,
    Active => undef,
    Executed => undef,
    Kids => 0, #Should always be zero for a statementhandler see DBI documentation
    ActiveKids => undef,
    CachedKids => undef,
    Type => 'st',
    ChildHandles => undef,
    CompatMode => undef,
    InactiveDestroy => undef,
    AutoInactiveDestroy => undef,
    PrintWarn => undef,
    PrintError => undef,
    RaiseError => undef,
    HandleError => undef,
    HandleSetErr => undef,
    ErrCount => undef,
    ShowErrorStatement => undef,
    TraceLevel => undef,
    FetchHashKeyName => undef,
    ChopBlanks => undef,
    LongReadLen => undef,
    LongTruncOk => undef,
    TaintIn => undef,
    TaintOut => undef,
    Taint => undef,
    Profile => undef,
    ReadOnly => undef,
    Callbacks => undef,    
  }, 'DBI::st';
  
  push( @{ $self->{ChildHandles} }, $o_retval);
  $self->{Kids} = scalar( @{ $self->{ChildHandles} } );
  $self->{ActiveKids} = Test::MockDBI::Db::_update_active_kids($self);
  return $o_retval;
}

sub _dbi_prepare_cached{
  my ($self, $statement, $attr, $if_active) = @_;
  
  $attr = {} if !$attr;
  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($statement);
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }  
  
	my $cache = $self->{CachedKids} ||= {};
	my $key = do { local $^W;
	    join "!\001", $statement, DBI::_concat_hash_sorted($attr, "=\001", ",\001", 0, 0)
	};
	my $sth = $cache->{$key};
  
  if($sth){
    return $sth unless ($sth->{Active});
    Carp::carp("prepare_cached($statement) statement handle $sth still Active")
      unless ($if_active ||= 0);
    $sth->finish if $if_active <= 1;
    return $sth  if $if_active <= 2;    
  }
	$sth = $self->prepare($statement, $attr);
	$cache->{$key} = $sth if $sth;

	return $sth;  
}

sub _dbi_do{
  my($self, $statement, $attr, @bind_values) = @_;

  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($statement);
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }  
  
  my $sth = $self->prepare($statement, $attr) or return;
  $sth->execute(@bind_values) or return;

  #Updating dbh attributes
  $self->{Executed} = 1;

  
  my $rows = $sth->rows;
  ($rows == 0) ? "0E0" : $rows; # always return true if no error  
}

sub _dbi_commit{
  my ($self) = @_;

  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  
  
  #The executed attribute is updated even if the
  #call fails
  $self->{Executed} = undef;
  
  #Warning is displayed even if the method fails
  warn "commit ineffective with AutoCommit enabled" if $self->{AutoCommit};
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($self->{Statement});
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }
  
  #Updating dbh attributes
  $self->{AutoCommit} = 1;

  return 1;
}

sub _dbi_rollback{
  my ($self) = @_;
  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  #The executed attribute is updated even if the
  #call fails
  $self->{Executed} = undef;
  
  #Warning is displayed even if the method fails
  warn "rollback ineffective with AutoCommit enabled" if $self->{AutoCommit};
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($self->{Statement});
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }
  
  $self->{AutoCommit} = 1;
  return 1;  
}

sub _dbi_begin_work{
  my ($self) = @_;
  
  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval($self->{Statement});
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }
  
  $self->{AutoCommit} = 0;
  return 1;
}

sub _dbi_ping{
  my ($self) = @_;
  
  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval();
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }  

  return 1;
}

sub _dbi_disconnect{
  my ($self) = @_;

  # Reset both errors as per DBI Rule
  $mockdbi->_clear_dbi_err_errstr($self);
  
  my ($status, $retval) = $mockdbi->_has_fake_retval();
  if($status){
    $mockdbi->_set_fake_dbi_err_errstr($self);
    
    if(ref($retval) eq 'CODE'){
      return $retval->($self);
    }
    return $retval;
  }   

  #Set the Active flag to false for all childhandlers
  foreach my $ch ( @{ $self->{ChildHandlers} } ){
    $ch->{Active} = undef;
  }
  Test::MockDBI::Db::_update_active_kids($self);

  return 1;  
}


#This is a helper method, and not a part of the DBI specification
sub _update_active_kids{
  my ($self) = @_;
  my $cnt = scalar(grep{ $_->{Active} } @{$self->{ChildHandles}});
  $self->{ActiveKids} = $cnt;
  return 1;
}
1;