From: Matt S Trout Date: Sat, 28 Jan 2006 17:03:31 +0000 (+0000) Subject: Added accessor => option to column_info to specify accessor name X-Git-Tag: v0.05005~82 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=91b0fbd7fb0a83c83ef2f11a6dd2119d42199a68;p=dbsrgits%2FDBIx-Class.git Added accessor => option to column_info to specify accessor name --- diff --git a/Build.PL b/Build.PL index 3b06ba2..63b9693 100644 --- a/Build.PL +++ b/Build.PL @@ -13,14 +13,13 @@ my %arguments = ( 'SQL::Abstract::Limit' => 0.101, 'DBD::SQLite' => 1.08, 'Class::C3' => 0.07, - 'Tie::IxHash' => 0, - 'Module::Find' => 0, 'Storable' => 0, 'Class::Data::Accessor' => 0.01, 'Carp::Clan' => 0, }, recommends => { 'Data::UUID' => 0, + 'Module::Find' => 0, }, create_makefile_pl => 'passthrough', create_readme => 1, diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index ad406ca..c86aed3 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -2,7 +2,6 @@ package DBIx::Class::PK; use strict; use warnings; -use Tie::IxHash; use base qw/DBIx::Class::Row/; diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 8a4bfc9..54c0763 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -323,13 +323,20 @@ sub is_changed { =head2 register_column($column, $column_info) - Registers a column on the class and creates an accessor for it + Registers a column on the class. If the column_info has an 'accessor' key, + creates an accessor named after the value if defined; if there is no such + key, creates an accessor with the same name as the column =cut sub register_column { my ($class, $col, $info) = @_; - $class->mk_group_accessors('column' => $col); + my $acc = $col; + if (exists $info->{accessor}) { + return unless defined $info->{accessor}; + $acc = [ $info->{accessor}, $col ]; + } + $class->mk_group_accessors('column' => $acc); } diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index be0f273..3385a1d 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -13,6 +13,7 @@ DBICTest::Schema::Track->add_columns( }, 'position' => { data_type => 'integer', + accessor => 'pos', }, 'title' => { data_type => 'varchar', diff --git a/t/run/01core.tl b/t/run/01core.tl index 27868df..7e451ae 100644 --- a/t/run/01core.tl +++ b/t/run/01core.tl @@ -110,9 +110,9 @@ $new->insert_or_update; ok($new->in_storage, 'insert_or_update insert ok'); # test in update mode -$new->position(5); +$new->pos(5); $new->insert_or_update; -is( $schema->resultset("Track")->find(100)->position, 5, 'insert_or_update update ok'); +is( $schema->resultset("Track")->find(100)->pos, 5, 'insert_or_update update ok'); eval { $schema->class("Track")->load_components('DoesNotExist'); };