From fec3d0ec15c5859fab06525178a6c5414b4b0f2c Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Fri, 20 Apr 2018 10:14:00 +0200 Subject: [PATCH] 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. --- lib/CPAN/Testers/Schema.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/CPAN/Testers/Schema.pm b/lib/CPAN/Testers/Schema.pm index 145772d..8606416 100644 --- a/lib/CPAN/Testers/Schema.pm +++ b/lib/CPAN/Testers/Schema.pm @@ -42,7 +42,7 @@ __PACKAGE__->upgrade_directory( dist_dir( 'CPAN-Testers-Schema' ) ); =method connect_from_config - my $schema = CPAN::Testers::Schema->connect_from_config; + my $schema = CPAN::Testers::Schema->connect_from_config( %extra_conf ); Connect to the MySQL database using a local MySQL configuration file 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: See L. +C<%extra_conf> will be added to the L +method in the C<%dbi_attributes> hashref (see +L). + =cut # Convenience connect method -sub connect_from_config ( $class ) { +sub connect_from_config ( $class, %config ) { my $schema = $class->connect( "DBI:mysql:mysql_read_default_file=$ENV{HOME}/.cpanstats.cnf;". "mysql_read_default_group=application;mysql_enable_utf8=1", @@ -70,6 +74,7 @@ sub connect_from_config ( $class ) { mysql_enable_utf8 => 1, quote_char => '`', name_sep => '.', + %config, }, ); return $schema;