This file is indexed.

/usr/share/perl5/DBI/Test/Conf.pm is in libdbi-test-perl 0.001-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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
package DBI::Test::Conf;

use strict;
use warnings;

use Carp qw(carp croak);
use Config;

use Cwd            ();
use Data::Dumper   ();
use File::Basename ();
use File::Path     ();
use File::Spec     ();

use DBI::Mock                ();
use DBI::Test::DSN::Provider ();

use Module::Pluggable::Object ();

my $cfg_plugins;

sub cfg_plugins
{
    defined $cfg_plugins and return @{$cfg_plugins};

    my $finder = Module::Pluggable::Object->new(
                                                 search_path => ["DBI::Test"],
                                                 require     => 1,
                                                 only        => qr/::Conf$/,
                                                 inner       => 0
                                               );
    my @plugs = grep { $_->isa("DBI::Test::Conf") } $finder->plugins();
    $cfg_plugins = \@plugs;

    return @{$cfg_plugins};
}

my %conf = (
             (
               -f $INC{'DBI.pm'}
               ? (
                   default => {
                                category   => "mock",
                                cat_abbrev => "m",
                                abbrev     => "b",
                                init_stub  => qq(\$ENV{DBI_MOCK} = 1;),
                                match      => {
                                           general   => qq(require DBI;),
                                           namespace => [""],
                                         },
                                name => "Unmodified Test",
                              }
                 )
               : ()
             )
           );

sub conf { %conf; }

sub allconf
{
    my ($self)  = @_;
    my %allconf = $self->conf();
    my @plugins = $self->cfg_plugins();
    foreach my $plugin (@plugins)
    {
        # Hash::Merge->merge( ... )
        %allconf = ( %allconf, $plugin->conf() );
    }
    return %allconf;
}

my $tc_plugins;

sub tc_plugins
{
    defined $tc_plugins and return @{$tc_plugins};

    my $finder = Module::Pluggable::Object->new(
                                                 search_path => ["DBI::Test"],
                                                 require     => 1,
                                                 only        => qr/::List$/,
                                                 inner       => 0
                                               );
    my @plugs = grep { $_->isa("DBI::Test::List") } $finder->plugins();
    $tc_plugins = \@plugs;

    return @{$tc_plugins};
}

sub alltests
{
    my ($self) = @_;
    my @alltests;
    my @plugins = $self->tc_plugins();
    foreach my $plugin (@plugins)
    {
        # Hash::Merge->merge( ... )
        @alltests = ( @alltests, $plugin->test_cases() );
    }
    return @alltests;
}

sub alldrivers
{
    # XXX restrict by config file !
    my @drivers = grep { $_ !~ m/^Gofer|Multi|Multiplex|Proxy|Sponge$/ } DBI->available_drivers();
    # hack around silly DBI behaviour which removes NullP from avail drivers
    -f $INC{'DBI.pm'} and push( @drivers, "NullP" );
    @drivers;
}

sub default_dsn_conf
{
    my ( $self, $driver ) = @_;

    $driver => {
                 category   => "driver",
                 cat_abbrev => "d",
                 abbrev     => lc( substr( $driver, 0, 1 ) ),
                 driver     => "dbi:$driver:",
                 name       => "DSN for $driver",
               };
}

sub dsn_conf
{
    my ( $self, $driver, $test_case_ns ) = @_;
    my @dsn_providers =
      grep { $_ =~ m/\b$driver$/ && $_->can("dsn_conf") } DBI::Test::DSN::Provider->dsn_plugins();
    @dsn_providers or return $self->default_dsn_conf($driver);
    return $dsn_providers[0]->dsn_conf($test_case_ns);
}

sub combine_nk
{
    my ( $n, $k ) = @_;
    my @indx;
    my @result;

    @indx = map { $_ } ( 0 .. $k - 1 );

  LOOP:
    while (1)
    {
        my @line = map { $indx[$_] } ( 0 .. $k - 1 );
        push( @result, \@line ) if @line;
        for ( my $iwk = $k - 1; $iwk >= 0; --$iwk )
        {
            if ( $indx[$iwk] <= ( $n - 1 ) - ( $k - $iwk ) )
            {
                ++$indx[$iwk];
                for my $swk ( $iwk + 1 .. $k - 1 )
                {
                    $indx[$swk] = $indx[ $swk - 1 ] + 1;
                }
                next LOOP;
            }
        }
        last;
    }

    return @result;
}

# simplified copy from Math::Cartesian::Product
# Copyright (c) 2009 Philip R Brenan.
# This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.

sub cartesian
{
    my @C = @_;    # Lists to be multiplied
    my @c = ();    # Current element of cartesian product
    my @P = ();    # Cartesian product
    my $n = 0;     # Number of elements in product

    @C or return;  # Empty product

    # Generate each cartesian product when there are no prior cartesian products.

    my $p;
    $p = sub {
        if ( @c < @C )
        {
            for ( @{ $C[@c] } )
            {
                push @c, $_;
                &$p();
                pop @c;
            }
        }
        else
        {
            my $p = [@c];
            push @P, $p;
        }
    };

    &$p();

    @P;
}

sub create_test
{
    my ( $self, $test_case, $cfg_pfx, $test_confs, $dsn_pfx, $dsn_cred, $options ) = @_;

    # simply don't deploy them when you don't want be bothered about them ...
    my $test_base =
      ( defined( $options->{AUTHOR_TESTS} ) and $options->{AUTHOR_TESTS} ) ? "xt" : "t";
    ( my $test_file = $test_case ) =~ s,::,/,g;
    $test_file = File::Spec->catfile( $test_base, $test_file . ".t" );
    my $test_dir = File::Basename::dirname($test_file);

    $test_file = File::Basename::basename($test_file);
    my @tf_name_parts;
    $cfg_pfx and push( @tf_name_parts, $cfg_pfx );
    $dsn_pfx and push( @tf_name_parts, $dsn_pfx );
    push( @tf_name_parts, $test_file );
    $test_file = File::Spec->catfile( $test_dir, join( "_", @tf_name_parts ) );

    -d $test_dir or File::Path::make_path($test_dir);
    open( my $tfh, ">", $test_file ) or croak("Cannot open \"$test_file\": $!");
    my $init_stub = join(
        ";\n",
        map {
            "ARRAY" eq ref( $_->{init_stub} )
              ? join( ";\n", @{ $_->{init_stub} } )
              : $_->{init_stub}
          } grep { $_->{init_stub} } @$test_confs
    );
    $init_stub and $init_stub = sprintf( <<EOS, $init_stub );
BEGIN {
%s
}
EOS
    my $cleanup_stub = join(
        ";\n",
        map {
            "ARRAY" eq ref( $_->{cleanup_stub} )
              ? join( ";\n", @{ $_->{cleanup_stub} } )
              : $_->{cleanup_stub}
          } grep { $_->{cleanup_stub} } @$test_confs
    );
    $cleanup_stub and $cleanup_stub = sprintf( <<EOC, $cleanup_stub );
END {
%s
}
EOC

    my $dsn =
      Data::Dumper->new( [$dsn_cred] )->Indent(0)->Sortkeys(1)->Quotekeys(0)->Terse(1)->Dump();
    # XXX how to deal with namespaces here and how do they affect generated test names?
    my $test_case_ns = "DBI::Test::Case::$test_case";
    my $test_case_code = sprintf( <<EOC, $init_stub, $cleanup_stub, $dsn );
#!$^X\n
%s
%s
use DBI::Mock;
use DBI::Test::DSN::Provider;

use ${test_case_ns};

my \$test_case_conf = DBI::Test::DSN::Provider->get_dsn_creds("${test_case_ns}", %s);
${test_case_ns}->run_test(\$test_case_conf);
EOC

    print $tfh "$test_case_code\n";
    close($tfh);

    return $test_dir;
}

sub create_conf_prefixes
{
    my ( $self, $allconf ) = @_;
    my %pfx_hlp;
    my %pfx_lst;

    foreach my $cfg ( values %$allconf )
    {
        push( @{ $pfx_hlp{ $cfg->{cat_abbrev} } }, $cfg );
    }

    foreach my $cfg_id ( keys %pfx_hlp )
    {
        my $n = scalar( @{ $pfx_hlp{$cfg_id} } );
        my @combs = map { combine_nk( $n, $_ ); } ( 1 .. $n );
        scalar @combs or next;
        $pfx_lst{$cfg_id} = {
            map {
                my @cfgs = map { $pfx_hlp{$cfg_id}->[$_] } @{$_};
                my $pfx = "${cfg_id}v" . join( "", map { $_->{abbrev} } @cfgs );
                $pfx => \@cfgs
              } @combs
        };
    }

    my %pfx_direct = map { %{$_} } values %pfx_lst;
    %pfx_hlp = %pfx_lst;
    %pfx_lst = ( "" => [] );
    do
    {
        my @pfx   = keys %pfx_hlp;
        my $n     = scalar(@pfx);
        my @combs = map { combine_nk( $n, $_ ); } ( 1 .. $n );
        foreach my $comb (@combs)
        {
            my @cfgs = cartesian( map { [ keys %{ $pfx_hlp{ $pfx[$_] } } ] } @$comb );
            foreach my $cfg (@cfgs)
            {
                my $_pfx = join( "_", @$cfg );
                $pfx_lst{$_pfx} = [ map { @{ $pfx_direct{$_} } } @$cfg ];
            }
        }
    } while (0);

    return %pfx_lst;
}

my %dsn_cfg = (
                dbm => {
                         category   => "driver",
                         cat_abbrev => "d",
                         abbrev     => "d",
                         driver     => "dbi:DBM:",
                         variants   => {
                                       mldbm => {
                                                  f => { dbm_mldbm => 'FreezeThaw' },
                                                  d => { dbm_mldbm => 'Data::Dumper' },
                                                  s => { dbm_mldbm => 'Storable' },
                                                },
                                       type => {
                                                 s => { dbm_type => 'SDBM_File' },
                                                 g => { dbm_type => 'GDBM_File' },
                                                 d => { dbm_type => 'DB_File' },
                                                 b => {
                                                        dbm_type           => 'BerkeleyDB',
                                                        dbm_berkeley_flags => '...'
                                                      }
                                               },
                                     },
                         name => "DSN for DBM",
                       },
                csv => {
                         category   => "driver",
                         cat_abbrev => "d",
                         abbrev     => "c",
                         driver     => "dbi:CSV:",
                         variants   => {
                                       type => {
                                                 p => { csv_class => 'Text::CSV' },
                                                 x => { csv_class => 'Text::CSV_XS' },
                                               },
                                     },
                         name => "DSN for CSV",
                       },
              );

sub create_driver_prefixes
{
    my ( $self, $dsnconf ) = @_;
    # $dsnconf or $dsnconf = \%dsn_cfg;
    my %pfx_lst;

    foreach my $dsncfg ( values %$dsnconf )
    {
        my @creds = @$dsncfg{qw(driver user passwd attrs)};
        my $pfx   = $dsncfg->{cat_abbrev} . "v" . $dsncfg->{abbrev};
        "HASH" eq ref $creds[3] or $creds[3] = {};
        $pfx_lst{$pfx} = [@creds];

        if ( $dsncfg->{variants} )
        {
            my @varvals = values %{ $dsncfg->{variants} };
            my @variants = cartesian( map { [ keys %{$_} ] } @varvals );
            foreach my $variant (@variants)
            {
                my $attrs = {
                              %{ $creds[3] },
                              map { %{ $varvals[$_]->{ $variant->[$_] } } } ( 0 .. $#varvals )
                            };
                $pfx_lst{ $pfx . join( "", @$variant ) } = [ @creds[ 0 .. 2 ], $attrs ];
            }
        }
    }

    # avoid prefix pollution
    if ( 1 == scalar( keys(%pfx_lst) ) )
    {
        %pfx_lst = ( '' => ( values %pfx_lst )[0] );
    }

    return %pfx_lst;
}

sub populate_tests
{
    my ( $self, $alltests, $allconf, $alldrivers, $options ) = @_;
    my %test_dirs;

    my %pfx_cfgs = $self->create_conf_prefixes($allconf);
    foreach my $test_case (@$alltests)
    {
        # XXX how to deal with namespaces here and how do they affect generated test names?
        my $test_case_ns = "DBI::Test::Case::$test_case";
        eval "require $test_case_ns;";
        $@ and carp $@ and next;    # don't create tests for broken test cases
        my @test_drivers = @$alldrivers;
        $test_case_ns->can("filter_drivers")
          and @test_drivers = $test_case_ns->filter_drivers( $options, @test_drivers );
        @test_drivers or next;

        $test_case_ns->can("supported_variant")
          or eval qq/
	      package #
	        $test_case_ns;
	    sub supported_variant { 1 };
	    1;
	  /;

        my %dsn_conf;
        foreach my $test_drv (@test_drivers)
        {
            %dsn_conf = ( %dsn_conf, $self->dsn_conf( $test_drv, $test_case_ns ) );
        }
        my %pfx_dsns = $self->create_driver_prefixes( \%dsn_conf );

        foreach my $pfx_dsn ( keys %pfx_dsns )
        {
            foreach my $pfx_cfg ( keys %pfx_cfgs )
            {
                $test_case_ns->supported_variant(
                                                  $test_case,          $pfx_cfg,
                                                  $pfx_cfgs{$pfx_cfg}, $pfx_dsn,
                                                  $pfx_dsns{$pfx_dsn}, $options
                                                )
                  or next;
                my $test_dir = $self->create_test(
                                               $test_case, $pfx_cfg,            $pfx_cfgs{$pfx_cfg},
                                               $pfx_dsn,   $pfx_dsns{$pfx_dsn}, $options );
                $test_dirs{$test_dir} = 1;
            }
        }
    }

    return keys %test_dirs;
}

sub setup
{
    my ( $self, %options ) = @_;

    my %allconf = $self->allconf();
    # from DBI::Test::{NameSpace}::List->test_cases()
    my @alltests   = $self->alltests();
    my @alldrivers = $self->alldrivers();

    my @gen_test_dirs = $self->populate_tests( \@alltests, \%allconf, \@alldrivers, \%options );

    if ( $options{SKIP_FILE} )
    {
        open( my $fh, ">", $options{SKIP_FILE} )
          or croak("Can't open $options{SKIP_FILE} for writing: $!");
        print $fh map { $_ . "/.*\\.t\n"; } @gen_test_dirs;
        close($fh);
    }

    return map { File::Spec->catfile( $_, "*.t" ) } @gen_test_dirs;
}

=head1 NAME

DBI::Test::Conf - provides variants configuration for DBI::Test

=head1 DESCRIPTION

This module provides the configuration of variants for tests
generated from DBI::Test::Case list.

=head1 AUTHOR

This module is a team-effort. The current team members are

  H.Merijn Brand   (Tux)
  Jens Rehsack     (Sno)
  Peter Rabbitson  (ribasushi)
  Joakim TE<0x00f8>rmoen   (trmjoa)

=head1 COPYRIGHT AND LICENSE

Copyright (C)2013 - The DBI development team

You may distribute this module under the terms of either the GNU
General Public License or the Artistic License, as specified in
the Perl README file.

=cut

1;