| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::CCSV; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
40902
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
4
|
1
|
|
|
1
|
|
3624
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
18402
|
|
|
|
1
|
|
|
|
|
83
|
|
|
5
|
1
|
|
|
1
|
|
590
|
use App::CCSV::TieCSV; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
6
|
1
|
|
|
1
|
|
1832
|
use Text::CSV_XS; |
|
|
1
|
|
|
|
|
13777
|
|
|
|
1
|
|
|
|
|
80
|
|
|
7
|
1
|
|
|
1
|
|
1556
|
use Config::General; |
|
|
1
|
|
|
|
|
107954
|
|
|
|
1
|
|
|
|
|
1595
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $csv; |
|
12
|
|
|
|
|
|
|
our $csvout; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw(cprint csay parse $csv); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.02; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import |
|
19
|
|
|
|
|
|
|
{ |
|
20
|
1
|
|
|
1
|
|
12
|
my $name = shift; |
|
21
|
1
|
|
|
|
|
3
|
_init(@_); |
|
22
|
1
|
|
|
|
|
308
|
__PACKAGE__->export_to_level(1,1,qw(csay cprint parse $csv)); |
|
23
|
1
|
|
|
|
|
11
|
tie *ARGV, 'TieCSV',$csv; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _init |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
1
|
50
|
33
|
1
|
|
16
|
my $out = length($_[-1] || '') > 1 && $#_ > 0 ? pop : ''; # last argument length > 1 means csvout config section if more than 1 argument |
|
29
|
1
|
|
|
|
|
2
|
my ($quote,$sep,$escape,$eol) = @_; |
|
30
|
|
|
|
|
|
|
#print join "|", ($quote, $sep, $escape, $eol,"\n"); |
|
31
|
1
|
|
50
|
|
|
13
|
my $cfgfile = $ENV{CCSVCONF} || $ENV{HOME} || '~'; |
|
32
|
1
|
50
|
|
|
|
7
|
$cfgfile = $cfgfile . '/.CCSVConf' unless $ENV{CCSVCONF}; |
|
33
|
1
|
50
|
50
|
|
|
8
|
if (length($quote || '') <= 1) # length > 1 specifies config section |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
1
|
|
50
|
|
|
173
|
$csv = Text::CSV_XS->new( { |
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
|
|
|
|
|
|
quote_char => $quote || '"', |
|
37
|
|
|
|
|
|
|
sep_char => $sep || ',', |
|
38
|
|
|
|
|
|
|
escape_char => $escape || '"', |
|
39
|
|
|
|
|
|
|
eol => $eol || '', |
|
40
|
|
|
|
|
|
|
binary => 1, |
|
41
|
|
|
|
|
|
|
} ); |
|
42
|
|
|
|
|
|
|
} else |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
|
|
|
|
0
|
$csv = Text::CSV_XS->new(); # config later from cfgfile |
|
45
|
|
|
|
|
|
|
} |
|
46
|
1
|
50
|
|
|
|
789
|
if (-r $cfgfile) |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
0
|
|
|
|
|
0
|
my $conf = new Config::General($cfgfile); |
|
49
|
0
|
|
|
|
|
0
|
my %config = $conf->getall; |
|
50
|
|
|
|
|
|
|
# CSV: |
|
51
|
0
|
0
|
0
|
|
|
0
|
if (!@_ || ($#_ == 0 and $quote eq '')) # no override(s) from command line |
|
|
|
0
|
0
|
|
|
|
|
|
52
|
|
|
|
|
|
|
{ |
|
53
|
0
|
0
|
|
|
|
0
|
_confme($csv,$config{CCSV}) if $config{CCSV}; |
|
54
|
|
|
|
|
|
|
} elsif (length($quote) > 1) # config section |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
0
|
0
|
|
|
|
0
|
die "no config section with name <$quote> could be found in $cfgfile\n" unless $config{CCSV}->{names}->{$quote}; |
|
57
|
0
|
|
|
|
|
0
|
_confme($csv,$config{CCSV}->{names}->{$quote}); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
0
|
_confme($csv,$config{CCSV}->{overrideall}) if $config{CCSV}->{overrideall}; |
|
61
|
|
|
|
|
|
|
# different CSVOUT? |
|
62
|
0
|
0
|
|
|
|
0
|
if ($out) # get from config section |
|
|
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
{ |
|
64
|
0
|
0
|
|
|
|
0
|
die "no config section with name <$out> could be found in $cfgfile\n" unless $config{CCSV}->{names}->{$out}; |
|
65
|
0
|
|
|
|
|
0
|
$csvout = Text::CSV_XS->new(); |
|
66
|
0
|
|
|
|
|
0
|
_confme($csvout,$config{CCSV}->{names}->{$out}); |
|
67
|
|
|
|
|
|
|
} elsif ($config{CCSV}->{out}) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
0
|
|
|
|
|
0
|
$csvout = Text::CSV_XS->new(); |
|
70
|
0
|
|
|
|
|
0
|
_confme($csvout,$config{CCSV}->{out}); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} else # die if config file is needed but not present: |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
1
|
50
|
50
|
|
|
24
|
die "1st param char length > 1 means input config section, but no readable config file could be found at $cfgfile \n" if (length($quote || '') > 1); |
|
75
|
1
|
50
|
50
|
|
|
11
|
die "last param length > 1 means output config section, but no readable config file could be found at $cfgfile\n" if (length($out || '') > 1); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _confme |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
|
|
|
|
|
|
# ($csv,$conf); |
|
82
|
0
|
|
|
0
|
|
|
my $conf = $_[1]; |
|
83
|
0
|
|
|
|
|
|
for my $key (keys %{$conf}) |
|
|
0
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
0
|
0
|
|
|
|
next if ($key eq 'overrideall' or $key eq 'out' or $key eq 'names'); |
|
|
|
|
0
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$_[0]->$key($conf->{$key}); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub cprint |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
0
|
0
|
|
0
|
1
|
|
if ($csvout) |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
0
|
|
|
|
|
|
$csvout->combine(@_); |
|
95
|
0
|
|
|
|
|
|
print $csvout->string(); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} else |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
0
|
|
|
|
|
|
$csv->combine(@_); |
|
100
|
0
|
|
|
|
|
|
print $csv->string(); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub csay |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
0
|
|
|
0
|
1
|
|
cprint(@_); |
|
107
|
0
|
|
|
|
|
|
print $/; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub parse |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
0
|
1
|
|
my $line = shift; |
|
113
|
0
|
|
0
|
|
|
|
$csv->parse($line || $_); |
|
114
|
0
|
|
|
|
|
|
return $csv->fields(); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |