Index: trunk/lib/MP3/Find/DB.pm
===================================================================
--- trunk/lib/MP3/Find/DB.pm	(revision 32)
+++ trunk/lib/MP3/Find/DB.pm	(revision 33)
@@ -135,82 +135,4 @@
 =back
 
-=head1 METHODS
-
-=head2 new
-
-    my $finder = MP3::Find::DB->new(
-        status_callback => \&callback,
-    );
-
-The C<status_callback> gets called each time an entry in the
-database is added, updated, or deleted by the C<update_db> and
-C<sync_db> methods. The arguments passed to the callback are
-a status code (A, U, or D) and the filename for that entry.
-The default callback just prints these to C<STDERR>:
-
-    sub default_callback {
-        my ($status_code, $filename) = @_;
-        print STDERR "$status_code $filename\n";
-    }
-
-To suppress any output, set C<status_callback> to an empty sub:
-
-    status_callback => sub {}
-
-=head2 create
-
-    $finder->create({
-	dsn => 'dbi:SQLite:dbname=mp3.db',
-	dbh => $dbh,
-	db_file => 'mp3.db',
-    });
-
-Creates a new table for storing mp3 info in the database. You can provide
-either a DSN (plus username and password, if needed), an already created
-database handle, or just the name of an SQLite database file.
-
-=cut
-
-sub create {
-    my $self = shift;
-    my $args = shift;
-
-    my $dbh = _get_dbh($args) or croak "Please provide a DBI database handle, DSN, or SQLite database filename";
-    
-    my $create = 'CREATE TABLE mp3 (' . join(',', map { "$$_[0] $$_[1]" } @COLUMNS) . ')';
-    $dbh->do($create);
-}
-
-=head2 create_db
-
-    $finder->create_db($db_filename);
-
-Creates a SQLite database in the file named c<$db_filename>.
-
-=cut
-
-# TODO: convert to using DSNs instead of hardcoded SQLite connections
-# TODO: extended table for ID3v2 data
-sub create_db {
-    my $self = shift;
-    my $db_file = shift or croak "Need a name for the database I'm about to create";
-    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1});
-    my $create = 'CREATE TABLE mp3 (' . join(',', map { "$$_[0] $$_[1]" } @COLUMNS) . ')';
-    $dbh->do($create);
-}
-
-=head2 update
-
-    my $count = $finder->update({
-	dsn   => 'dbi:SQLite:dbname=mp3.db',
-	files => \@filenames,
-	dirs  => \@dirs,
-    });
-
-Compares the files in the C<files> list plus any MP3s found by searching
-in C<dirs> to their records in the database pointed to by C<dsn>. If the
-files found have been updated since they have been recorded in the database
-(or if they are not in the database), they are updated (or added).
-
 =cut
 
@@ -239,5 +161,98 @@
     return;
 }
-	
+
+sub _sqlite_workaround {
+    # as a workaround for the 'closing dbh with active staement handles warning
+    # (see http://rt.cpan.org/Ticket/Display.html?id=9643#txn-120724)
+    foreach (@_) {
+        $_->{RaiseError} = 0;  # don't die on error
+        $_->{PrintError} = 0;  # ...and don't even say anything
+        $_->{Active} = 1;
+        $_->finish;
+    }
+}
+ 
+=head1 METHODS
+
+=head2 new
+
+    my $finder = MP3::Find::DB->new(
+        status_callback => \&callback,
+    );
+
+The C<status_callback> gets called each time an entry in the
+database is added, updated, or deleted by the C<update_db> and
+C<sync_db> methods. The arguments passed to the callback are
+a status code (A, U, or D) and the filename for that entry.
+The default callback just prints these to C<STDERR>:
+
+    sub default_callback {
+        my ($status_code, $filename) = @_;
+        print STDERR "$status_code $filename\n";
+    }
+
+To suppress any output, set C<status_callback> to an empty sub:
+
+    status_callback => sub {}
+
+=head2 create
+
+    $finder->create({
+	dsn => 'dbi:SQLite:dbname=mp3.db',
+	dbh => $dbh,
+	db_file => 'mp3.db',
+    });
+
+Creates a new table for storing mp3 info in the database. You can provide
+either a DSN (plus username and password, if needed), an already created
+database handle, or just the name of an SQLite database file.
+
+=cut
+
+sub create {
+    my $self = shift;
+    my $args = shift;
+
+    my $dbh = _get_dbh($args) or croak "Please provide a DBI database handle, DSN, or SQLite database filename";
+    
+    my $create = 'CREATE TABLE mp3 (' . join(',', map { "$$_[0] $$_[1]" } @COLUMNS) . ')';
+    $dbh->do($create);
+}
+
+=head2 create_db (DEPRECATED)
+
+    $finder->create_db($db_filename);
+
+Creates a SQLite database in the file named c<$db_filename>.
+
+=cut
+
+# TODO: extended table for ID3v2 data
+sub create_db {
+    my $self = shift;
+    my $db_file = shift or croak "Need a name for the database I'm about to create";
+    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1});
+    my $create = 'CREATE TABLE mp3 (' . join(',', map { "$$_[0] $$_[1]" } @COLUMNS) . ')';
+    $dbh->do($create);
+}
+
+=head2 update
+
+    my $count = $finder->update({
+	dsn   => 'dbi:SQLite:dbname=mp3.db',
+	files => \@filenames,
+	dirs  => \@dirs,
+    });
+
+Compares the files in the C<files> list plus any MP3s found by searching
+in C<dirs> to their records in the database pointed to by C<dsn>. If the
+files found have been updated since they have been recorded in the database
+(or if they are not in the database), they are updated (or added).
+
+Instead of a C<dsn>, you can also provide either an already created
+database handle as C<dbh> or the filename of an SQLite database as C<db_file>.
+
+=cut
+
 # this is update_db and update_files (from Matt Dietrich) rolled into one
 sub update {
@@ -310,18 +325,11 @@
     }
     
-    # SQLite specific code:
-    # as a workaround for the 'closing dbh with active staement handles warning
-    # (see http://rt.cpan.org/Ticket/Display.html?id=9643#txn-120724)
-    foreach ($mtime_sth, $insert_sth, $update_sth) {
-        $_->{RaiseError} = 0;  # don't die on error
-        $_->{PrintError} = 0;  # ...and don't even say anything
-        $_->{Active} = 1;
-        $_->finish;
-    }
-    
+    # SQLite buggy driver
+    _sqlite_workaround($mtime_sth, $insert_sth, $update_sth);
+     
     return $count;
 }
 
-=head2 update_db
+=head2 update_db (DEPRECATED)
 
     my $count = $finder->update_db($db_filename, \@dirs);
@@ -385,12 +393,6 @@
     }
     
-    # as a workaround for the 'closing dbh with active staement handles warning
-    # (see http://rt.cpan.org/Ticket/Display.html?id=9643#txn-120724)
-    foreach ($mtime_sth, $insert_sth, $update_sth) {
-        $_->{RaiseError} = 0;  # don't die on error
-        $_->{PrintError} = 0;  # ...and don't even say anything
-        $_->{Active} = 1;
-        $_->finish;
-    }
+    # SQLite buggy driver
+    _sqlite_workaround($mtime_sth, $insert_sth, $update_sth);
     
     return $count;
@@ -398,4 +400,10 @@
 
 =head2 sync
+
+    my $count = $finder->sync({ dsn => $DSN });
+
+Removes entries from the database that refer to files that no longer
+exist in the filesystem. Returns the count of how many records were
+removed.
 
 =cut
@@ -424,8 +432,11 @@
     }
     
+    # SQLite buggy driver
+    _sqlite_workaround($select_sth, $delete_sth);
+    
     return $count;    
 }
 
-=head2 sync_db
+=head2 sync_db (DEPRECATED)
 
     my $count = $finder->sync_db($db_filename);
@@ -437,5 +448,4 @@
 =cut
 
-# TODO: use DSNs instead of SQLite db names
 sub sync_db {
     my $self = shift;
@@ -474,10 +484,9 @@
 sub destroy_db {
     my $self = shift;
-    my $db_file = shift or croak "Need the name of a database to destory";
+    my $db_file = shift or croak "Need the name of a database to destroy";
     unlink $db_file;
 }
 
 
-# TODO: use DSNs instead of SQLite db names
 sub search {
     my $self = shift;
@@ -486,5 +495,5 @@
     croak 'Need a database name to search (set "db_file" in the call to find_mp3s)' unless $$options{db_file};
     
-    my $dbh = DBI->connect("dbi:SQLite:dbname=$$options{db_file}", '', '', {RaiseError => 1});
+    my $dbh = _get_dbh($options);
     
     # use the 'LIKE' operator to ignore case
