From: Dan Kubb Date: Thu, 25 Aug 2005 08:34:20 +0000 (+0000) Subject: Continued integrating Fields into CDBICompat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e84f3c1064200358a006021c83484a78a9e054b;p=dbsrgits%2FDBIx-Class-Historic.git Continued integrating Fields into CDBICompat Corrected test cases in Fields after class behaviour changed slightly --- diff --git a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm index 11fd13a..d707e74 100644 --- a/lib/DBIx/Class/CDBICompat/AccessorMapping.pm +++ b/lib/DBIx/Class/CDBICompat/AccessorMapping.pm @@ -8,10 +8,17 @@ use NEXT; sub mk_group_accessors { my ($class, $group, @cols) = @_; foreach my $col (@cols) { + my $ro_meth = ($class->can('accessor_name') + ? $class->accessor_name($col) + : $col); + my $wo_meth = ($class->can('mutator_name') + ? $class->mutator_name($col) + : $col); + my $field = $class->get_field($col); - my $ro_meth = $field->get_accessor_name; - my $wo_meth = $field->get_mutator_name; - #warn "$col $ro_meth $wo_meth"; + $field->set_accessor_name($ro_meth); + $field->set_mutator_name($wo_meth); + if ($ro_meth eq $wo_meth) { $class->NEXT::ACTUAL::mk_group_accessors($group => [ $ro_meth => $col ]); } else { @@ -28,12 +35,16 @@ sub create { my %att; foreach my $col (keys %{ $class->_columns }) { my $field = $class->get_field($col); - - my $acc = $field->get_accessor_name; - $att{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; - - my $mut = $field->get_mutator_name; - $att{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; + if ($class->can('accessor_name')) { + my $acc = $class->accessor_name($col); + $field->set_accessor_name($acc); + $att{$col} = delete $attrs->{$acc} if exists $attrs->{$acc}; + } + if ($class->can('mutator_name')) { + my $mut = $class->mutator_name($col); + $field->set_mutator_name($mut); + $att{$col} = delete $attrs->{$mut} if exists $attrs->{$mut}; + } } return $class->NEXT::ACTUAL::create({ %$attrs, %att }, @rest); } diff --git a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm index 4c0b148..f8e1b1b 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm @@ -46,7 +46,22 @@ sub _register_column_group { } } - $groups->{$group}{$_} ||= {} for @cols; + foreach my $col (@cols) { + $groups->{$group}{$col} ||= {}; +# $class->set_field_column_name($col => $col); +# +# my $field = $class->get_field($col); +# +# if($class->can('accessor_name')) { +# $field->set_accessor_name($class->accessor_name($col)); +# } +# if($class->can('mutator_name')) { +# $field->set_mutator_name($class->mutator_name($col)); +# } +# +# $class->_columns->{$col}{field} = $field; + } + #if ($group eq 'Essential') { # $groups->{$group}{$_} ||= {} for keys %{ $class->_primaries || {} }; #} diff --git a/lib/DBIx/Class/Field.pm b/lib/DBIx/Class/Field.pm index fae55ae..f8b6ca5 100644 --- a/lib/DBIx/Class/Field.pm +++ b/lib/DBIx/Class/Field.pm @@ -37,9 +37,9 @@ use Class::Std; $mutator_name_of{$ident} = $arg_ref->{mutator_name} || $arg_ref->{name}; - if(!defined $self->get_label) { - $self->set_label( - join ' ', + if(!exists $arg_ref->{label}) { + $label_of{$ident} = join( + ' ', map { ucfirst(lc $_) } split '_', $arg_ref->{name}, diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index ddcb8d7..9ed225c 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -41,9 +41,9 @@ sub _register_columns { $names->{$_} ||= {} for @cols; $class->_columns($names); - foreach my $name (@cols) { - $class->set_field_column_name($name => $name); - $class->_columns->{$name}{field} = $class->get_field($name); + foreach my $col (@cols) { + $class->set_field_column_name($col => $col); + $class->_columns->{$col}{field} = $class->get_field($col); } } diff --git a/t/DBIx/Class/Field/Type/object/validate.t b/t/DBIx/Class/Field/Type/object/validate.t index 97803ba..6c5b320 100644 --- a/t/DBIx/Class/Field/Type/object/validate.t +++ b/t/DBIx/Class/Field/Type/object/validate.t @@ -43,7 +43,7 @@ BEGIN { my $class = __PACKAGE__; my %attributes = ( - name => 'off_road_vechicle', + name => 'off_road_vehicle', label => 'Off Road Vehicle', roles => [ qw( steer brake gas four_wheel_drive ) ], classes => [ qw( Vehicle Jeep ) ], diff --git a/t/DBIx/Class/Field/basic.t b/t/DBIx/Class/Field/basic.t index b1b676e..f806ea8 100644 --- a/t/DBIx/Class/Field/basic.t +++ b/t/DBIx/Class/Field/basic.t @@ -23,7 +23,7 @@ NEW: { ATTRIBUTE_DEFAULTS: { my %attribute_defaults = ( - label => undef, + label => 'Id', description => undef, allowed_values => [], callbacks => [], diff --git a/t/DBIx/Class/Field/validate.t b/t/DBIx/Class/Field/validate.t index 16b7061..4dde9bf 100644 --- a/t/DBIx/Class/Field/validate.t +++ b/t/DBIx/Class/Field/validate.t @@ -78,7 +78,7 @@ VALIDATION_ERROR_WITH_FIELD_NAME: { my %error = ( rule => 'rule_name', - message => 'customer_id rule message', + message => 'Customer Id rule message', ); my ($error) = $obj->validation_error( rule_name => 'rule message' ); diff --git a/t/DBIx/Class/Validation/basic.t b/t/DBIx/Class/Validation/basic.t index 60b4c93..d9d57fa 100644 --- a/t/DBIx/Class/Validation/basic.t +++ b/t/DBIx/Class/Validation/basic.t @@ -60,16 +60,18 @@ SET_FIELD_COMMON: { ); while ( my ( $attr, $value ) = each %attr ) { - my $mutator = "set_field_$attr"; + my $accessor = "get_$attr"; + my $mutator = "set_field_$attr"; + + my $old = $field->$accessor; can_ok $class, $mutator; is( $class->$mutator( $field_name => $value ), - undef, + $old, "set field $attr", ); - my $accessor = "get_$attr"; is $field->$accessor, $value, "get field $attr"; # returns the previous value on-set