From: Peter Rabbitson Date: Sun, 10 Oct 2010 18:13:07 +0000 (+0200) Subject: Load sqlite backup required modules on demand only X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=357eb92cffca5b9e9a50ef0c14cf579c936de101;p=dbsrgits%2FDBIx-Class-Historic.git Load sqlite backup required modules on demand only --- diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index 766eb13..6e6e7bb 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -6,15 +6,15 @@ use warnings; use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; -use POSIX 'strftime'; -use File::Copy; -use File::Spec; - __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite'); __PACKAGE__->sql_limit_dialect ('LimitOffset'); -sub backup -{ +sub backup { + + require File::Spec; + require File::Copy; + require POSIX; + my ($self, $dir) = @_; $dir ||= './'; @@ -26,20 +26,20 @@ sub backup { $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i); } - $self->throw_exception("Cannot determine name of SQLite db file") + $self->throw_exception("Cannot determine name of SQLite db file") if(!$dbname || !-f $dbname); # print "Found database: $dbname\n"; # my $dbfile = file($dbname); my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname); # my $file = $dbfile->basename(); - $file = strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file; + $file = POSIX::strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file; $file = "B$file" while(-f $file); mkdir($dir) unless -f $dir; my $backupfile = File::Spec->catfile($dir, $file); - my $res = copy($dbname, $backupfile); + my $res = File::Copy::copy($dbname, $backupfile); $self->throw_exception("Backup failed! ($!)") if(!$res); return $backupfile; @@ -62,7 +62,7 @@ sub deployment_statements { $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest); } -sub datetime_parser_type { return "DateTime::Format::SQLite"; } +sub datetime_parser_type { return "DateTime::Format::SQLite"; } =head2 connect_call_use_foreign_keys