| 1 | package App::CCSV; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use App::CCSV::TieCSV; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Text::CSV_XS; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Config::General; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $csv; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $csvout; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our @EXPORT = qw(cprint csay parse $csv); | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our $VERSION = 0.02; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | sub import | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | _init(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | __PACKAGE__->export_to_level(1,1,qw(csay cprint parse $csv)); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | tie *ARGV, 'TieCSV',$csv; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub _init | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=28 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my $out = length($_[-1] || '') > 1 && $#_ > 0 ? pop : ''; # last argument length > 1 means csvout config section if more than 1 argument | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
length($_[-1] || "") > 1 and $#_ > 0
$_[-1] || ''
MC/DC0%0/2
length($_[-1] || "") > 1 and $#_ > 0
$_[-1]
$#_ > 0
Truth table33%1/3
A and B
A= $_[-1]B= $#_ > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my ($quote,$sep,$escape,$eol) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | #print join "|", ($quote, $sep, $escape, $eol,"\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $cfgfile = $ENV{CCSVCONF} || $ENV{HOME} || '~'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$ENV{'CCSVCONF'} || $ENV{'HOME'} || '~'
$ENV{"CCSVCONF"} or $ENV{"HOME"}
MC/DC0%0/2
$ENV{'CCSVCONF'} || $ENV{'HOME'} || '~'
$ENV{"CCSVCONF"}
$ENV{"HOME"}
Truth table33%1/3
A or B
A= $ENV{"CCSVCONF"}B= $ENV{"HOME"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $cfgfile = $cfgfile . '/.CCSVConf' unless $ENV{CCSVCONF}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if (length($quote || '') <= 1) # length > 1 specifies config section | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$quote || ''
MC/DC0%0/1
$quote || ''
$quote
Truth table50%1/2
A
A= $quote
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | $csv = Text::CSV_XS->new( { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$quote || '"'
$sep || ','
$escape || '"'
$eol || ''
MC/DC0%0/1
$quote || '"'
$quote
MC/DC0%0/1
$sep || ','
$sep
MC/DC0%0/1
$escape || '"'
$escape
MC/DC0%0/1
$eol || ''
$eol
Truth table50%1/2
A
A= $quote
Truth table50%1/2
A
A= $sep
Truth table50%1/2
A
A= $escape
Truth table50%1/2
A
A= $eol
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | quote_char => $quote || '"', | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sep_char => $sep || ',', | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | escape_char => $escape || '"', | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | eol => $eol || '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | binary => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } else | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $csv = Text::CSV_XS->new(); # config later from cfgfile | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if (-r $cfgfile) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $conf = new Config::General($cfgfile); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my %config = $conf->getall; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | # CSV: | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (!@_ || ($#_ == 0 and $quote eq '')) # no override(s) from command line | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
not @_ or $#_ == 0 and $quote eq ""
$#_ == 0 and $quote eq ""
MC/DC0%0/3
not @_ or $#_ == 0 and $quote eq ""
not @_
$#_ == 0
$quote eq ""
Truth table0%0/4
not(A) or B and C
A= not @_B= $#_ == 0C= $quote eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | _confme($csv,$config{CCSV}) if $config{CCSV}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif (length($quote) > 1) # config section | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | die "no config section with name <$quote> could be found in $cfgfile\n" unless $config{CCSV}->{names}->{$quote}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | _confme($csv,$config{CCSV}->{names}->{$quote}); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | _confme($csv,$config{CCSV}->{overrideall}) if $config{CCSV}->{overrideall}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # different CSVOUT? | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($out) # get from config section | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | die "no config section with name <$out> could be found in $cfgfile\n" unless $config{CCSV}->{names}->{$out}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $csvout = Text::CSV_XS->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | _confme($csvout,$config{CCSV}->{names}->{$out}); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } elsif ($config{CCSV}->{out}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $csvout = Text::CSV_XS->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | _confme($csvout,$config{CCSV}->{out}); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } else # die if config file is needed but not present: | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | 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); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$quote || ''
MC/DC0%0/1
$quote || ''
$quote
Truth table50%1/2
A
A= $quote
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | die "last param length > 1 means output config section, but no readable config file could be found at $cfgfile\n" if (length($out || '') > 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$out || ''
MC/DC0%0/1
$out || ''
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub _confme | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_confme: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # ($csv,$conf); | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $conf = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | for my $key (keys %{$conf}) | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | next if ($key eq 'overrideall' or $key eq 'out' or $key eq 'names'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$key eq "overrideall" or $key eq "out" or $key eq "names"
$key eq "overrideall" or $key eq "out"
MC/DC0%0/3
$key eq "overrideall" or $key eq "out" or $key eq "names"
$key eq "overrideall"
$key eq "out"
$key eq "names"
Truth table0%0/4
A or B or C
A= $key eq "overrideall"B= $key eq "out"C= $key eq "names"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $_[0]->$key($conf->{$key}); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub cprint | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cprint: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($csvout) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csay: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | cprint(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | print $/; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $csv->parse($line || $_); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$line || $_
MC/DC0%0/2
$line || $_
$line
$_
Truth table0%0/3
A || B
A= $lineB= $_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $csv->fields(); | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||