{"action":"created","issue":{"url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/75","labels_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/75/comments","events_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/75/events","html_url":"https://github.com/bigpresh/Dancer-Plugin-Database/issues/75","id":118117977,"number":75,"title":"Applying settings to database() at runtime does not reuse database connections","user":{"login":"yahermann","id":4622382,"avatar_url":"https://avatars.githubusercontent.com/u/4622382?v=3","gravatar_id":"","url":"https://api.github.com/users/yahermann","html_url":"https://github.com/yahermann","followers_url":"https://api.github.com/users/yahermann/followers","following_url":"https://api.github.com/users/yahermann/following{/other_user}","gists_url":"https://api.github.com/users/yahermann/gists{/gist_id}","starred_url":"https://api.github.com/users/yahermann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahermann/subscriptions","organizations_url":"https://api.github.com/users/yahermann/orgs","repos_url":"https://api.github.com/users/yahermann/repos","events_url":"https://api.github.com/users/yahermann/events{/privacy}","received_events_url":"https://api.github.com/users/yahermann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-20T20:14:50Z","updated_at":"2015-12-15T21:23:41Z","closed_at":null,"body":"Per documentation, using database() in this way:\r\n\r\n    my $dbh = database({ driver => 'SQLite', database => $filename });\r\n\r\ncauses a brand new connection to be created each time, and old connections don't get disconnected, so the max gets hits quickly.\r\n\r\nThe problem appears to be in Database.pm, lines 52-54:\r\n\r\n    if (ref $arg eq 'HASH') {\r\n        $handle_key = $arg;\r\n        $conn_details = _merge_settings($arg, $settings, $logger);\r\n     } else {\r\n\r\nEven though $arg may be the same hash, i.e., { database => \"mydb\", username=\"myuser\" }, unless special precautions are taken, generating it during runtime creates a different anonymous hashref each time, therefore when used as a key, Perl treats them each as different keys.  Since they're different keys, a new connection gets created with each call, and old connections/handles are not reused.\r\n"},"comment":{"url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/comments/164900876","html_url":"https://github.com/bigpresh/Dancer-Plugin-Database/issues/75#issuecomment-164900876","issue_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/75","id":164900876,"user":{"login":"yahermann","id":4622382,"avatar_url":"https://avatars.githubusercontent.com/u/4622382?v=3","gravatar_id":"","url":"https://api.github.com/users/yahermann","html_url":"https://github.com/yahermann","followers_url":"https://api.github.com/users/yahermann/followers","following_url":"https://api.github.com/users/yahermann/following{/other_user}","gists_url":"https://api.github.com/users/yahermann/gists{/gist_id}","starred_url":"https://api.github.com/users/yahermann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahermann/subscriptions","organizations_url":"https://api.github.com/users/yahermann/orgs","repos_url":"https://api.github.com/users/yahermann/repos","events_url":"https://api.github.com/users/yahermann/events{/privacy}","received_events_url":"https://api.github.com/users/yahermann/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T21:23:41Z","updated_at":"2015-12-15T21:23:41Z","body":"Fair enough :-)"}}