App-Spoor

 view release on metacpan or  search on metacpan

lib/App/Spoor/OutputFormatter.pm  view on Meta::CPAN

  } elsif ($output_type eq 'mailbox_event') {
    __print_mailbox_events(@_);
  }
}

sub __print_reports {
  my $records = shift;
  my $output_handle = shift // *STDOUT;
  my @transformed_record;
  my @headers = ('id', 'event time', 'host', 'event type', 'mailbox address');
  my $csv = Text::CSV->new({ eol => $/ });

  $csv->print($output_handle, \@headers);
  foreach my $record_hash (@{$records}) {
    @transformed_record = (
      $record_hash->{id},
      time2str('%Y-%m-%d %H:%M:%S %z', $record_hash->{event_time}, 'UTC'),
      $record_hash->{host},
      $record_hash->{type},
      $record_hash->{mailbox_address}
    );

    $csv->print($output_handle, \@transformed_record);
  }
}

sub __print_mailbox_events {
  my $records = shift;
  my $output_handle = shift // *STDOUT;
  my @transformed_record;
  my @headers = ('id', 'event time', 'host', 'event type', 'mailbox address', 'ip');
  my $csv = Text::CSV->new({ eol => $/ });

  $csv->print($output_handle, \@headers);
  foreach my $record_hash (@{$records}) {
    @transformed_record = (
      $record_hash->{id},
      time2str('%Y-%m-%d %H:%M:%S %z', $record_hash->{event_time}, 'UTC'),
      $record_hash->{host},
      $record_hash->{type},
      $record_hash->{mailbox_address},
      $record_hash->{ip_actor}{ip_address}

t/OutputFormatter.t  view on Meta::CPAN

sub test_print {
  my $output_type = shift;
  my $records = shift;
  my $output_file = shift;

  my @formatted_records = (
    ['foo', 'bar'],
    ['shnazzle', 'snafu']
  );

  my $csv = Text::CSV->new({ eol => $/ });

  foreach my $record (@formatted_records) {
    $csv->print($output_file, $record);
  }
}

sub teardown {
  remove_tree($test_directory_path);
  close $test_output;
}



( run in 0.970 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )