Aniki

 view release on metacpan or  search on metacpan

lib/Aniki/Handler/WeightedRoundRobin.pm  view on Meta::CPAN

        # TODO: patches wellcome :p
    }

    warn "Unsupported dirver: $driver";
    return 0;
}

sub disconnect {
    my $self = shift;
    $self->_reset_connect_info();
    $self->SUPER::disconnect();
}

my %NO_OVERRIDE_PROXY_METHODS = (
    trace_query_set_comment => 1,
    in_txn                  => 1,
);

for my $name (grep { !$NO_OVERRIDE_PROXY_METHODS{$_} } __PACKAGE__->_proxy_methods) {
    # override
    __PACKAGE__->meta->add_method($name => sub {

lib/Aniki/QueryBuilder/Canonical.pm  view on Meta::CPAN


use parent qw/Aniki::QueryBuilder/;

sub insert {
    my ($self, $table, $values, $opt) = @_;
    if (ref $values eq 'HASH') {
        $values = [
            map { $_ => $values->{$_} } sort keys %$values
        ];
    }
    return $self->SUPER::insert($table, $values, $opt);
}

sub update {
    my ($self, $table, $args, $where) = @_;
    if (ref $args eq 'HASH') {
        $args = [
            map { $_ => $args->{$_} } sort keys %$args
        ];
    }
    if (ref $where eq 'HASH') {
        $where = [
            map { $_ => $where->{$_} } sort keys %$where
        ];
    }
    return $self->SUPER::update($table, $args, $where);
}

sub delete :method {
    my ($self, $table, $where, $opt) = @_;
    if (ref $where eq 'HASH') {
        $where = [
            map { $_ => $where->{$_} } sort keys %$where
        ];
    }
    return $self->SUPER::delete($table, $where, $opt);
}

sub select_query {
    my ($self, $table, $fields, $where, $opt) = @_;
    if (ref $where eq 'HASH') {
        $where = [
            map { $_ => $where->{$_} } sort keys %$where
        ];
    }
    return $self->SUPER::select_query($table, $fields, $where, $opt);
}

1;
__END__

lib/Aniki/Result/Collection/Joined.pm  view on Meta::CPAN

    my $self = shift;
    return map { $self->handler->guess_row_class($_) } @{ $self->table_names };
}

sub rows {
    my $self = shift;
    if (@_ == 1) {
        my $table_name = shift;
        return $self->subresult($table_name)->rows();
    }
    return $self->SUPER::rows();
}

sub subresult {
    my ($self, $table_name) = @_;
    return $self->_subresult_cache->{$table_name} if $self->_subresult_cache->{$table_name};

    my $result_class = $self->handler->guess_result_class($table_name);
    return $self->_subresult_cache->{$table_name} = $result_class->new(
        table_name           => $table_name,
        handler              => $self->handler,

lib/Aniki/Row.pm  view on Meta::CPAN


        my $relationships = $self->table->get_relationships;
        return $cache->{$column} = sub { shift->relay($column) } if $relationships && $relationships->get($column);
    }

    return undef; ## no critic
}

sub can {
    my ($invocant, $method) = @_;
    my $code = $invocant->SUPER::can($method);
    return $code if defined $code;
    return $invocant->_guess_accessor_method($method);
}

our $AUTOLOAD;
sub AUTOLOAD {
    my $invocant = shift;
    my $column = $AUTOLOAD =~ s/^.+://r;

    if (ref $invocant) {

lib/Aniki/Row/Joined.pm  view on Meta::CPAN

use Carp qw/croak/;

sub new {
    my ($class, @rows) = @_;
    my %rows = map { $_->table_name => $_ } @rows;
    return bless \%rows => $class;
}

sub can {
    my ($invocant, $method) = @_;
    my $code = $invocant->SUPER::can($method);
    return $code if defined $code;

    if (ref $invocant) {
        my $self       = $invocant;
        my $table_name = $method;
        return sub { shift->{$table_name} } if exists $self->{$table_name};
    }

    return undef; ## no critic
}

lib/Aniki/Schema/Table.pm  view on Meta::CPAN

    default => sub {
        my $self = shift;
        return {
            map { $_->name => $_ } @{ $self->_fields_cache }
        }
    },
);

sub BUILDARGS {
    my ($class, $table, $schema) = @_;
    return $class->SUPER::BUILDARGS(_table => $table, _schema => $schema);
}

sub get_fields { @{ shift->_fields_cache } }

sub field_names { wantarray ? @{ shift->_field_names } : [@{ shift->_field_names }] }

sub get_field {
    my ($self, $name) = @_;
    return unless exists $self->_fields_map_cache->{$name};
    return $self->_fields_map_cache->{$name}

lib/Aniki/Schema/Table/Field.pm  view on Meta::CPAN

    default => sub { shift->_field->default_value },
);

has sql_data_type => (
    is      => 'ro',
    default => sub { shift->_field->sql_data_type },
);

sub BUILDARGS {
    my ($class, $field) = @_;
    return $class->SUPER::BUILDARGS(_field => $field);
}

our $AUTOLOAD;
sub AUTOLOAD {
    my $self = shift;
    my $method = $AUTOLOAD =~ s/^.*://r;
    if ($self->_field->can($method)) {
        return $self->_field->$method(@_);
    }

lib/Aniki/Schema/Table/PrimaryKey.pm  view on Meta::CPAN

    default => sub {
        my $self = shift;
        return [
            map { Aniki::Schema::Table::Field->new($_) } $self->_primary_key->fields
        ];
    },
);

sub BUILDARGS {
    my ($class, $primary_key) = @_;
    return $class->SUPER::BUILDARGS(_primary_key => $primary_key);
}

sub fields { @{ shift->_fields } }

our $AUTOLOAD;
sub AUTOLOAD {
    my $self = shift;
    my $method = $AUTOLOAD =~ s/^.*://r;
    if ($self->_primary_key->can($method)) {
        return $self->_primary_key->$method(@_);



( run in 0.617 second using v1.01-cache-2.11-cpan-49f99fa48dc )