r66017 - in /branches/upstream/libdancer-plugin-database-perl/current: ./ lib/Dancer/Plugin/ lib/Dancer/Plugin/Database/ t/ t/lib/ t/lib/lib/ t/lib/public/ t/lib/views/

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Dec 19 22:33:44 UTC 2010


Author: gregoa
Date: Sun Dec 19 22:33:38 2010
New Revision: 66017

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

Added:
    branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/
    branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/.placeholder
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/.placeholder
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/
    branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/.placeholder
Modified:
    branches/upstream/libdancer-plugin-database-perl/current/Changes
    branches/upstream/libdancer-plugin-database-perl/current/MANIFEST
    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/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=66017&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/Changes (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/Changes Sun Dec 19 22:33:38 2010
@@ -1,9 +1,27 @@
 Revision history for Dancer-Plugin-Database
 
-0.11  2010-11-09 (CoD Black Ops day!)
+0.90    2010-12-10
+        - New features quick_insert, quick_update, quick_delete.  The database
+          keyword now returns a Dancer::Plugin::Database::Handle object, which
+          is a subclass of DBI::db so does everything you'd expect a DBI
+          connection handle to do, but add extra convenience methods.
+        - Fixed test failures on Windows systems.
+
+       (Large version bump due to new features; assuming there are no reports of
+       issues with this version (there shouldn't be!), I'll release 1.0 soon,
+       for those who look for a >= 1.0 version number as an indication of being
+       production-ready.
+
+
+0.12    2010-12-03
+        - Documentation mentioned connectivity-check-threshold instead of the
+          correct connection_check_threshold.  Thanks to bessarabov for catching
+          this and submitting corrections via GitHub!
+
+0.11    2010-11-09 (CoD Black Ops day!)
         - Bugfix: pass connection settings when reconnecting, too.
 
-0.10  2010-10-30
+0.10    2010-10-30
         - Add some proper tests [Franck Cuny]
 
 0.09    2010-09-28

Modified: branches/upstream/libdancer-plugin-database-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/MANIFEST?rev=66017&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/MANIFEST (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/MANIFEST Sun Dec 19 22:33:38 2010
@@ -3,10 +3,14 @@
 Makefile.PL
 README
 lib/Dancer/Plugin/Database.pm
+lib/Dancer/Plugin/Database/Handle.pm
 t/00-load.t
 t/01-basic.t
 t/manifest.t
 t/pod-coverage.t
 t/pod.t
 t/lib/TestApp.pm
+t/lib/public/.placeholder
+t/lib/views/.placeholder
+t/lib/lib/.placeholder
 META.yml                                 Module meta-data (added by MakeMaker)

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=66017&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/META.yml (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/META.yml Sun Dec 19 22:33:38 2010
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Dancer-Plugin-Database
-version:            0.11
+version:            0.90
 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=66017&op=diff
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/README (original)
+++ branches/upstream/libdancer-plugin-database-perl/current/README Sun Dec 19 22:33:38 2010
@@ -1,47 +1,196 @@
-Dancer-Plugin-Database
+NAME
+    Dancer::Plugin::Database - easy database connections for Dancer
+    applications
 
-A plugin for Dancer applications, providing easy database connection handling.
+SYNOPSIS
+        use Dancer;
+        use Dancer::Plugin::Database;
 
-See http://www.perldancer.org/ for details on Dancer.
+        # Calling the database keyword will get you a connected database handle:
+        get '/widget/view/:id' => sub {
+            my $sth = database->prepare(
+                'select * from widgets where id = ?',
+            );
+            $sth->execute(params->{id});
+            template 'display_widget', { widget => $sth->fetchrow_hashref };
+        };
 
-INSTALLATION
+        # The handle is a Dancer::Plugin::Database::Handle object, which subclasses
+        # DBI's DBI::db handle and adds a few convenience features, for example:
+        get '/insert/:name' => sub {
+            database->quick_insert('people', { name => params->{name} });
+        };
 
-To install this module, run the following commands:
+        dance;
 
-	perl Makefile.PL
-	make
-	make test
-	make install
+    Database connection details are read from your Dancer application config
+    - see below.
 
-SUPPORT AND DOCUMENTATION
+DESCRIPTION
+    Provides an easy way to obtain a connected DBI database handle by simply
+    calling the database keyword within your Dancer application
 
-After installing, you can find documentation for this module with the
-perldoc command.
+    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
+    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.
 
-    perldoc Dancer::Plugin::Database
+    Takes care of ensuring that the database handle is still connected and
+    valid. If the handle was last asked for more than
+    `connection_check_threshold' seconds ago, it will check that the
+    connection is still alive, using either the `$dbh->ping' method if the
+    DBD driver supports it, or performing a simple no-op query against the
+    database if not. If the connection has gone away, a new connection will
+    be obtained and returned. This avoids any problems for a long-running
+    script where the connection to the database might go away.
 
-You can also look for information at:
+CONFIGURATION
+    Connection details will be taken from your Dancer application config
+    file, and should be specified as, for example:
 
-    RT, CPAN's request tracker
+        plugins:
+            Database:
+                driver: 'mysql'
+                database: 'test'
+                host: 'localhost'
+                username: 'myusername'
+                password: 'mypassword'
+                connection_check_threshold: 10
+                dbi_params:
+                    RaiseError: 1
+                    AutoCommit: 1
+                on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
+
+    The `connection_check_threshold' setting is optional, if not provided,
+    it will default to 30 seconds. If the database keyword was last called
+    more than this number of seconds ago, a quick check will be performed to
+    ensure that we still have a connection to the database, and will
+    reconnect if not. This handles cases where the database handle hasn't
+    been used for a while and the underlying connection has gone away.
+
+    The `dbi_params' setting is also optional, and if specified, should be
+    settings which can be passed to `DBI->connect' as its third argument;
+    see the DBI documentation for these.
+
+    The optional `on_connect_do' setting is an array of queries which should
+    be performed when a connection is established; if given, each query will
+    be performed using `$dbh->do'.
+
+    If you prefer, you can also supply a pre-crafted DSN using the `dsn'
+    setting; in that case, it will be used as-is, and the
+    driver/database/host settings will be ignored. This may be useful if
+    you're using some DBI driver which requires a peculiar DSN.
+
+  DEFINING MULTIPLE CONNECTIONS
+    If you need to connect to multiple databases, this is easy - just list
+    them in your config under `connections' as shown below:
+
+        plugins:
+            Database:
+                connections:
+                    foo:
+                        driver: "SQLite"
+                        database: "foo.sqlite"
+                    bar:
+                        driver: "mysql"
+                        host: "localhost"
+                        ....
+
+    Then, you can call the `database' keyword with the name of the database
+    connection you want, for example:
+
+        my $foo_dbh = database('foo');
+        my $bar_dbh = database('bar');
+
+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
+    database, and return a reference to the DBI object. On subsequent calls,
+    the same DBI connection object will be returned, unless it has been
+    found to be no longer usable (the connection has gone away), in which
+    case a fresh connection will be obtained.
+
+    If you have declared named connections as described above in 'DEFINING
+    MULTIPLE CONNECTIONS', then calling the database() keyword with the name
+    of the connection as specified in the config file will get you a
+    database handle connected with those details.
+
+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'
+    DBI connection handle. This means you can use it just like you'd
+    normally use a DBI handle, but extra convenience methods are provided,
+    as documented in the POD for Dancer::Plugin::Database::Handle.
+
+    Examples:
+
+      # Update the row where the 'id' column is '42', setting the 'foo' column to
+      # 'Bar':
+      database->quick_update($table_name, { id => 42 }, { foo => 'Bar');
+
+      # Insert a new row, using a named connection (see above)
+      database('connectionname')->quick_insert($table_name, { foo => 'Bar' });
+
+      # Delete the row with id 42:
+      database->quick_delete($table_name, { id => 42 });
+
+AUTHOR
+    David Precious, `<davidp at preshweb.co.uk>'
+
+CONTRIBUTING
+    This module is developed on Github at:
+
+    http://github.com/bigpresh/Dancer-Plugin-Database
+
+    Feel free to fork the repo and submit pull requests!
+
+ACKNOWLEDGEMENTS
+    Igor Bujna
+
+    Franck Cuny
+
+BUGS
+    Please report any bugs or feature requests to
+    `bug-dancer-plugin-database at rt.cpan.org', or through the web
+    interface at
+    http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Database. I
+    will be notified, and then you'll automatically be notified of progress
+    on your bug as I make changes.
+
+SUPPORT
+    You can find documentation for this module with the perldoc command.
+
+        perldoc Dancer::Plugin::Database
+
+    You can also look for information at:
+
+    * RT: CPAN's request tracker
         http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Database
 
-    AnnoCPAN, Annotated CPAN documentation
+    * AnnoCPAN: Annotated CPAN documentation
         http://annocpan.org/dist/Dancer-Plugin-Database
 
-    CPAN Ratings
+    * CPAN Ratings
         http://cpanratings.perl.org/d/Dancer-Plugin-Database
 
-    Search CPAN
+    * Search CPAN
         http://search.cpan.org/dist/Dancer-Plugin-Database/
 
+    You can find the author on IRC in the channel `#dancer' on
+    <irc.perl.org>.
 
 LICENSE AND COPYRIGHT
+    Copyright 2010 David Precious.
 
-Copyright (C) 2010 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
+    by the Free Software Foundation; or the Artistic License.
 
-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
-by the Free Software Foundation; or the Artistic License.
+    See http://dev.perl.org/licenses/ for more information.
 
-See http://dev.perl.org/licenses/ for more information.
+SEE ALSO
+    Dancer
 
+    DBI
+

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=66017&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 Dec 19 22:33:38 2010
@@ -3,6 +3,7 @@
 use strict;
 use Dancer::Plugin;
 use DBI;
+use Dancer::Plugin::Database::Handle;
 
 =head1 NAME
 
@@ -10,7 +11,7 @@
 
 =cut
 
-our $VERSION = '0.11';
+our $VERSION = '0.90';
 
 my $settings = undef;
 
@@ -112,7 +113,9 @@
         }
     }
 
-    return $dbh;
+    # Re-bless it as a Dancer::Plugin::Database::Handle object, to provide nice
+    # extra features:
+    return bless $dbh, 'Dancer::Plugin::Database::Handle';
 }
 
 
@@ -164,11 +167,20 @@
             );
         }
     }
-    
+
     # We should have soemthing to return now; remove any unrelated connections
     # (only needed if this is the default connection), and make sure we have a
-    # connection_check_threshold, then return what we found
+    # connection_check_threshold, then return what we found.  In previous
+    # versions the documentation contained a typo mentioning
+    # connectivity-check-threshold, so support that as an alias.
     delete $return_settings->{connections};
+    if (exists $return_settings->{'connectivity-check-threshold'}
+        && !exists $return_settings->{connection_check_threshold})
+    {
+        $return_settings->{connection_check_threshold}
+            = delete $return_settings->{'connectivity-check-threshold'};
+    }
+
     $return_settings->{connection_check_threshold} ||= 30;
     return $return_settings;
 
@@ -180,7 +192,7 @@
     use Dancer;
     use Dancer::Plugin::Database;
 
-    # Calling the database keyword will get you a connected DBI handle:
+    # Calling the database keyword will get you a connected database handle:
     get '/widget/view/:id' => sub {
         my $sth = database->prepare(
             'select * from widgets where id = ?',
@@ -189,6 +201,12 @@
         template 'display_widget', { widget => $sth->fetchrow_hashref };
     };
 
+    # The handle is a Dancer::Plugin::Database::Handle object, which subclasses
+    # DBI's DBI::db handle and adds a few convenience features, for example:
+    get '/insert/:name' => sub {
+        database->quick_insert('people', { name => params->{name} });
+    };
+
     dance;
 
 Database connection details are read from your Dancer application config - see
@@ -198,7 +216,12 @@
 =head1 DESCRIPTION
 
 Provides an easy way to obtain a connected DBI database handle by simply calling
-the database keyword within your L<Dancer> application.
+the database keyword within your L<Dancer> application
+
+Returns a L<Dancer::Plugin::Database::Handle> object, which is a subclass of
+L<DBI>'s C<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 L<Dancer::Plugin::Database::Handle> for full details of those.
 
 Takes care of ensuring that the database handle is still connected and valid.
 If the handle was last asked for more than C<connection_check_threshold> seconds
@@ -220,13 +243,13 @@
             host: 'localhost'
             username: 'myusername'
             password: 'mypassword'
-            connectivity-check-threshold: 10
+            connection_check_threshold: 10
             dbi_params:
                 RaiseError: 1
                 AutoCommit: 1
             on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
 
-The C<connectivity-check-threshold> setting is optional, if not provided, it
+The C<connection_check_threshold> setting is optional, if not provided, it
 will default to 30 seconds.  If the database keyword was last called more than
 this number of seconds ago, a quick check will be performed to ensure that we
 still have a connection to the database, and will reconnect if not.  This
@@ -284,6 +307,28 @@
 connection as specified in the config file will get you a database handle
 connected with those details.
 
+
+=head1 CONVENIENCE FEATURES (quick_update, quick_insert, quick_delete)
+
+The handle returned by the C<database> keyword is a
+L<Dancer::Plugin::Database::Handle> object, which subclasses the C<DBI::db> DBI
+connection handle.  This means you can use it just like you'd normally use a DBI
+handle, but extra convenience methods are provided, as documented in the POD for
+L<Dancer::Plugin::Database::Handle>.
+
+Examples:
+
+  # Update the row where the 'id' column is '42', setting the 'foo' column to
+  # 'Bar':
+  database->quick_update($table_name, { id => 42 }, { foo => 'Bar');
+
+  # Insert a new row, using a named connection (see above)
+  database('connectionname')->quick_insert($table_name, { foo => 'Bar' });
+
+  # Delete the row with id 42:
+  database->quick_delete($table_name, { id => 42 });
+
+
 =head1 AUTHOR
 
 David Precious, C<< <davidp at preshweb.co.uk> >>

Added: 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=66017&op=file
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm (added)
+++ branches/upstream/libdancer-plugin-database-perl/current/lib/Dancer/Plugin/Database/Handle.pm Sun Dec 19 22:33:38 2010
@@ -1,0 +1,177 @@
+package Dancer::Plugin::Database::Handle;
+
+use Carp;
+use DBI;
+use base qw(DBI::db);
+
+our $VERSION = '0.01';
+
+=head1 NAME
+
+Dancer::Plugin::Database::Handle
+
+=head1 DESCRIPTION
+
+Subclassed DBI connection handle with added features
+
+
+=head1 SYNOPSIS
+
+  # in your Dancer app:
+  database->quick_insert($tablename, \%data);
+
+  # Updating a record where id = 42:
+  database->quick_update($tablename, { id => 42 }, { foo => 'New value' });
+
+
+=head1 Added features
+
+A C<Dancer::Plugin::Database::Handle> object is a subclassed L<DBI::st> L<DBI>
+database handle, with the following added convenience methods:
+
+=over 4
+
+=item quick_insert
+
+  database->quick_insert('mytable', { foo => 'Bar', baz => 5 });
+
+Given a table name and a hashref of data (where keys are column names, and the
+values are, well, the values), insert a row in the table.
+
+=cut
+
+sub quick_insert {
+    my ($self, $table_name, $data) = @_;
+    return $self->_quick_query('INSERT', $table_name, $data);
+}
+
+=item quick_update
+
+  database->quick_update('mytable', { id => 42 }, { foo => 'Baz' });
+
+Given a table name, a hashref describing a where clause and a hashref of
+changes, update a row.
+
+The second parameter is a hashref of field => 'value', each of which will be
+included in the WHERE clause used, for instance:
+
+  { id => 42 }
+
+Will result in an SQL query which would include:
+
+  WHERE id = 42
+
+When more than one field => value pair is given, they will be ANDed together:
+
+  { foo => 'Bar', bar => 'Baz' }
+
+Will result in:
+
+  WHERE foo = 'Bar' AND bar = 'Baz'
+
+(Actually, parameterised queries will be used, with placeholders, so SQL
+injection attacks will not work, but it's easier to illustrate as though the
+values were interpolated directly.)
+
+=cut
+
+sub quick_update {
+    my ($self, $table_name, $where, $data) = @_;
+    return $self->_quick_query('UPDATE', $table_name, $data, $where);
+}
+
+
+=item quick_delete
+
+  database->quick_delete($table, {  id => 42 });
+
+Given a table name and a hashref to describe the rows which should be deleted,
+delete them.
+
+=cut
+
+sub quick_delete {
+    my ($self, $table_name, $where) = @_;
+    return $self->_quick_query('DELETE', $table_name, undef, $where);
+}
+
+sub _quick_query {
+    my ($self, $type, $table_name, $data, $where) = @_;
+    
+    if ($type !~ m{^ (INSERT|UPDATE|DELETE) $}x) {
+        carp "Unrecognised query type $type!";
+        return;
+    }
+    if (!$table_name || ref $table_name) {
+        carp "Expected table name as a straight scalar";
+        return;
+    }
+    if (($type eq 'INSERT' || $type eq 'UPDATE')
+        && (!$data || ref $data ne 'HASH')) 
+    {
+        carp "Expected a hashref of changes";
+        return;
+    }
+    if (($type eq 'UPDATE' || $type eq 'DELETE')
+        && (!$where || ref $where ne 'HASH')) {
+        carp "Expected a hashref of where conditions";
+        return;
+    }
+
+    $table_name = $self->quote_identifier($table_name);
+    my @bind_params;
+    my $sql = {
+        INSERT => "INSERT INTO $table_name ",
+        UPDATE => "UPDATE $table_name SET ",
+        DELETE => "DELETE FROM $table_name ",
+    }->{$type};
+    if ($type eq 'INSERT') {
+        $sql .= "("
+            . join(',', map { $self->quote($_) } keys %$data)
+            . ") VALUES ("
+            . join(',', map { "?" } values %$data)
+            . ")";
+        push @bind_params, values %$data;
+    }
+    if ($type eq 'UPDATE') {
+        $sql .= join ',', map { $self->quote_identifier($_) .'=?' } keys %$data;
+        push @bind_params, values %$data;
+    }
+    
+    if ($type eq 'UPDATE' || $type eq 'DELETE') {
+        $sql .= " WHERE " . join " AND ",
+            map { $self->quote_identifier($_) . '=?' } keys %$where;
+        push @bind_params, values %$where;
+    }
+    Dancer::Logger::debug(
+        "Executing query $sql with params " . join ',', @bind_params
+    );
+    return $self->do($sql, undef, @bind_params);
+}
+
+
+=back
+
+All of the convenience methods provided take care to quote table and column
+names using DBI's C<quote_identifier>, and use parameterised queries to avoid
+SQL injection attacks.  See L<http://www.bobby-tables.com/> for why this is
+important, if you're not familiar with it.
+
+
+=head1 AUTHOR
+
+David Precious C< <<davidp at preshweb.co.uk >> >
+
+
+=head1 SEE ALSO
+
+L<Dancer::Plugin::Database>
+
+L<Dancer>
+
+L<DBI>
+
+=cut
+
+1;
+__END__

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=66017&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 Dec 19 22:33:38 2010
@@ -12,7 +12,7 @@
     plan skip_all => 'DBD::SQLite required to run these tests';
 }
 
-plan tests => 8;
+plan tests => 14;
 
 my $dsn = "dbi:SQLite:dbname=:memory:";
 
@@ -21,7 +21,7 @@
 response_status_is [ GET => '/prepare_db' ], 200, 'db is created';
 
 response_status_is    [ GET => '/' ], 200,   "GET / is found";
-response_content_like [ GET => '/' ], qr/2/, "content looks god for /";
+response_content_like [ GET => '/' ], qr/2/, "content looks good for /";
 
 response_status_is [ GET => '/user/1' ], 200, 'GET /user/1 is found';
 
@@ -33,3 +33,20 @@
 response_status_is [ DELETE => '/user/2' ], 200, 'DELETE /user/2 is ok';
 response_content_like [ GET => '/' ], qr/1/, 'content looks good for /';
 
+# Exercise the extended features (quick_update et al)
+response_status_is    [ GET => '/quick_insert/42/Bob' ], 200, 
+    "quick_insert returned OK status";
+response_content_like [ GET => '/user/42' ], qr/Bob/,
+    "quick_insert created a record successfully";
+
+response_status_is    [ GET => '/quick_update/42/Billy' ], 200,
+    "quick_update returned OK status";
+response_content_like [ GET => '/user/42' ], qr/Billy/,
+    "quick_update updated a record successfully";
+
+response_status_is    [ GET => '/quick_delete/42' ], 200,
+    "quick_delete returned OK status";
+response_content_like [ GET => '/user/42' ], qr/No such user/,
+    "quick_delete deleted a record successfully";
+
+

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=66017&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 Dec 19 22:33:38 2010
@@ -26,7 +26,7 @@
     my $sth = database->prepare('select * from users where id = ?');
     $sth->execute( params->{id} );
     my $user = $sth->fetch();
-    $user->[1];
+    $user->[1] || "No such user";
 };
 
 del '/user/:id' => sub {
@@ -35,4 +35,28 @@
     'ok';
 };
 
+
+# Routes to exercise some of the extended features:
+get '/quick_insert/:id/:name' => sub {
+    database->quick_insert('users',
+        { id => params->{id}, name => params->{name} },
+    );
+    'ok';
+};
+
+get '/quick_update/:id/:name' => sub {
+    database->quick_update('users',
+        { id => params->{id}     },
+        { name => params->{name} },
+    );
+    'ok';
+};
+
+get '/quick_delete/:id' => sub {
+    database->quick_delete('users', { id => params->{id} });
+    'ok';
+};
+
+
+
 1;

Added: branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/.placeholder
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/.placeholder?rev=66017&op=file
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/.placeholder (added)
+++ branches/upstream/libdancer-plugin-database-perl/current/t/lib/lib/.placeholder Sun Dec 19 22:33:38 2010
@@ -1,0 +1,6 @@
+This directory is empty on purpose, and this file is here solely so that git
+tracks it, as git won't track empty directories (mostly because it doesn't track
+directories at all, only the files in them).
+
+This otherwise-empty directory is needed to avoid a strange bug on Windows 
+systems where Cwd::realpath() croaks if they don't exist.

Added: branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/.placeholder
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/.placeholder?rev=66017&op=file
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/.placeholder (added)
+++ branches/upstream/libdancer-plugin-database-perl/current/t/lib/public/.placeholder Sun Dec 19 22:33:38 2010
@@ -1,0 +1,6 @@
+This directory is empty on purpose, and this file is here solely so that git
+tracks it, as git won't track empty directories (mostly because it doesn't track
+directories at all, only the files in them).
+
+This otherwise-empty directory is needed to avoid a strange bug on Windows 
+systems where Cwd::realpath() croaks if they don't exist.

Added: branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/.placeholder
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/.placeholder?rev=66017&op=file
==============================================================================
--- branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/.placeholder (added)
+++ branches/upstream/libdancer-plugin-database-perl/current/t/lib/views/.placeholder Sun Dec 19 22:33:38 2010
@@ -1,0 +1,6 @@
+This directory is empty on purpose, and this file is here solely so that git
+tracks it, as git won't track empty directories (mostly because it doesn't track
+directories at all, only the files in them).
+
+This otherwise-empty directory is needed to avoid a strange bug on Windows 
+systems where Cwd::realpath() croaks if they don't exist.




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