Skip to content

Commit fec3d0e

Browse files
committed
add extra config to main connect method
We mostly use connect_from_config() to connect to the database. Now we have the ability to add additional configuration to this method, for example to add an `on_connect_do` subref to track reconnections to the database.
1 parent 4c193dc commit fec3d0e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/CPAN/Testers/Schema.pm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ __PACKAGE__->upgrade_directory( dist_dir( 'CPAN-Testers-Schema' ) );
4242

4343
=method connect_from_config
4444
45-
my $schema = CPAN::Testers::Schema->connect_from_config;
45+
my $schema = CPAN::Testers::Schema->connect_from_config( %extra_conf );
4646
4747
Connect to the MySQL database using a local MySQL configuration file
4848
in C<$HOME/.cpanstats.cnf>. This configuration file should look like:
@@ -55,10 +55,14 @@ in C<$HOME/.cpanstats.cnf>. This configuration file should look like:
5555
5656
See L<DBD::mysql/mysql_read_default_file>.
5757
58+
C<%extra_conf> will be added to the L<DBIx::Class::Schema/connect>
59+
method in the C<%dbi_attributes> hashref (see
60+
L<DBIx::Class::Storage::DBI/connect_info>).
61+
5862
=cut
5963

6064
# Convenience connect method
61-
sub connect_from_config ( $class ) {
65+
sub connect_from_config ( $class, %config ) {
6266
my $schema = $class->connect(
6367
"DBI:mysql:mysql_read_default_file=$ENV{HOME}/.cpanstats.cnf;".
6468
"mysql_read_default_group=application;mysql_enable_utf8=1",
@@ -70,6 +74,7 @@ sub connect_from_config ( $class ) {
7074
mysql_enable_utf8 => 1,
7175
quote_char => '`',
7276
name_sep => '.',
77+
%config,
7378
},
7479
);
7580
return $schema;

0 commit comments

Comments
 (0)