Changed PK to use class methods for accessing the list of primary keys, instead of direct hash access
sub _ident_cond {
my ($class) = @_;
- return join(" AND ", map { "$_ = ?" } keys %{$class->_primaries});
+ return join " AND ", map { "$_ = ?" } $class->primary_columns;
}
sub _ident_values {
my ($self) = @_;
- return (map { $self->{_column_data}{$_} } keys %{$self->_primaries});
+ return map { $self->{_column_data}{$_} } $self->primary_columns;
}
sub set_primary_key {
my ($class, @cols) = @_;
- my %pri;
- tie %pri, 'Tie::IxHash';
- %pri = map { $_ => {} } @cols;
+ $class->add_columns(@cols);
+ tie my %pri, 'Tie::IxHash', map { $_ => {} } @cols;
$class->_primaries(\%pri);
}
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 find unless primary columns are defined" )
- unless @pk;
+ unless my @pk = $class->primary_columns;
my $query;
if (ref $vals[0] eq 'HASH') {
$query = $vals[0];
foreach my $name (@cols) {
$class->set_field_column_name($name => $name);
$class->_columns->{$name}{field} = $class->get_field($name);
- }
+ }
}
sub _mk_column_accessors {
return;
}
+
+ sub _add_types_to_field : method {
+ my ( $class, $field_name, @type_names ) = @_;
+
+ my $field = $class->get_field($field_name);
+ my $field_class = ref $field;
+
+ no strict 'refs';
+ push @{"${field_class}::ISA"},
+ grep { !$field->isa($_) }
+ map { "DBIx::Class::Field::Type::$_" }
+ @type_names;
+ }
}
1;
sub set_field_column_name : method {
my ( $class, $field_name, $column_name ) = @_;
- $class->_add_column_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'column');
return shift->get_field($field_name)->set_column_name($column_name);
}
-
- sub _add_column_type_to_field : PRIVATE method {
- my ( $class, $field_name, $opt ) = @_;
-
- my $field = $class->get_field($field_name);
- my $field_class = ref $field;
-
- no strict 'refs';
- push @{"${field_class}::ISA"},
- grep { !$field->isa($_) }
- qw( DBIx::Class::Field::Type::column );
-
- return;
- }
}
1;
sub validates_numericality_of : method {
my ( $class, $field_name, $opt ) = @_;
- my $field = $class->get_field($field_name);
- my $field_class = ref $field;
-
- no strict 'refs';
- push @{"${field_class}::ISA"},
- grep { !$field->isa($_) }
- qw( DBIx::Class::Field::Type::number );
+ $class->_add_types_to_field($field_name => 'number');
# TODO: set up trigger points based on the $opt passed in. Want
# to be able to validate during different DBIx::Class
sub validates_roles_of : method {
my ( $class, $field_name, $roles, $opt ) = @_;
- $class->_add_object_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'object');
$class->get_field($field_name)->set_roles($roles);
sub validates_classes_of : method {
my ( $class, $field_name, $classes, $opt ) = @_;
- $class->_add_object_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'object');
$class->get_field($field_name)->set_classes($classes);
return;
}
-
- sub _add_object_type_to_field : PRIVATE method {
- my ( $class, $field_name, $opt ) = @_;
-
- my $field = $class->get_field($field_name);
- my $field_class = ref $field;
-
- no strict 'refs';
- push @{"${field_class}::ISA"},
- grep { !$field->isa($_) }
- qw( DBIx::Class::Field::Type::object );
-
- return;
- }
}
1;
sub validates_length_of : method {
my ( $class, $field_name, $opt ) = @_;
- $class->_add_string_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'string');
my $field = $class->get_field($field_name);
sub validates_allowed_chars_of : method {
my ( $class, $field_name, $allowed_chars, $opt ) = @_;
- $class->_add_string_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'string');
$class->get_field($field_name)
->set_allowed_chars($allowed_chars);
sub validates_disallowed_chars_of : method {
my ( $class, $field_name, $disallowed_chars, $opt ) = @_;
- $class->_add_string_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'string');
$class->get_field($field_name)
->set_disallowed_chars($disallowed_chars);
sub validates_format_of : method {
my ( $class, $field_name, $format, $opt ) = @_;
- $class->_add_string_type_to_field($field_name);
+ $class->_add_types_to_field($field_name => 'string');
$class->get_field($field_name)
->set_format($format);
return;
}
-
- sub _add_string_type_to_field : PRIVATE method {
- my ( $class, $field_name, $opt ) = @_;
-
- my $field = $class->get_field($field_name);
- my $field_class = ref $field;
-
- no strict 'refs';
- push @{"${field_class}::ISA"},
- grep { !$field->isa($_) }
- qw( DBIx::Class::Field::Type::string );
-
- return;
- }
}
1;