Show
Ignore:
Timestamp:
09/24/08 00:09:41 (6 years ago)
Author:
lopnor
Message:

lang/perl/App-Hachero: more tt friendly result

Location:
lang/perl/App-Hachero/trunk
Files:
3 modified

Legend:

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

    r19768 r19782  
    1212    my $tt = Template->new; 
    1313    my $template < io $tt_file; 
    14     $tt->process(\$template, $context->result, \my $out); 
     14    $tt->process(\$template, $context, \my $out); 
    1515    $out > io $out_file; 
    1616} 
    1717 
    18181; 
    19  
     19__DATA__ 
  • lang/perl/App-Hachero/trunk/lib/App/Hachero/Result.pm

    r19768 r19782  
    1717    my ($self, $args) = @_; 
    1818    my $key = $self->key($args); 
    19     $self->data->{$key} ||= $args; 
    20     $self->data->{$key}->{count}++; 
     19    $self->data->{$key} ||= App::Hachero::Result::Data->new($args); 
     20    $self->data->{$key}->count_up; 
    2121} 
    2222 
     
    5151} 
    5252 
     53package App::Hachero::Result::Data; 
     54 
     55sub new { 
     56    my ($class, $self) = @_; 
     57    bless $self, $class; 
     58} 
     59 
     60sub keys { 
     61    my $self = shift; 
     62    return sort {$a eq 'count' ? 1 : 0} keys %{$self}; 
     63} 
     64 
     65sub value { 
     66    my ($self, $arg) = @_; 
     67    return $self->{$arg}; 
     68} 
     69 
     70sub count_up { 
     71    shift->{count}++; 
     72} 
     73 
    53741; 
  • lang/perl/App-Hachero/trunk/t/plugin/output/04_tt.t

    r19768 r19782  
    6565    - key: hooo 
    6666--- template 
    67 [% FOR i IN Hoge.values -%] 
    68 [% i.key %]: [% i.count %] 
     67[% FOR r IN result -%] 
     68[% r.key %] 
     69[% FOR i IN r.value.values -%] 
     70[% FOR k IN i.keys -%] 
     71[% k %]: [% i.value(k) %] 
     72[% END -%] 
     73[% END -%] 
    6974[% END -%] 
    7075--- expected 
    71 bar: 2 
    72 hooo: 3 
     76Hoge 
     77key: bar 
     78count: 2 
     79key: hooo 
     80count: 3 
     81