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 {
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);
}
}
}
- $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 || {} };
#}
$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},
$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);
}
}
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 ) ],
ATTRIBUTE_DEFAULTS: {
my %attribute_defaults = (
- label => undef,
+ label => 'Id',
description => undef,
allowed_values => [],
callbacks => [],
my %error = (
rule => 'rule_name',
- message => 'customer_id rule message',
+ message => 'Customer Id rule message',
);
my ($error) = $obj->validation_error( rule_name => 'rule message' );
);
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