lib/App/PerlShell/Plugin/TextCSV.pm

filter: Statementstmt 38.4% 20 / 52 Branchbran 5.5% 1 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 36.2% 29 / 80 CC 10 SCAR 41.8
CC
10
Cov
30%
textcsv
110.0
TextCSV
2.0
BEGIN
1.1
CRAP 65.2
« lib/App/PerlShell/Plugin/File.pm ↑ Summary lib/App/PerlShell/Plugin/Gnuplot.pm »
1 package App::PerlShell::Plugin::TextCSV;
2  
3 ########################################################
4 # AUTHOR = Michael Vincent
5 # www.VinsWorld.com
6 ########################################################
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Pod::Find qw( pod_where );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶eval "use Text::CSV";
Subroutine BEGIN: called CC=1 SCAR=1.2
14 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 0 1
15 1 print "Text::CSV required.\n";
16 1 return 1;
17 }
18  
19 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 our @EXPORT = qw(
22 TextCSV
23 textcsv
24 );
25  
26 0 our @ISA = qw ( Exporter );
27  
28 0 ▶sub TextCSV {
Subroutine TextCSV: not called CC=1 SCAR=6.9
Pod documented
29 0 pod2usage(
30 -verbose => 2,
31 -exitval => "NOEXIT",
32 -input => pod_where( {-inc => 1}, __PACKAGE__ )
33 );
34 }
35  
36 ########################################################
37  
38 0 ▶sub textcsv {
Subroutine textcsv: not called CC=10 SCAR=47.0
Pod documented
39 0 my ( $file, $params ) = @_;
40  
41 0 ▶ if ( not defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
42 0 print "file required\n";
43 0 return;
44 }
45 0 ▶ if ( not defined $params ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params) 0 0 0
46 0 $params = {};
47 }
48  
49 0 ▶ my $csv = Text::CSV->new( $params )
Branch: 1 branch
BranchTrueFalseTotal
my $csv = "Text::CSV"->new($params) or die "Text::CSV"->error_diag 0 0 0
50 or die Text::CSV->error_diag;
51  
52 0 ▶ open my $fh, "<", $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "$!" 0 0 0
53 or die "$!";
54  
55 0 my @rets;
56 0 my $retType = wantarray;
57 0 my ( $line, $skip ) = ( 0, 0 );
58 0 ▶ while ( my $row = $csv->getline($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $csv->getline($fh)) 0 0 0
59 0 $line++; # for error message if needed
60 0 push @rets, $row;
61 }
62 0 ▶ if ( not $csv->eof ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($csv->eof) 0 0 0
63 0 my ( $cde, $str, $pos ) = $csv->error_diag;
64 0 print "$line,$pos: ($cde) $str\n";
65 }
66  
67 0 close $fh;
68  
69 0 ▶ if ( not defined($retType) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
70 0 for ( @rets ) {
71 0 print join $csv->sep_char, @{$_};
72 0 print "\n";
73 }
74 return
75 0 } elsif ($retType) {
76 0 return @rets;
77 } else {
78 0 return \@rets;
79 }
80 }
81  
82 0 1;
83  
84 __END__
« lib/App/PerlShell/Plugin/File.pm ↑ Summary lib/App/PerlShell/Plugin/Gnuplot.pm »