Data-Model

 view release on metacpan or  search on metacpan

lib/Data/Model.pm  view on Meta::CPAN

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# for query param validation
if ($RUN_VALIDATION && $query) {
    my @p = %{ $query };
    validate(
        @p, {
            index => {
                type     => HASHREF | UNDEF,
                optional => 1,
                callbacks => {
                    has_index_name => sub {
                        return 1 unless $_[0];
                        return 0 unless scalar(@{ [ %{ $_[0] } ] }) == 2;
                        my($name) = %{ $_[0] };
                        $schema->has_index($name);
                    },
                },
            },
            where => {
                type     => HASHREF | ARRAYREF | UNDEF,

lib/Data/Model/Driver/Queue/Q4M.pm  view on Meta::CPAN

4
5
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
 
use Carp ();
$Carp::Internal{(__PACKAGE__)}++;
 
sub timeout { $_[0]->{timeout} }
 
sub _create_arguments {
    my $arg_length = scalar(@_);
    my $timeout;
    my %callbacks;
    my @queue_tables;
    for (my $i = 0; $i < $arg_length; $i++) {
        my($table, $value) = ($_[$i], $_[$i + 1]);
        if (ref($value) eq 'CODE') {
            # register callback
            push @queue_tables, $table;
            $callbacks{$table} = $value;
 
        } elsif ($table eq 'timeout' && $value =~ /\A[0-9]+\z/) {
            # timeout
            $timeout = $value;
        }
        $i++;
    }
    (\@queue_tables, \%callbacks, $timeout);
}
 
sub queue_wait {
    my($self, $timeout, @tables) = @_;
 
    my $dbh = $self->r_handle;
    my $sql = sprintf 'SELECT queue_wait(%s)', join(', ', (('?') x (scalar(@tables) + 1)));
    my $sth = $dbh->prepare_cached($sql);
 
    # bind params

lib/Data/Model/Driver/Queue/Q4M.pm  view on Meta::CPAN

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    $sth->execute;
}
 
sub queue_running {
    my($self, $c) = (shift, shift);
    $self->{is_aborted} = 0;
    my $arg_length = scalar(@_);
    Carp::croak 'illegal parameter' if $arg_length % 2;
 
    # create table attributes
    my($queue_tables, $callbacks, $timeout) = _create_arguments(@_);
    Carp::croak 'required is callback handler' unless @{ $queue_tables };
 
    my %schema  = map { $_ => 1 } $c->schema_names;
    for my $table (@{ $queue_tables }) {
        my($name) = split /:/, $table;
        Carp::croak "'$name' is missing model name" unless $schema{$name};
    }
 
    $timeout ||= $self->timeout || 60;

lib/Data/Model/Driver/Queue/Q4M.pm  view on Meta::CPAN

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    my $running_table = $queue_tables->[$table_id - 1];
    my($real_table) = split /:/, $running_table;
    my($row) = $c->get( $real_table );
    unless ($row) {
        $self->queue_abort;
        return;
    }
 
    # running callback
    eval {
        $callbacks->{$running_table}->($row);
    };
    if ($@) {
        $self->queue_abort unless $self->{is_aborted};
        die $@; # throwing exception
    }
    return if $self->{is_aborted};
 
    $self->queue_end;
    return $real_table;
}



( run in 0.565 second using v1.01-cache-2.11-cpan-ec4f86ec37b )