Changeset 19768

Show
Ignore:
Timestamp:
09/23/08 21:55:46 (6 years ago)
Author:
lopnor
Message:

lang/perl/App-Hachero: new result class, tt output plugin

Location:
lang/perl/App-Hachero/trunk
Files:
4 added
5 removed
9 modified
1 moved

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Analyze/AccessCount.pm

    r19478 r19768  
    1212    my $time = $req->{datetime}->clone->truncate(to => $truncate); 
    1313    my $key = $time->epoch; 
    14     $context->result->{'AccessCount'}->{$key} = { 
    15         datetime => DateTime::Format::MySQL->format_datetime($time), 
    16         count => ($context->result->{'AccessCount'}->{$key}->{count} || 0) + 1, 
    17     } 
     14    $context->result->{AccessCount} ||= App::Hachero::Result::AccessCount->new; 
     15    $context->result->{AccessCount}->push( 
     16        { 
     17            datetime => DateTime::Format::MySQL->format_datetime($time), 
     18        } 
     19    ); 
    1820} 
    1921 
     22package App::Hachero::Result::AccessCount; 
     23use base qw(App::Hachero::Result); 
     24__PACKAGE__->mk_classdata(primary => ['datetime']); 
     25 
    20261; 
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Analyze/UserAgent.pm

    r19505 r19768  
    1616    my $key = $time->epoch.$browser_string; 
    1717 
    18     $context->result->{'UserAgent'}->{$key} = { 
    19         datetime => DateTime::Format::MySQL->format_datetime($time), 
    20         useragent => $browser_string, 
    21         count => ($context->result->{'UserAgent'}->{$key}->{count} || 0) + 1, 
    22     }; 
     18    $context->result->{UserAgent} ||= App::Hachero::Result::UserAgent->new; 
     19     
     20    $context->result->{UserAgent}->push( 
     21        { 
     22            datetime => DateTime::Format::MySQL->format_datetime($time), 
     23            useragent => $browser_string, 
     24        } 
     25    ); 
    2326} 
    2427 
     28package App::Hachero::Result::UserAgent; 
     29use base qw(App::Hachero::Result); 
     30__PACKAGE__->mk_classdata('primary' => [qw(datetime useragent)]); 
     31 
    25321; 
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/Output/DBIC.pm

    r19336 r19768  
    88    my $schema = App::Hachero::Plugin::Output::DBIC::Schema 
    99        ->connect(@{$self->config->{config}->{connect_info}}); 
     10    unless ($schema) { 
     11        $context->log(error => "connection error"); 
     12        return; 
     13    } 
    1014    for my $key (keys %{$context->result}) { 
    1115        (my $table = $key) =~ s/\:\://g; 
    12         for (values %{$context->result->{$key}}) { 
    13             my $rs = eval {$schema->resultset($table)}; 
    14             $context->log(error => $!) if $@; 
    15             if ($rs) { 
     16        my $rs = eval {$schema->resultset($table)}; 
     17        if ($@) { 
     18            $context->log(error => $!); 
     19            next; 
     20        } 
     21        if ($rs) { 
     22            my $result = $context->result->{$key}; 
     23            for my $data ($result->values) { 
    1624                eval { 
    17                     $rs->update_or_create($_) 
     25                    $rs->update_or_create($data) 
    1826                }; 
    1927                if ($@) { 
    2028                    $context->log(error => $!); 
    2129                } 
    22             } else { 
    23                 $context->log(error => "$table not found"); 
    2430            } 
     31        } else { 
     32            $context->log(error => "$table not found"); 
    2533        } 
    2634    } 
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Plugin/OutputLine/HadoopMap.pm

    r19363 r19768  
    1111    local $Data::Dumper::Terse = 0; 
    1212    for my $prime_key (keys %{$context->result}) { 
    13         my $result = $context->result->{$prime_key}; 
     13        my $result = $context->result->{$prime_key}->data; 
    1414        for my $second_key (keys %{$result}) { 
    1515            my $value = Dumper $result->{$second_key}; 
  • lang/perl/App-Hachero/trunk/t/plugin/analyze/02_accesscount.t

    r19262 r19768  
    3333    $app->run_hook('parse'); 
    3434    $app->run_hook('analyze'); 
    35     my $value = (values %{$app->result->{AccessCount}})[0]; 
     35    my $value = (values %{$app->result->{AccessCount}->data})[0]; 
    3636    is_deeply $value, $block->expected; 
    3737} 
  • lang/perl/App-Hachero/trunk/t/plugin/analyze/03_useragent.t

    r19499 r19768  
    3737    $app->run_hook('classify'); 
    3838    $app->run_hook('analyze'); 
    39     my $value = (values %{$app->result->{UserAgent}})[0]; 
     39    my $res = $app->result->{UserAgent}; 
     40    my $value = (values %{$app->result->{UserAgent}->data})[0]; 
    4041    is_deeply $value, $block->expected; 
    4142} 
  • lang/perl/App-Hachero/trunk/t/plugin/output/01_dbic.t

    r18806 r19768  
    33use Test::Base; 
    44use App::Hachero; 
     5use App::Hachero::Result; 
    56use App::Hachero::Plugin::Output::DBIC; 
    67 
     
    4142    my $rs = $schema->resultset($exp->{tablename}); 
    4243    $rs->delete_all; 
    43     $app->result($block->input); 
     44    my ($key, $value) = %{$block->input}; 
     45    my $res = App::Hachero::Result->new; 
     46    for (@{$value}) { 
     47        $res->primary([ keys %{$_} ]) unless $res->primary; 
     48        $res->push($_);  
     49    } 
     50    $app->result({$key => $res}); 
    4451    $app->run_hook('output'); 
    4552    my @rows = $rs->all; 
     
    5865--- input 
    5966AccessCount: 
    60     '2008-08-21 18:13:00': 
    61         datetime: '2008-08-21 18:13:00' 
    62         count: 5 
    63     '2008-08-21 18:14:00': 
    64         datetime: '2008-08-21 18:14:00' 
    65         count: 2 
     67    - datetime: '2008-08-21 18:13:00' 
     68    - datetime: '2008-08-21 18:13:00' 
     69    - datetime: '2008-08-21 18:13:00' 
     70    - datetime: '2008-08-21 18:13:00' 
     71    - datetime: '2008-08-21 18:13:00' 
     72    - datetime: '2008-08-21 18:14:00' 
     73    - datetime: '2008-08-21 18:14:00' 
    6674--- expected 
    6775tablename: AccessCount 
  • lang/perl/App-Hachero/trunk/t/plugin/output/03_dbic_failure.t

    r19499 r19768  
    2424                connect_info => [ 
    2525                    'dbi:mysql:test', 
    26                     'root', 
    2726                ], 
    2827            } 
  • lang/perl/App-Hachero/trunk/t/plugin/output_line/01_hadoop_map.t

    r19721 r19768  
    33use Test::More tests => 3; 
    44use App::Hachero; 
     5use App::Hachero::Result; 
    56use URI; 
    67use File::Temp; 
    78use IO::All; 
     9use Digest::MD5 qw(md5_hex); 
    810 
    911BEGIN { 
     
    2729 
    2830my $app = App::Hachero->new({config => $config}); 
    29 $app->result({ 
    30     foo => { 
    31         bar => {a => 1, b => 2}, 
    32     } 
    33 }); 
    34  
     31my $res = App::Hachero::Result->new; 
     32$res->primary(['a']); 
     33$res->push({a => 1}); 
     34my $primary = 'foo'; 
     35my $secondary = md5_hex(1); 
     36$app->result({$primary => $res}); 
    3537$app->run_hook('output_line'); 
    3638close STDOUT; 
     
    3941my ($key,$value) = split(/\t/,$contents); 
    4042 
    41 is $key, 'foo-bar'; 
     43is $key, "$primary-$secondary"; 
    4244my $VAR1; 
    4345eval $value; 
    44 is_deeply $VAR1, {a => 1, b => 2}; 
     46is_deeply $VAR1, {a => 1, count => 1};