Data-Model
view release on metacpan or search on metacpan
lib/Data/Model/Schema/Properties.pm view on Meta::CPAN
$self->{$name}->{$index} = $key;
};
}
}
sub add_column {
my $self = shift;
my($column, $type, $options) = @_;
return $self->add_column_sugar(@_) if $column =~ /^[^\.+]+\.[^\.+]+$/;
Carp::croak "Column can't be called '$column': reserved name"
if grep { lc $_ eq lc $column } @RESERVED;
Carp::croak 'The multiplex definition of "require" and the "required" is carried out.'
if exists $options->{require} && exists $options->{required};
if (exists $options->{require}) {
$options->{required} = delete $options->{require};
}
# validation for $options
if ($Data::Model::RUN_VALIDATION) {
my @p = %{ $options };
validate(
@p, {
size => {
type => SCALAR,
regex => qr/\A[0-9]+\z/,
optional => 1,
},
required => {
type => BOOLEAN,
optional => 1,
},
null => {
type => BOOLEAN,
optional => 1,
},
signed => {
type => BOOLEAN,
optional => 1,
},
unsigned => {
type => BOOLEAN,
optional => 1,
},
decimals => {
type => BOOLEAN,
optional => 1,
},
zerofill => {
type => BOOLEAN,
optional => 1,
},
binary => {
type => BOOLEAN,
optional => 1,
},
ascii => {
type => BOOLEAN,
optional => 1,
},
unicode => {
type => BOOLEAN,
optional => 1,
},
default => {
type => SCALAR | CODEREF,
optional => 1,
},
# validation => {},
auto_increment => {
type => BOOLEAN,
optional => 1,
},
inflate => {
type => SCALAR | CODEREF,
optional => 1,
},
deflate => {
type => SCALAR | CODEREF,
optional => 1,
},
}
);
}
$self->{utf8_columns}->{$column} = 1
if delete $self->{_build_tmp}->{utf8_column}->{$column};
push @{ $self->{columns} }, $column;
$self->{column}->{$column} = +{
type => $type || 'char',
options => $options || +{},
};
}
sub add_utf8_column {
my $self = shift;
my($column) = @_;
$self->{_build_tmp}->{utf8_column} ||= {};
$self->{_build_tmp}->{utf8_column}->{$column} = 1;
$self->add_column(@_);
}
sub add_alias_column {
my $self = shift;
my($base_name, $alias_name, $args) = @_;
$self->{aluas_column_revers_map}->{$base_name} ||= [];
push @{ $self->{aluas_column_revers_map}->{$base_name} }, $alias_name;
$self->{alias_column}->{$alias_name} = +{
%{ $args || {} },
base => $base_name,
};
}
sub add_column_sugar {
my $self = shift;
my $name = shift;
my $sugar = Data::Model::Schema->get_column_sugar($self);
Carp::croak "Undefined column of '$name'"
unless exists $sugar->{$name} && $sugar->{$name};
( run in 1.336 second using v1.01-cache-2.11-cpan-e93a5daba3e )