r49927 - in /branches/upstream/liborlite-perl/current: Changes MANIFEST META.yml README lib/ORLite.pm t/02_basics.t t/04_readonly.t t/08_prune.pl t/09_badfile.t t/lib/Test.pm
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sat Jan 2 16:58:12 UTC 2010
Author: jawnsy-guest
Date: Sat Jan 2 16:58:07 2010
New Revision: 49927
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=49927
Log:
[svn-upgrade] Integrating new upstream version, liborlite-perl (1.31)
Added:
branches/upstream/liborlite-perl/current/t/09_badfile.t
Modified:
branches/upstream/liborlite-perl/current/Changes
branches/upstream/liborlite-perl/current/MANIFEST
branches/upstream/liborlite-perl/current/META.yml
branches/upstream/liborlite-perl/current/README
branches/upstream/liborlite-perl/current/lib/ORLite.pm
branches/upstream/liborlite-perl/current/t/02_basics.t
branches/upstream/liborlite-perl/current/t/04_readonly.t
branches/upstream/liborlite-perl/current/t/08_prune.pl
branches/upstream/liborlite-perl/current/t/lib/Test.pm
Modified: branches/upstream/liborlite-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/Changes?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/Changes (original)
+++ branches/upstream/liborlite-perl/current/Changes Sat Jan 2 16:58:07 2010
@@ -1,4 +1,34 @@
Changes for Perl extension ORLite
+
+1.31 Sat 2 Jan 2010
+ - Adding explicit versioned-use lines to the generated code (in case
+ the generated code is used independantly to its creation)
+
+1.30 Sat 2 Jan 2010
+ - Switching to a production release, CPAN Testers looks ok
+ - Update DBD::SQLite dependency to 1.27. Some of the metadata pragmas
+ have changed, and we don't want to have to support both the old and
+ new versions.
+ - ORLite will now correctly use RaiseError => 1, PrintError => 0 when
+ itself introspecting the schema, so a corrupted SQLite database
+ won't result in silent failure and the larger parent application
+ won't crash in unpredictable ways.
+
+1.29_03 Thu 1 Oct 2009
+ - Reverse the prune deletion order
+ - Apply recursive delete flag
+
+1.29_02 Tue 29 Sep 2009
+ - Changed ->load to use selectrow_hashref
+ - Allow ->load calls for multiple-columns primary keys
+ - All connections now explicitly RaiseError => 1 for correctness
+ - All connections now explicitly PrintError => 0 to avoid spewing
+ stuff to STDOUT/STDERR unexpectedly in embedded scenarios.
+ - Remove most explicit error handling and allow the native DBI
+ errors to cascade upwards instead.
+
+1.29_01 Mon 28 Sep 2009
+ - Adding first experimental implementation of ->load
1.28 Fri 25 Sep 2009
- Adding ->prune method that so that pruning can also be done
Modified: branches/upstream/liborlite-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/MANIFEST?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/MANIFEST (original)
+++ branches/upstream/liborlite-perl/current/MANIFEST Sat Jan 2 16:58:07 2010
@@ -27,6 +27,7 @@
t/07_pk.t
t/08_prune.pl
t/08_prune.t
+t/09_badfile.t
t/97_meta.t
t/98_pod.t
t/99_pmv.t
Modified: branches/upstream/liborlite-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/META.yml?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/META.yml (original)
+++ branches/upstream/liborlite-perl/current/META.yml Sat Jan 2 16:58:07 2010
@@ -21,7 +21,7 @@
- inc
- t
requires:
- DBD::SQLite: 1.25
+ DBD::SQLite: 1.27
DBI: 1.607
File::Basename: 0
File::Path: 2.04
@@ -34,4 +34,4 @@
ChangeLog: http://fisheye2.atlassian.com/changelog/cpan/trunk/ORLite
license: http://dev.perl.org/licenses/
repository: http://svn.ali.as/cpan/trunk/ORLite
-version: 1.28
+version: 1.31
Modified: branches/upstream/liborlite-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/README?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/README (original)
+++ branches/upstream/liborlite-perl/current/README Sat Jan 2 16:58:07 2010
@@ -274,7 +274,7 @@
ORLite::Mirror, ORLite::Migrate
COPYRIGHT
- Copyright 2008 - 2009 Adam Kennedy.
+ Copyright 2008 - 2010 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Modified: branches/upstream/liborlite-perl/current/lib/ORLite.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/lib/ORLite.pm?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/lib/ORLite.pm (original)
+++ branches/upstream/liborlite-perl/current/lib/ORLite.pm Sat Jan 2 16:58:07 2010
@@ -11,20 +11,20 @@
use File::Basename 0 ();
use Params::Util 0.33 ();
use DBI 1.607 ();
-use DBD::SQLite 1.25 ();
+use DBD::SQLite 1.27 ();
use vars qw{$VERSION};
BEGIN {
- $VERSION = '1.28';
+ $VERSION = '1.31';
}
# Support for the 'prune' option
my @PRUNE = ();
END {
- foreach ( @PRUNE ) {
+ foreach ( reverse @PRUNE ) {
next unless -e $_;
require File::Remove;
- File::Remove::remove($_);
+ File::Remove::remove( \1, $_ );
}
}
@@ -101,7 +101,10 @@
my $pkg = $params{package};
my $readonly = $params{readonly};
my $dsn = "dbi:SQLite:$file";
- my $dbh = DBI->connect($dsn);
+ my $dbh = DBI->connect( $dsn, undef, undef, {
+ PrintError => 0,
+ RaiseError => 1,
+ } );
# Schema creation support
if ( $created and Params::Util::_CODELIKE($params{create}) ) {
@@ -111,7 +114,7 @@
# Check the schema version before generating
my $version = $dbh->selectrow_arrayref('pragma user_version')->[0];
if ( exists $params{user_version} and $version != $params{user_version} ) {
- die "Schema user_version mismatch (got $version, wanted $params{user_version})";
+ Carp::croak("Schema user_version mismatch (got $version, wanted $params{user_version})");
}
# Generate the support package code
@@ -119,8 +122,9 @@
package $pkg;
use strict;
-use Carp ();
-use DBI ();
+use Carp ();
+use DBI 1.607 ();
+use DBD::SQLite 1.27 ();
my \$DBH = undef;
@@ -131,13 +135,14 @@
sub dsn { '$dsn' }
sub dbh {
- \$DBH or
- \$_[0]->connect or
- Carp::croak("connect: \$DBI::errstr");
+ \$DBH or \$_[0]->connect;
}
sub connect {
- DBI->connect(\$_[0]->dsn);
+ DBI->connect( \$_[0]->dsn, undef, undef, {
+ PrintError => 0,
+ RaiseError => 1,
+ } );
}
sub prepare {
@@ -194,8 +199,7 @@
$code .= <<"END_PERL" unless $readonly;
sub begin {
\$DBH or
- \$DBH = \$_[0]->connect or
- Carp::croak("connect: \$DBI::errstr");
+ \$DBH = \$_[0]->connect;
\$DBH->begin_work;
}
@@ -260,6 +264,7 @@
# Discover the primary key
@{$table->{pk}} = map($_->{name}, grep { $_->{pk} } @columns);
+ $table->{pks} = scalar(@{$table->{pk}});
# What will be the class for this table
$table->{class} = ucfirst lc $table->{name};
@@ -276,6 +281,7 @@
"insert into $table->{name}" .
"( $table->{sql}->{cols} )" .
" values ( $table->{sql}->{vals} )";
+ $sql->{where_pk} = join(' and ', map("$_ = ?", @{$table->{pk}}))
}
# Generate the foreign key metadata
@@ -343,17 +349,34 @@
END_PERL
+ # Add the primary key based single object loader
+ if ( $table->{pks} ) {
+ $code .= <<"END_PERL";
+sub load {
+ my \$class = shift;
+ my \$row = $pkg->selectrow_hashref(
+ '$sql->{select} where $sql->{where_pk}',
+ undef, \@_,
+ );
+ unless ( \$row ) {
+ Carp::croak("$table->{class} row does not exist");
+ }
+ bless( \$row, '$table->{class}' );
+}
+
+END_PERL
+ }
+
# Generate the elements for tables with primary keys
if ( defined $table->{pk} and ! $readonly ) {
my $nattr = join "\n", map { "\t\t$_ => \$attr{$_}," } @names;
my $iattr = join "\n", map { "\t\t\$self->{$_}," } @names;
my $fill_pk = scalar @{$table->{pk}} == 1
- ? "\t\$self->{$table->{pk}->[0]} = \$dbh->func('last_insert_rowid') unless \$self->{$table->{pk}->[0]};"
- : q{};
+ ? "\t\$self->{$table->{pk}->[0]} = \$dbh->func('last_insert_rowid') unless \$self->{$table->{pk}->[0]};"
+ : q{};
my $where_pk = join(' and ', map("$_ = ?", @{$table->{pk}}));
- my $where_pk_attr = join("\n", map("\t\t\$self->{$_},", @{$table->{pk}}));
+ my $where_pk_attr = join("\n", map("\t\t\$self->{$_},", @{$table->{pk}}));
$code .= <<"END_PERL";
-
sub new {
my \$class = shift;
my \%attr = \@_;
@@ -369,7 +392,7 @@
sub insert {
my \$self = shift;
my \$dbh = $pkg->dbh;
- \$dbh->do('$sql->{insert}', {},
+ \$dbh->do( '$sql->{insert}', {},
$iattr
);
$fill_pk
@@ -759,7 +782,7 @@
=head1 COPYRIGHT
-Copyright 2008 - 2009 Adam Kennedy.
+Copyright 2008 - 2010 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
Modified: branches/upstream/liborlite-perl/current/t/02_basics.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/02_basics.t?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/02_basics.t (original)
+++ branches/upstream/liborlite-perl/current/t/02_basics.t Sat Jan 2 16:58:07 2010
@@ -9,7 +9,7 @@
$^W = 1;
}
-use Test::More tests => 65;
+use Test::More tests => 68;
use File::Spec::Functions ':ALL';
use t::lib::Test;
@@ -57,6 +57,7 @@
Foo::Bar::TableOne->create( col1 => 1, col2 => 'foo' ),
'Created row 1',
);
+isa_ok( Foo::Bar::TableOne->load(1), 'Foo::Bar::TableOne' );
my $new = Foo::Bar::TableOne->create( col2 => 'bar' );
isa_ok( $new, 'Foo::Bar::TableOne' );
is( $new->col1, 2, '->col1 ok' );
@@ -82,7 +83,6 @@
isa_ok( $ones->[2], 'Foo::Bar::TableOne' );
is( $ones->[2]->col1, 3, '->col1 ok' );
is( $ones->[2]->col2, 'bar', '->col2 ok' );
-
}
# Fetch the rows (list context)
@@ -160,3 +160,19 @@
ok( Foo::Bar::TableOne->truncate, '->truncate ok' );
is( Foo::Bar::TableOne->count, 0, 'Commit ok' );
}
+
+
+
+
+
+######################################################################
+# Exceptions
+
+# Load an object that does not exist
+SCOPE: {
+ my @rv = eval {
+ Foo::Bar::TableOne->load(undef);
+ };
+ is( scalar(@rv), 0, 'Exception returns nothing' );
+ like( $@, qr/Foo::Bar::TableOne row does not exist/, 'Foo::Bar::TableOne row does not exist' );
+}
Modified: branches/upstream/liborlite-perl/current/t/04_readonly.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/04_readonly.t?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/04_readonly.t (original)
+++ branches/upstream/liborlite-perl/current/t/04_readonly.t Sat Jan 2 16:58:07 2010
@@ -9,7 +9,7 @@
$^W = 1;
}
-use Test::More tests => 9;
+use Test::More tests => 12;
use File::Spec::Functions ':ALL';
use t::lib::Test;
@@ -46,7 +46,11 @@
1;
END_PERL
+# Check standard methods exist
is( Foo::Bar->orlite, $t::lib::Test::VERSION, '->orlite ok' );
+ok( Foo::Bar->can('sqlite'), '->sqlite method exists' );
+ok( Foo::Bar::TableOne->can('load'), '->load method exists' );
+ok( Foo::Bar::TableOne->can('select'), '->select method exists' );
# Check the user_version value
is( Foo::Bar->pragma('user_version'), 10, '->user_version ok' );
Modified: branches/upstream/liborlite-perl/current/t/08_prune.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/08_prune.pl?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/08_prune.pl (original)
+++ branches/upstream/liborlite-perl/current/t/08_prune.pl Sat Jan 2 16:58:07 2010
@@ -4,7 +4,9 @@
use strict;
-unless ( $ORLite::VERSION eq '1.28' ) {
+our $VERSION = '1.31';
+
+unless ( $ORLite::VERSION eq $VERSION ) {
die('Failed to load correct ORLite version');
}
Added: branches/upstream/liborlite-perl/current/t/09_badfile.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/09_badfile.t?rev=49927&op=file
==============================================================================
--- branches/upstream/liborlite-perl/current/t/09_badfile.t (added)
+++ branches/upstream/liborlite-perl/current/t/09_badfile.t Sat Jan 2 16:58:07 2010
@@ -1,0 +1,36 @@
+#!/usr/bin/perl
+
+# Test ORLite's behaviour when the SQLite file is broken
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use Test::More tests => 2;
+use Test::Script;
+use File::Remove;
+use t::lib::Test;
+
+# Where the test file will be
+my $file = test_db();
+ok( ! -f $file, 'File does not exist' );
+
+# Corrupt the database file
+open( FILE, '>', $file ) or die("open: $!");
+print FILE "broken" or die("print: $!");
+close FILE or die("close: $!");
+
+# Try to load the database
+eval <<'END_PERL';
+package Foo;
+
+use ORLite {
+ file => $file,
+ prune => 1,
+};
+
+1;
+END_PERL
+ok( $@, 'Loading a bad database throws an exception' );
Modified: branches/upstream/liborlite-perl/current/t/lib/Test.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/lib/Test.pm?rev=49927&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/lib/Test.pm (original)
+++ branches/upstream/liborlite-perl/current/t/lib/Test.pm Sat Jan 2 16:58:07 2010
@@ -8,7 +8,7 @@
use vars qw{$VERSION @ISA @EXPORT};
BEGIN {
- $VERSION = '1.28';
+ $VERSION = '1.31';
@ISA = 'Exporter';
@EXPORT = qw{ test_db connect_ok create_ok };
}
More information about the Pkg-perl-cvs-commits
mailing list