[Jifty-commit] jifty-dbi branch, computed-columns, updated. 0.60-13-ga41aa36
Jifty commits
jifty-commit at lists.jifty.org
Wed May 19 03:46:31 EDT 2010
The branch, computed-columns has been updated
via a41aa36a2f316750d8e0c8c60a4c25daf9ed911f (commit)
via d83ce162f1ce76389a2743876fa2f1a2d1f823eb (commit)
via 497634e5233ed7ca328be4a6424de06fa35e87bf (commit)
from c574d7d9288429787a598f2f09eba6a377ed72f4 (commit)
Summary of changes:
lib/Jifty/DBI/Record.pm | 9 +++++++--
t/11schema_records.t | 14 +++++++++-----
t/testmodels.pl | 5 +++++
3 files changed, 21 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 497634e5233ed7ca328be4a6424de06fa35e87bf
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Wed May 19 16:45:04 2010 +0900
Computed columns need a method (that's the whole point)
I originally tried to throw the error immediately at compile-time, but by
that point the actual computed method will likely not have been
defined, since people write methods after the schema. So as a
compromise, the error is thrown later, when the accessor is finally called
diff --git a/lib/Jifty/DBI/Record.pm b/lib/Jifty/DBI/Record.pm
index 6fc24cd..4ab68cd 100755
--- a/lib/Jifty/DBI/Record.pm
+++ b/lib/Jifty/DBI/Record.pm
@@ -272,10 +272,15 @@ sub _init_methods_for_column {
no strict 'refs'; # We're going to be defining subs
if ( not $self->can($column_name) ) {
-
# Accessor
my $subref;
- if ( $column->active ) {
+
+ if ($column->computed) {
+ $subref = sub {
+ Carp::croak("column '$column_name' in $package is computed but has no corresponding method");
+ };
+ }
+ elsif ( $column->active ) {
if ( $column->readable ) {
if (UNIVERSAL::isa(
commit d83ce162f1ce76389a2743876fa2f1a2d1f823eb
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Wed May 19 16:46:33 2010 +0900
Tests for pid
diff --git a/t/11schema_records.t b/t/11schema_records.t
index 29d574f..803fc61 100644
--- a/t/11schema_records.t
+++ b/t/11schema_records.t
@@ -9,7 +9,7 @@ use Test::More;
BEGIN { require "t/utils.pl" }
our (@available_drivers);
-use constant TESTS_PER_DRIVER => 67;
+use constant TESTS_PER_DRIVER => 68;
my $total = scalar(@available_drivers) * TESTS_PER_DRIVER;
plan tests => $total;
@@ -35,7 +35,8 @@ SKIP: {
ok($e_id, "Got an id for the new employee: $e_id");
$emp->load($e_id);
is($emp->id, $e_id);
-
+ is($emp->pid, $$);
+
my $phone_collection = $emp->phones;
isa_ok($phone_collection, 'TestApp::PhoneCollection');
@@ -265,9 +266,12 @@ use base qw/Jifty::DBI::Record/;
BEGIN {
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
- column name => type is 'varchar';
- column phones => references TestApp::PhoneCollection by 'employee';
- }
+ column name => type is 'varchar';
+ column phones => references TestApp::PhoneCollection by 'employee';
+ column pid => is computed;
+ };
+
+ sub pid { $$ }
}
sub _value {
commit a41aa36a2f316750d8e0c8c60a4c25daf9ed911f
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Wed May 19 16:46:49 2010 +0900
Add an age method to Sample::Employee just to have something there
diff --git a/t/testmodels.pl b/t/testmodels.pl
index 02f7082..10ea549 100644
--- a/t/testmodels.pl
+++ b/t/testmodels.pl
@@ -12,6 +12,11 @@ column age => is computed;
};
+sub age {
+ my $self = shift;
+ return $self->dexterity * 2;
+}
+
sub schema_sqlite {
return q{
CREATE TABLE employees (
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list