Show
Ignore:
Timestamp:
10/21/08 11:09:09 (5 years ago)
Author:
lopnor
Message:

lang/perl/App-Hachero: support count_up mode in Output::DBIC

Location:
lang/perl/App-Hachero/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Output/DBIC.pm

    r21618 r21765  
    88    my $schema = App::Hachero::Plugin::Output::DBIC::Schema 
    99        ->connect(@{$self->config->{config}->{connect_info}}); 
     10    my $update_mode = $self->config->{config}->{update_mode}; 
    1011    unless ($schema) { 
    1112        $context->log(error => "connection error"); 
     
    2324            for my $data ($result->values) { 
    2425                eval { 
    25                     $rs->update_or_create($data->hashref) 
     26                    my $hashref = $data->hashref; 
     27                    if ( $update_mode eq 'count_up' ) { 
     28                        my $count = delete $hashref->{count}; 
     29                        my $rec = $rs->find_or_create($hashref); 
     30                        $rec->update({count => ($rec->count || 0) + $count}); 
     31                    } else { 
     32                        $rs->update_or_create($hashref) 
     33                    } 
    2634                }; 
    2735                if ($@) { 
     
    5664    - module: Output::DBIC 
    5765      config: 
     66        update_mode: [count_up|overwrite] 
    5867        connect_info: 
    5968            - dbi:mysql:dbhost=db.local;dbname=logdb 
    6069            - your_name 
    6170            - your_password 
     71         
    6272 
    6373=head1 DESCRIPTION