File: 35-csv_obj.t

package info (click to toggle)
libtie-array-csv-perl 0.08-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: perl: 302; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 881 bytes parent folder | download
1
2
3
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
40
41
42
43
44
45
46
47
48
49
50
51
52

use strict;
use warnings;

use Test::More;
use File::Temp qw/tempfile/;

use_ok( 'Tie::Array::CSV' );

my $test_data = <<END_DATA;
name,rank,serial number
joel berger,plebe,1010101
larry wall,general,1
damian conway,colonel,1001
END_DATA

{ 
  package My::Text::CSV;
  use Text::CSV;
  our @ISA = ('Text::CSV');

  my $parsed_lines = 0;

  sub my_parsed_lines { return $parsed_lines }

  sub parse {
    my $self = shift;

    $parsed_lines++;

    return $self->SUPER::parse(@_);
  }
}

{
  my ($fh, $file) = tempfile();
  print $fh $test_data;

  my $csv_obj = My::Text::CSV->new();

  my @csv;
  ok( tie(@csv, 'Tie::Array::CSV', $fh, {text_csv => $csv_obj}), "Tied CSV" );

  is( scalar @csv, 4, "Report correct number of rows" );
  is( scalar @{$csv[0]}, 3, "Report correct number of columns" );

  ok( $csv_obj->my_parsed_lines, "Text::CSV subclass" );
 
}

done_testing();