/usr/share/perl5/Test/Database/Util.pm is in libtest-database-perl 1.11-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 | package Test::Database::Util;
use strict;
use warnings;
use Carp;
# export everything
sub import {
my $caller = caller();
no strict 'refs';
*{"${caller}::$_"} = \&$_ for qw( _read_file );
}
# return a list of hashrefs representing each configuration section
sub _read_file {
my ($file) = @_;
my @config;
open my $fh, '<', $file or croak "Can't open $file for reading: $!";
my $re_header = qr/^(?:(?:driver_)?dsn|key)$/;
my %args;
my $records;
while (<$fh>) {
next if /^\s*(?:#|$)/; # skip blank lines and comments
chomp;
/\s*(\w+)\s*=\s*(.*)\s*/ && do {
my ( $key, $value ) = ( $1, $2 );
if ( $key =~ $re_header ) {
push @config, {%args} if keys %args;
$records++;
%args = ();
}
elsif ( !$records ) {
croak "Record doesn't start with dsn or driver_dsn or key "
. "at $file, line $.:\n <$_>";
}
$args{$key} = $value;
next;
};
# unknown line
croak "Can't parse line at $file, line $.:\n <$_>";
}
push @config, {%args} if keys %args;
close $fh;
return @config;
}
'USING';
__END__
=head1 NAME
Test::Database::Util - Utility functions for Test::Database modules
=head1 SYNOPSIS
use Test::Database::Util;
# exports a collection of underscore functions
=head1 DESCRIPTION
C<Test::Database::Util> exports a collection of functions used by
several modules in the C<Test-Database> distribution.
=head1 EXPORTED FUNCTIONS
All functions provided by C<Test::Database::Util> are exported in the
calling package.
The following functions are provided:
=over 4
=item _read_file( $file )
Return a list of hash references, read in the given C<$file> file.
=back
=head1 AUTHOR
Philippe Bruhat (BooK), C<< <book@cpan.org> >>
=head1 COPYRIGHT
Copyright 2008-2010 Philippe Bruhat (BooK), all rights reserved.
=head1 LICENSE
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
|