r67752 - in /branches/upstream/libdancer-plugin-database-perl/current: Changes META.yml README lib/Dancer/Plugin/Database.pm lib/Dancer/Plugin/Database/Handle.pm t/01-basic.t t/lib/TestApp.pm

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Jan 23 17:11:11 UTC 2011


Author: gregoa
Date: Sun Jan 23 17:11:00 2011
New Revision: 67752

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=67752
Log:
[svn-upgrade] new version libdancer-plugin-database-perl (1.00)

Modified:
    branches/upstream/libdancer-plugin-database-perl/current/Changes
    branches/upstream/libdancer-plugin-database-perl/current/META.yml
    branches/upstream/libdancer-plugin-database-perl/current/README
    branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database.pm
    branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm
    branches/upstream/libdancer-plugin-database-perl/current/t/01-basic.t
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/TestApp.pm

Modified: branches/upstream/libdancer-plugin-database-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/Changes?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/Changes (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/Changes Sun Jan 23 17:11:00 2011
@@ -1,4 +1,11 @@
 Revision history for Dancer-Plugin-Database
+
+1.00    2011-01-10
+        - Bumping to 1.00 to signify being ready for production use, for users
+          who have a mistrust of 0.x version numbers.
+        - Applied Alan Haggai's changes to allow a hashref of settings to be
+          passed to the database() keyword at runtime.  Thanks Alan!
+          (This was released as 0.91_01 for testing first.)
 
 0.91    2010-12-21
         - Whoah - didn't "use strict" in Dancer::Plugin::Database::Handle!

Modified: branches/upstream/libdancer-plugin-database-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/META.yml?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/META.yml (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/META.yml Sun Jan 23 17:11:00 2011
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Dancer-Plugin-Database
-version:            0.91
+version:            1.00
 abstract:           easy database connections for Dancer applications
 author:
     - David Precious <davidp at preshweb.co.uk>

Modified: branches/upstream/libdancer-plugin-database-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/README?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/README (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/README Sun Jan 23 17:11:00 2011
@@ -31,7 +31,7 @@
     calling the database keyword within your Dancer application
 
     Returns a Dancer::Plugin::Database::Handle object, which is a subclass
-    of DBI's DBI::db connection handle object, so it does everything you'd
+    of DBI's `DBI::db' connection handle object, so it does everything you'd
     expect to do with DBI, but also adds a few convenience methods. See the
     documentation for Dancer::Plugin::Database::Handle for full details of
     those.
@@ -103,6 +103,15 @@
         my $foo_dbh = database('foo');
         my $bar_dbh = database('bar');
 
+RUNTIME CONFIGURATION
+    You can pass a hashref to the `database()' keyword to provide
+    configuration details to override any in the config file at runtime if
+    desired, for instance:
+
+        my $dbh = database({ driver => 'SQLite', database => $filename });
+
+    (Thanks to Alan Haggai for this feature.)
+
 GETTING A DATABASE HANDLE
     Calling `database' will return a connected database handle; the first
     time it is called, the plugin will establish a connection to the
@@ -116,6 +125,9 @@
     of the connection as specified in the config file will get you a
     database handle connected with those details.
 
+    You can also pass a hashref of settings if you wish to provide settings
+    at runtime.
+
 CONVENIENCE FEATURES (quick_update, quick_insert, quick_delete)
     The handle returned by the `database' keyword is a
     Dancer::Plugin::Database::Handle object, which subclasses the `DBI::db'
@@ -149,6 +161,8 @@
     Igor Bujna
 
     Franck Cuny
+
+    Alan Haggai
 
 BUGS
     Please report any bugs or feature requests to
@@ -181,7 +195,7 @@
     <irc.perl.org>.
 
 LICENSE AND COPYRIGHT
-    Copyright 2010 David Precious.
+    Copyright 2010-11 David Precious.
 
     This program is free software; you can redistribute it and/or modify it
     under the terms of either: the GNU General Public License as published

Modified: branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database.pm?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database.pm (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database.pm Sun Jan 23 17:11:00 2011
@@ -11,7 +11,7 @@
 
 =cut
 
-our $VERSION = '0.91';
+our $VERSION = '1.00';
 
 my $settings = undef;
 
@@ -24,12 +24,24 @@
 my $def_handle = {};
 
 register database => sub {
-    my $name = shift;
+    my $arg = shift;
+
+    my $name;
+    my $handle;
 
     _load_db_settings() if (!$settings);
-    
-    my $handle = defined($name) ? $handles{$name} : $def_handle;
-    my $settings = _get_settings($name);
+
+    # Update settings from configuration file with those from application
+    if ( ref $arg eq 'HASH' ) {
+        for my $key ( keys %$arg ) {
+            $settings->{$key} = $arg->{$key};
+        }
+    }
+    else {
+        $name     = $arg;
+        $handle   = defined($name) ? $handles{$name} : $def_handle;
+        $settings = _get_settings($name);
+    }
 
     if ($handle->{dbh}) {
         if (time - $handle->{last_connection_check}
@@ -293,6 +305,15 @@
     my $bar_dbh = database('bar');
 
 
+=head1 RUNTIME CONFIGURATION
+
+You can pass a hashref to the C<database()> keyword to provide configuration
+details to override any in the config file at runtime if desired, for instance:
+
+    my $dbh = database({ driver => 'SQLite', database => $filename });
+
+(Thanks to Alan Haggai for this feature.)
+
 
 =head1 GETTING A DATABASE HANDLE
 
@@ -307,6 +328,9 @@
 connection as specified in the config file will get you a database handle
 connected with those details.
 
+You can also pass a hashref of settings if you wish to provide settings at
+runtime.
+
 
 =head1 CONVENIENCE FEATURES (quick_update, quick_insert, quick_delete)
 
@@ -350,6 +374,8 @@
 
 Franck Cuny
 
+Alan Haggai
+
 =head1 BUGS
 
 Please report any bugs or feature requests to C<bug-dancer-plugin-database at rt.cpan.org>, or through
@@ -393,7 +419,7 @@
 
 =head1 LICENSE AND COPYRIGHT
 
-Copyright 2010 David Precious.
+Copyright 2010-11 David Precious.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of either: the GNU General Public License as published

Modified: branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm Sun Jan 23 17:11:00 2011
@@ -27,7 +27,7 @@
 
 =head1 Added features
 
-A C<Dancer::Plugin::Database::Handle> object is a subclassed L<DBI::st> L<DBI>
+A C<Dancer::Plugin::Database::Handle> object is a subclassed L<DBI::db> L<DBI>
 database handle, with the following added convenience methods:
 
 =over 4

Modified: branches/upstream/libdancer-plugin-database-perl/current/t/01-basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/t/01-basic.t?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/t/01-basic.t (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/t/01-basic.t Sun Jan 23 17:11:00 2011
@@ -12,7 +12,7 @@
     plan skip_all => 'DBD::SQLite required to run these tests';
 }
 
-plan tests => 14;
+plan tests => 16;
 
 my $dsn = "dbi:SQLite:dbname=:memory:";
 
@@ -49,4 +49,9 @@
 response_content_like [ GET => '/user/42' ], qr/No such user/,
     "quick_delete deleted a record successfully";
 
+# Test that runtime configuration gives us a handle, too:
+response_status_is    [ GET => '/runtime_config' ], 200,
+    "runtime_config returned OK status";
+response_content_like [ GET => '/runtime_config' ], qr/ok/,
+    "runtime_config got a usable database handle";
 

Modified: branches/upstream/libdancer-plugin-database-perl/current/t/lib/TestApp.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/t/lib/TestApp.pm?rev=67752&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/t/lib/TestApp.pm (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/t/lib/TestApp.pm Sun Jan 23 17:11:00 2011
@@ -57,6 +57,10 @@
     'ok';
 };
 
-
+# Check we can get a handle by passing a hashref of settings, too:
+get '/runtime_config' => sub {
+    my $dbh = database({ driver => 'SQLite', database => ':memory'});
+    $dbh ? 'ok' : '';
+};
 
 1;




More information about the Pkg-perl-cvs-commits mailing list