r67591 - in /branches/upstream/liborlite-perl/current: Changes MANIFEST META.yml README lib/ORLite.pm t/08_prune.pl t/17_cache.t t/20_shim.t t/lib/Test.pm
angelabad-guest at users.alioth.debian.org
angelabad-guest at users.alioth.debian.org
Fri Jan 21 10:05:40 UTC 2011
Author: angelabad-guest
Date: Fri Jan 21 10:03:12 2011
New Revision: 67591
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=67591
Log:
[svn-upgrade] new version liborlite-perl (1.48)
Added:
branches/upstream/liborlite-perl/current/t/20_shim.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/08_prune.pl
branches/upstream/liborlite-perl/current/t/17_cache.t
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=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/Changes (original)
+++ branches/upstream/liborlite-perl/current/Changes Fri Jan 21 10:03:12 2011
@@ -1,4 +1,7 @@
Changes for Perl extension ORLite
+
+1.48 Fri 21 Jan 2011
+ - Initial support for shim => 1 to simplify customisation (ADAMK)
1.47 Wed 8 Dec 2010
- Adding readonly support for views (ADAMK)
Modified: branches/upstream/liborlite-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/MANIFEST?rev=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/MANIFEST (original)
+++ branches/upstream/liborlite-perl/current/MANIFEST Fri Jan 21 10:03:12 2011
@@ -42,6 +42,7 @@
t/18_update.t
t/19_view.sql
t/19_view.t
+t/20_shim.t
t/lib/Test.pm
xt/meta.t
xt/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=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/META.yml (original)
+++ branches/upstream/liborlite-perl/current/META.yml Fri Jan 21 10:03:12 2011
@@ -35,4 +35,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.47
+version: 1.48
Modified: branches/upstream/liborlite-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/README?rev=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/README (original)
+++ branches/upstream/liborlite-perl/current/README Fri Jan 21 10:03:12 2011
@@ -235,7 +235,7 @@
of generating it each time from scratch.
cleanup
- When working with embedded SQLite database containing rapidly changing
+ When working with embedded SQLite databases containing rapidly changing
state data, it is important for database performance and general health
to make sure you VACUUM or ANALYZE the database regularly.
@@ -260,6 +260,35 @@
cleanup operation will be made pointless when "prune" deletes the file.
By default, the "prune" option is set to false.
+
+ shim
+ In some situtations you may wish to make extensive changes to the
+ behaviour of the classes and methods generated by ORLite. Under normal
+ circumstances all code is generated into the table class directly, which
+ can make overriding method difficult.
+
+ The "shim" option will make ORLite generate all of it's methods into a
+ seperate "Foo::TableName::Shim" class, and leave the main table class
+ "Foo::TableName" as a transparent subclass of the shim.
+
+ This allows you to alter the behaviour of a table class without having
+ to do nasty tricks with symbol tables in order to alter or replace
+ methods.
+
+ package My::Person;
+
+ # Write a log message when we create a new object
+ sub create {
+ my $class = shift;
+ my $self = SUPER::create(@_);
+ my $name = $self->name;
+ print LOG "Created new person '$name'\n";
+ return $self;
+ }
+
+ The "shim" option is global. It will alter the structure of all table
+ classes at once. However, unless you are making alterations to a class
+ the impact of this different class structure should be zero.
ROOT PACKAGE METHODS
All ORLite root packages receive an identical set of methods for
@@ -775,10 +804,10 @@
Adam Kennedy <adamk at cpan.org>
SEE ALSO
- ORLite::Mirror, ORLite::Migrate
+ ORLite::Mirror, ORLite::Migrate, ORLite::Pod
COPYRIGHT
- Copyright 2008 - 2010 Adam Kennedy.
+ Copyright 2008 - 2011 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=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/lib/ORLite.pm (original)
+++ branches/upstream/liborlite-perl/current/lib/ORLite.pm Fri Jan 21 10:03:12 2011
@@ -14,7 +14,7 @@
use vars qw{$VERSION};
BEGIN {
- $VERSION = '1.47';
+ $VERSION = '1.48';
}
# Support for the 'prune' option
@@ -45,17 +45,25 @@
}
# Check params and apply defaults
- my %params = ();
+ my %params = (
+ # Simple defaults here, complex defaults later
+ package => scalar(caller),
+ create => 0,
+ cleanup => '',
+ array => 0,
+ xsaccessor => 0,
+ shim => 0,
+ tables => 1,
+ views => 0,
+ x_update => 0,
+ );
if ( defined Params::Util::_STRING($_[1]) ) {
# Support the short form "use ORLite 'db.sqlite'"
- %params = ( file => $_[1] );
+ $params{file} = $_[1];
} elsif ( Params::Util::_HASHLIKE($_[1]) ) {
- %params = %{ $_[1] };
+ %params = ( %params, %{$_[1]} );
} else {
Carp::croak("Missing, empty or invalid params HASH");
- }
- unless ( defined $params{create} ) {
- $params{create} = 0;
}
unless (
defined Params::Util::_STRING($params{file})
@@ -69,27 +77,6 @@
}
unless ( defined $params{readonly} ) {
$params{readonly} = $params{create} ? 0 : ! -w $params{file};
- }
- unless ( defined $params{cleanup} ) {
- $params{cleanup} = '';
- }
- unless ( defined $params{array} ) {
- $params{array} = 0;
- }
- unless ( defined $params{xsaccessor} ) {
- $params{xsaccessor} = 0;
- }
- unless ( defined $params{tables} ) {
- $params{tables} = 1;
- }
- unless ( defined $params{views} ) {
- $params{views} = 0;
- }
- unless ( defined $params{x_update} ) {
- $params{x_update} = 0;
- }
- unless ( defined $params{package} ) {
- $params{package} = scalar caller;
}
unless ( Params::Util::_CLASS($params{package}) ) {
Carp::croak("Missing or invalid package class");
@@ -470,10 +457,27 @@
? '{}'
: '{ Slice => {} }';
- # Generate the elements in all packages
+ # Generate the package header
+ if ( $params{shim} ) {
+ # Generate a shim-wrapper class
+ $code .= <<"END_PERL";
+package $table->{class};
+
+\@$table->{class}::ISA = '$table->{class}::Shim';
+
+package $table->{class}::Shim;
+
+END_PERL
+ } else {
+ # Plain vanilla package header
+ $code .= <<"END_PERL";
+package $table->{class};
+
+END_PERL
+ }
+
+ # Generate the common elements for all classes
$code .= <<"END_PERL";
-package $table->{class};
-
sub base { '$pkg' }
sub table { '$table->{name}' }
@@ -1030,7 +1034,7 @@
=head2 cleanup
-When working with embedded SQLite database containing rapidly changing
+When working with embedded SQLite databases containing rapidly changing
state data, it is important for database performance and general health
to make sure you VACUUM or ANALYZE the database regularly.
@@ -1056,6 +1060,35 @@
cleanup operation will be made pointless when C<prune> deletes the file.
By default, the C<prune> option is set to false.
+
+=head2 shim
+
+In some situtations you may wish to make extensive changes to the behaviour
+of the classes and methods generated by ORLite. Under normal circumstances
+all code is generated into the table class directly, which can make
+overriding method difficult.
+
+The C<shim> option will make ORLite generate all of it's methods into a
+seperate C<Foo::TableName::Shim> class, and leave the main table class
+C<Foo::TableName> as a transparent subclass of the shim.
+
+This allows you to alter the behaviour of a table class without having
+to do nasty tricks with symbol tables in order to alter or replace methods.
+
+ package My::Person;
+
+ # Write a log message when we create a new object
+ sub create {
+ my $class = shift;
+ my $self = SUPER::create(@_);
+ my $name = $self->name;
+ print LOG "Created new person '$name'\n";
+ return $self;
+ }
+
+The C<shim> option is global. It will alter the structure of all table
+classes at once. However, unless you are making alterations to a class
+the impact of this different class structure should be zero.
=head1 ROOT PACKAGE METHODS
@@ -1602,11 +1635,11 @@
=head1 SEE ALSO
-L<ORLite::Mirror>, L<ORLite::Migrate>
+L<ORLite::Mirror>, L<ORLite::Migrate>, L<ORLite::Pod>
=head1 COPYRIGHT
-Copyright 2008 - 2010 Adam Kennedy.
+Copyright 2008 - 2011 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/08_prune.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/08_prune.pl?rev=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/08_prune.pl (original)
+++ branches/upstream/liborlite-perl/current/t/08_prune.pl Fri Jan 21 10:03:12 2011
@@ -4,7 +4,7 @@
use strict;
-our $VERSION = '1.47';
+our $VERSION = '1.48';
unless ( $ORLite::VERSION eq $VERSION ) {
die('Failed to load correct ORLite version');
Modified: branches/upstream/liborlite-perl/current/t/17_cache.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/17_cache.t?rev=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/17_cache.t (original)
+++ branches/upstream/liborlite-perl/current/t/17_cache.t Fri Jan 21 10:03:12 2011
@@ -14,7 +14,7 @@
use t::lib::Test;
# Where will the cache file be written to
-my $cached = catfile( qw{ t Foo-Bar-1-23-ORLite-1-47-user_version-2.pm } );
+my $cached = catfile( qw{ t Foo-Bar-1-23-ORLite-1-48-user_version-2.pm } );
clear($cached);
ok( ! -e $cached, 'Cache file does not initially exist' );
Added: branches/upstream/liborlite-perl/current/t/20_shim.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liborlite-perl/current/t/20_shim.t?rev=67591&op=file
==============================================================================
--- branches/upstream/liborlite-perl/current/t/20_shim.t (added)
+++ branches/upstream/liborlite-perl/current/t/20_shim.t Fri Jan 21 10:03:12 2011
@@ -1,0 +1,99 @@
+#!/usr/bin/perl
+
+# Test that the shim => 1 option works
+
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use Test::More tests => 12;
+use File::Spec::Functions ':ALL';
+use t::lib::Test;
+
+
+
+
+
+#####################################################################
+# Set up for testing
+
+# Connect
+my $file = test_db();
+my $dbh = create_ok(
+ file => catfile(qw{ t 02_basics.sql }),
+ connect => [ "dbi:SQLite:$file" ],
+);
+
+# Create the test package
+eval <<"END_PERL"; die $@ if $@;
+package Foo::Bar;
+
+use strict;
+use ORLite {
+ file => '$file',
+ shim => 1,
+};
+
+1;
+END_PERL
+
+CLASS: {
+ package Foo::Bar::TableOne;
+
+ use vars qw{$INCREMENT};
+ BEGIN {
+ $INCREMENT = 0;
+ }
+
+ # Overload new to increment the counter
+ sub new {
+ my $self = shift->SUPER::new(@_);
+ $INCREMENT++;
+ return $self;
+ }
+
+ 1;
+}
+
+is( $Foo::Bar::TableOne::INCREMENT, 0, '->new calls = 0' );
+
+
+
+
+
+#####################################################################
+# Tests for the base package update methods
+
+isa_ok(
+ Foo::Bar::TableOne->create(
+ col1 => 1,
+ col2 => 'foo',
+ ),
+ 'Foo::Bar::TableOne',
+);
+is( $Foo::Bar::TableOne::INCREMENT, 1, '->new calls = 1' );
+
+isa_ok(
+ Foo::Bar::TableOne->create(
+ col1 => 2,
+ col2 => 'bar',
+ ),
+ 'Foo::Bar::TableOne',
+);
+is( Foo::Bar::TableOne->count, 2, 'Found 2 rows' );
+is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 2' );
+
+is(
+ Foo::Bar::TableOne->count,
+ 2,
+ 'Count found 2 rows',
+);
+is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 2' );
+
+SCOPE: {
+ my $object = Foo::Bar::TableOne->load(1);
+ isa_ok( $object, 'Foo::Bar::TableOne' );
+ isa_ok( $object, 'Foo::Bar::TableOne::Shim' );
+ is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 3' );
+}
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=67591&op=diff
==============================================================================
--- branches/upstream/liborlite-perl/current/t/lib/Test.pm (original)
+++ branches/upstream/liborlite-perl/current/t/lib/Test.pm Fri Jan 21 10:03:12 2011
@@ -9,7 +9,7 @@
use vars qw{$VERSION @ISA @EXPORT};
BEGIN {
- $VERSION = '1.47';
+ $VERSION = '1.48';
@ISA = 'Exporter';
@EXPORT = qw{ test_db connect_ok create_ok };
}
More information about the Pkg-perl-cvs-commits
mailing list