From: Dan Kubb Date: Sat, 6 Aug 2005 22:04:34 +0000 (+0000) Subject: Renamed DBIx::Class::PK's retrieve() as find() X-Git-Tag: v0.03001~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=656796f2088da66cc80f4eb127c39c923ef3c1dd;p=dbsrgits%2FDBIx-Class.git Renamed DBIx::Class::PK's retrieve() as find() Renamed DBIx::Class::Table's retrieve_from_sql() as search_literal() Renamed DBIx::Class::Table's count_from_sql() as count_literal() Removed DBIx::Class::Table->retrieve_all() Added DBIx::Class::CDBICompat::Retrieve to account for method renaming Updated affected test cases --- diff --git a/lib/DBIx/Class/CDBICompat.pm b/lib/DBIx/Class/CDBICompat.pm index 60857f6..c7f4c46 100644 --- a/lib/DBIx/Class/CDBICompat.pm +++ b/lib/DBIx/Class/CDBICompat.pm @@ -22,6 +22,7 @@ __PACKAGE__->load_components(qw/ CDBICompat::LazyLoading CDBICompat::AutoUpdate CDBICompat::TempColumns + CDBICompat::Retrieve CDBICompat::ColumnGroups CDBICompat::ImaDBI/); diff --git a/lib/DBIx/Class/CDBICompat/Constructor.pm b/lib/DBIx/Class/CDBICompat/Constructor.pm index 2b4b1e9..6983733 100644 --- a/lib/DBIx/Class/CDBICompat/Constructor.pm +++ b/lib/DBIx/Class/CDBICompat/Constructor.pm @@ -10,7 +10,7 @@ sub add_constructor { *{"${class}::${meth}"} = sub { my ($class, @args) = @_; - return $class->retrieve_from_sql($sql, @args); + return $class->search_literal($sql, @args); }; } diff --git a/lib/DBIx/Class/CDBICompat/Retrieve.pm b/lib/DBIx/Class/CDBICompat/Retrieve.pm new file mode 100644 index 0000000..b7fca68 --- /dev/null +++ b/lib/DBIx/Class/CDBICompat/Retrieve.pm @@ -0,0 +1,10 @@ +package DBIx::Class::CDBICompat::Retrieve; + +use strict; +use warnings FATAL => 'all'; + +sub retrieve { shift->find(@_) } +sub retrieve_all { shift->search_literal('1') } +sub retrieve_from_sql { shift->search_literal(@_) } + +1; diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index bcd545d..e420ac6 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -44,23 +44,23 @@ sub set_primary_key { $class->_primaries(\%pri); } -sub retrieve { +sub find { my ($class, @vals) = @_; my $attrs = (@vals > 1 && ref $vals[$#vals] eq 'HASH' ? pop(@vals) : {}); my @pk = keys %{$class->_primaries}; - $class->throw( "Can't retrieve unless primary columns are defined" ) + $class->throw( "Can't find unless primary columns are defined" ) unless @pk; my $query; if (ref $vals[0] eq 'HASH') { $query = $vals[0]; } elsif (@pk == @vals) { - my $ret = ($class->retrieve_from_sql($class->_ident_cond, @vals, $attrs))[0]; + my $ret = ($class->search_literal($class->_ident_cond, @vals, $attrs))[0]; #warn "$class: ".join(', ', %{$ret->{_column_data}}); return $ret; } else { $query = {@vals}; } - $class->throw( "Can't retrieve unless all primary keys are specified" ) + $class->throw( "Can't find unless all primary keys are specified" ) unless (keys %$query >= @pk); # If we check 'em we run afoul of uc/lc # column names etc. Not sure what to do yet my $ret = ($class->search($query))[0]; @@ -72,7 +72,7 @@ sub discard_changes { my ($self) = @_; delete $self->{_dirty_columns}; return unless $self->in_database; # Don't reload if we aren't real! - my ($reload) = $self->retrieve($self->id); + my ($reload) = $self->find($self->id); unless ($reload) { # If we got deleted in the mean-time $self->in_database(0); return $self; diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 109edf2..14741b0 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -104,18 +104,18 @@ sub _cond_value { sub search_related { my $self = shift; - return $self->_from_sql_related('retrieve', @_); + return $self->_literal_related('search', @_); } sub count_related { my $self = shift; - return $self->_from_sql_related('count', @_); + return $self->_literal_related('count', @_); } -sub _from_sql_related { +sub _literal_related { my $self = shift; my $op = shift; - my $meth = "${op}_from_sql"; + my $meth = "${op}_literal"; my $rel = shift; my $attrs = { }; if (@_ > 1 && ref $_[$#_] eq 'HASH') { diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 72928fc..3a08e5c 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -39,7 +39,7 @@ DBIx::Class::Schema - composable schemas then in app code - my @obj = My::DB::Foo->retrieve_all; # My::DB::Foo isa My::Schema::Foo My::DB + my @obj = My::DB::Foo->search({}); # My::DB::Foo isa My::Schema::Foo My::DB =head1 DESCRIPTION diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index d3c737f..144826f 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -248,14 +248,14 @@ sub add_columns { $class->_mk_column_accessors(@cols); } -=item retrieve_from_sql +=item search_literal - my @obj = $class->retrieve_from_sql($sql_where_cond, @bind); - my $cursor = $class->retrieve_from_sql($sql_where_cond, @bind); + my @obj = $class->search_literal($literal_where_cond, @bind); + my $cursor = $class->search_literal($literal_where_cond, @bind); =cut -sub retrieve_from_sql { +sub search_literal { my ($class, $cond, @vals) = @_; $cond =~ s/^\s*WHERE//i; my $attrs = (ref $vals[$#vals] eq 'HASH' ? { %{ pop(@vals) } } : {}); @@ -263,13 +263,13 @@ sub retrieve_from_sql { return $class->search(\$cond, $attrs); } -=item count_from_sql +=item count_literal - my $count = $class->count($sql_where_cond); + my $count = $class->count_literal($literal_where_cond); =cut -sub count_from_sql { +sub count_literal { my ($class, $cond, @vals) = @_; $cond =~ s/^\s*WHERE//i; my $attrs = (ref $vals[$#vals] eq 'HASH' ? pop(@vals) : {}); @@ -417,17 +417,6 @@ sub insert_or_update { return ($self->in_database ? $self->update : $self->insert); } -=item retrieve_all - - my @all = $class->retrieve_all; - -=cut - -sub retrieve_all { - my ($class) = @_; - return $class->retrieve_from_sql( '1' ); -} - =item is_changed my @changed_col_names = $obj->is_changed diff --git a/t/01core.t b/t/01core.t index 20090c0..3e95f08 100644 --- a/t/01core.t +++ b/t/01core.t @@ -70,7 +70,7 @@ $new->name('Man With A Spoon'); $new->update; -$new_again = DBICTest::Artist->retrieve(4); +$new_again = DBICTest::Artist->find(4); is($new_again->name, 'Man With A Spoon', 'Retrieved correctly'); @@ -89,4 +89,4 @@ ok($new->in_database, 'insert_or_update insert ok'); # test in update mode $new->position(5); $new->insert_or_update; -is( DBICTest::Track->retrieve(100)->position, 5, 'insert_or_update update ok'); +is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok'); diff --git a/t/04db.t b/t/04db.t index 98a2a89..3ab26b7 100644 --- a/t/04db.t +++ b/t/04db.t @@ -16,7 +16,7 @@ for (10..15) { } ); } DBICTest::Artist->dbi_commit; -my ($artist) = DBICTest::Artist->retrieve(15); +my ($artist) = DBICTest::Artist->find(15); is($artist->name, 'artist number 15', "Commit ok"); # repeat the test using AutoCommit = 1 to force the commit @@ -28,7 +28,7 @@ for (16..20) { } ); } DBICTest::Artist->storage->dbh->{AutoCommit} = 1; -($artist) = DBICTest::Artist->retrieve(20); +($artist) = DBICTest::Artist->find(20); is($artist->name, 'artist number 20', "Commit using AutoCommit ok"); # add some rows inside a transaction and roll it back diff --git a/t/05multipk.t b/t/05multipk.t index 6aff06f..e4d364a 100644 --- a/t/05multipk.t +++ b/t/05multipk.t @@ -6,5 +6,5 @@ use lib qw(t/lib); use_ok('DBICTest'); -ok(DBICTest::FourKeys->retrieve(1,2,3,4), "retrieve multiple pks without hash"); -ok(DBICTest::FourKeys->retrieve(5,4,3,6), "retrieve multiple pks without hash"); \ No newline at end of file +ok(DBICTest::FourKeys->find(1,2,3,4), "find multiple pks without hash"); +ok(DBICTest::FourKeys->find(5,4,3,6), "find multiple pks without hash"); diff --git a/t/06relationship.t b/t/06relationship.t index ea74a3a..7c4984e 100644 --- a/t/06relationship.t +++ b/t/06relationship.t @@ -7,12 +7,12 @@ use lib qw(t/lib); use_ok('DBICTest'); # has_a test -my $cd = DBICTest::CD->retrieve(4); +my $cd = DBICTest::CD->find(4); my ($artist) = $cd->search_related('artist'); is($artist->name, 'Random Boy Band', 'has_a search_related ok'); # has_many test with an order_by clause defined -$artist = DBICTest::Artist->retrieve(1); +$artist = DBICTest::Artist->find(1); is( ($artist->search_related('cds'))[1]->title, 'Spoonful of bees', 'has_many search_related with order_by ok' ); # search_related with additional abstract query diff --git a/t/08inflate.t b/t/08inflate.t index 4a98949..3ecba70 100644 --- a/t/08inflate.t +++ b/t/08inflate.t @@ -15,7 +15,7 @@ DBICTest::CD->inflate_column( 'year', ); # inflation test -my $cd = DBICTest::CD->retrieve(3); +my $cd = DBICTest::CD->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); diff --git a/t/08inflate_has_a.t b/t/08inflate_has_a.t index 6f59161..c621eed 100644 --- a/t/08inflate_has_a.t +++ b/t/08inflate_has_a.t @@ -19,7 +19,7 @@ DBICTest::CD->has_a( 'year', 'DateTime', ); # inflation test -my $cd = DBICTest::CD->retrieve(3); +my $cd = DBICTest::CD->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); @@ -40,7 +40,7 @@ DBICTest::CD->has_a( 'year', 'DateTime', ); # inflation test -$cd = DBICTest::CD->retrieve(3); +$cd = DBICTest::CD->find(3); is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' ); diff --git a/t/09update.t b/t/09update.t index ec90358..3b4dbe4 100644 --- a/t/09update.t +++ b/t/09update.t @@ -10,7 +10,7 @@ use lib qw(t/lib); use_ok('DBICTest'); -my $art = DBICTest::Artist->retrieve(1); +my $art = DBICTest::Artist->find(1); isa_ok $art => 'DBICTest::Artist'; diff --git a/t/cdbi-t/01-columns.t b/t/cdbi-t/01-columns.t index 3380f52..2bc8573 100644 --- a/t/cdbi-t/01-columns.t +++ b/t/cdbi-t/01-columns.t @@ -106,11 +106,11 @@ ok(!State->find_column('HGLAGAGlAG'), '!find_column HGLAGAGlAG'); { package DieTest; @DieTest::ISA = qw(DBIx::Class); - DieTest->load_components(qw/Core/); + DieTest->load_components(qw/CDBICompat::Retrieve Core/); package main; local $SIG{__WARN__} = sub { }; eval { DieTest->retrieve(1) }; - like $@, qr/Can't retrieve unless primary columns are defined/, "Need primary key for retrieve"; + like $@, qr/unless primary columns are defined/, "Need primary key for retrieve"; } #-----------------------------------------------------------------------