sub mk_group_accessors {
my ($class, $group, @cols) = @_;
- unless ($class->can('accessor_name') || $class->can('mutator_name')) {
- return $class->NEXT::ACTUAL::mk_group_accessors($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";
if ($ro_meth eq $wo_meth) {
$class->NEXT::ACTUAL::mk_group_accessors($group => [ $ro_meth => $col ]);
$attrs = { %$attrs };
my %att;
foreach my $col (keys %{ $class->_columns }) {
- if ($class->can('accessor_name')) {
- my $acc = $class->accessor_name($col);
-#warn "$col $acc";
- $att{$col} = delete $attrs->{$acc} if exists $attrs->{$acc};
- }
- if ($class->can('mutator_name')) {
- my $mut = $class->mutator_name($col);
- $att{$col} = delete $attrs->{$mut} if exists $attrs->{$mut};
- }
+ 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};
}
return $class->NEXT::ACTUAL::create({ %$attrs, %att }, @rest);
}
use Class::Std;
{
my %name_of : ATTR( :init_arg<name> :get<name> );
- my %label_of : ATTR( :init_arg<label> :get<label> :set<label> :default<undef> );
+ my %accessor_name_of : ATTR( :init_arg<accessor_name> :get<accessor_name> :set<accessor_name> );
+ my %mutator_name_of : ATTR( :init_arg<mutator_name> :get<mutator_name> :set<mutator_name> );
+ my %label_of : ATTR( :init_arg<label> :get<label> :set<label> );
my %description_of : ATTR( :init_arg<description> :get<description> :set<description> :default<undef> );
my %allowed_values_of : ATTR( :init_arg<allowed_values> :get<allowed_values> :set<allowed_values> :default<[]> );
my %disallowed_values_of : ATTR( :init_arg<disallowed_values> :get<disallowed_values> :set<disallowed_values> :default<[]> );
my %is_required : ATTR( :init_arg<is_required> :get<is_required> :set<is_required> :default<0> );
my %default_of : ATTR( :init_arg<default> :get<default> :set<default> :default<undef> );
+ sub BUILD : method {
+ my ( $self, $ident, $arg_ref ) = @_;
+
+ $accessor_name_of{$ident} = $arg_ref->{accessor_name}
+ || $arg_ref->{name};
+
+ $mutator_name_of{$ident} = $arg_ref->{mutator_name}
+ || $arg_ref->{name};
+
+ if(!defined $self->get_label) {
+ $self->set_label(
+ join ' ',
+ map { ucfirst(lc $_) }
+ split '_',
+ $arg_ref->{name},
+ );
+ }
+
+ return;
+ }
+
sub validate : CUMULATIVE method {
shift->_validate(
shift,