Aniki

 view release on metacpan or  search on metacpan

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

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        # 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

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
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

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    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

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
        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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    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

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    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

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    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.808 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )