lib/App/PerlShell/Plugin/Gnuplot.pm

filter: Statementstmt 17.5% 20 / 114 Branchbran 2.0% 1 / 50 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 46.1% 6 / 13 Podpod 100% 6 / 6 totaltotal 17.1% 33 / 193 CC 28 SCAR 41.5
CC
28
Cov
12%
gnuscript
156.0
gnuplot
42.0
gnuterm
42.0
CRAP 63.7
« lib/App/PerlShell/Plugin/TextCSV.pm ↑ Summary lib/App/PerlShell/Plugin/Macros.pm »
1 package App::PerlShell::Plugin::Gnuplot;
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 Chart::Gnuplot";
Subroutine BEGIN: called CC=1 SCAR=1.2
14 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 0 1
15 1 print "Chart::Gnuplot 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 Gnuplot
23 gnuplot
24 gnuterm
25 gnuscript
26 chart
27 dataset
28 );
29  
30 0 our @ISA = qw ( Exporter );
31  
32 # Set gnuplot global config
33 0 $ENV{PERLSHELL_GNUPLOT} = 'gnuplot';
34 0 $ENV{PERLSHELL_GNUPLOT_TERM} = 'wxt';
35  
36 # Update gnuplot program location for Windows by searching Path/PathExt
37 0 ▶if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
38 0 my @paths = split /;/, $ENV{'PATH'};
39 0 my @exts = split /;/, $ENV{'PATHEXT'};
40 0 my $FOUND = 0;
41 0 for my $path (@paths) {
42 0 $path =~ s/\\$//;
43 0 $path .= "\\";
44 0 for my $ext (@exts) {
45 0 my $gnuplot = $path . $ENV{PERLSHELL_GNUPLOT} . "$ext";
46 0 ▶ if ( -e $gnuplot ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $gnuplot) 0 0 0
47 0 $ENV{PERLSHELL_GNUPLOT} = $gnuplot;
48 0 $FOUND++;
49 0 last;
50 }
51 0 ▶ if ($FOUND) { last }
Branch: 1 branch
BranchTrueFalseTotal
if ($FOUND) 0 0 0
52 }
53 }
54 }
55  
56 0 ▶sub Gnuplot {
Subroutine Gnuplot: not called CC=1 SCAR=6.9
Pod documented
57 0 pod2usage(
58 -verbose => 2,
59 -exitval => "NOEXIT",
60 -input => pod_where( {-inc => 1}, __PACKAGE__ )
61 );
62 }
63  
64 ########################################################
65  
66 0 ▶sub gnuplot {
Subroutine gnuplot: not called CC=6 SCAR=37.4
Pod documented
67 0 my %params = ( gnuplot => '' );
68  
69 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
70 0 ( $params{gnuplot} ) = @_;
71 } else {
72 0 ▶ if ( ( @_ % 2 ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 1) 0 0 0
73 0 $params{gnuplot} = shift;
74 }
75  
76 #%args = @_
77 }
78  
79 0 ▶ if ( defined( $params{gnuplot} ) and ( $params{gnuplot} ne '' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"gnuplot"} and $params{"gnuplot"} ne "") 0 0 0
Condition0%0/3
defined $params{"gnuplot"} and $params{"gnuplot"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"gnuplot"} and $params{"gnuplot"} ne ""
defined $params{"gnuplot"} $params{"gnuplot"} ne ""
Truth table0%0/3
A and B
A= defined $params{"gnuplot"}B= $params{"gnuplot"} ne ""
ABresult
0X0
100
111
80 0 $ENV{PERLSHELL_GNUPLOT} = $params{gnuplot};
81 }
82 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
83 0 return $ENV{PERLSHELL_GNUPLOT};
84 } else {
85 0 print $ENV{PERLSHELL_GNUPLOT} . "\n";
86 }
87 }
88  
89 0 ▶sub gnuterm {
Subroutine gnuterm: not called CC=6 SCAR=37.4
Pod documented
90 0 my %params = ( gnuplot_term => '' );
91  
92 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
93 0 ( $params{gnuplot_term} ) = @_;
94 } else {
95 0 ▶ if ( ( @_ % 2 ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 1) 0 0 0
96 0 $params{gnuplot_term} = shift;
97 }
98  
99 #%args = @_
100 }
101  
102 0 ▶ if ( defined( $params{gnuplot_term} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"gnuplot_term"} and $params{"gnuplot_term"} ne "") 0 0 0
Condition0%0/3
defined $params{"gnuplot_term"} and $params{"gnuplot_term"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"gnuplot_term"} and $params{"gnuplot_term"} ne ""
defined $params{"gnuplot_term"} $params{"gnuplot_term"} ne ""
Truth table0%0/3
A and B
A= defined $params{"gnuplot_term"}B= $params{"gnuplot_term"} ne ""
ABresult
0X0
100
111
103 and ( $params{gnuplot_term} ne '' ) ) {
104 0 $ENV{PERLSHELL_GNUPLOT_TERM} = $params{gnuplot_term};
105 }
106 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
107 0 return $ENV{PERLSHELL_GNUPLOT_TERM};
108 } else {
109 0 print $ENV{PERLSHELL_GNUPLOT_TERM} . "\n";
110 }
111 }
112  
113 0 ▶sub gnuscript {
Subroutine gnuscript: not called CC=12 SCAR=50.5
Pod documented
114 0 my ($arg) = @_;
115  
116 0 ▶ if ( not defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg) 0 0 0
117 0 _help( "COMMANDS/gnuscript - return Gnuplot script" );
118 0 return;
119 }
120  
121 0 my @rets;
122 0 my $retType = wantarray;
123  
124 0 ▶ if ( ( ref $arg ) ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg ne "") 0 0 0
125 0 ▶ if ( ( ref $arg ) =~ /^Chart::Gnuplot/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($arg) =~ /^Chart::Gnuplot/) 0 0 0
126 0 ▶ if ( defined $retType ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $retType) { } 0 0 0
127 0 push @rets, $arg->{_script};
128 } else {
129 0 printf "%s\n", $arg->{_script};
130 }
131 0 my $fh;
132 0 ▶ if ( not open( $fh, '<', $arg->{_script} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "<", $arg->{"_script"}) 0 0 0
133 0 warn( "Cannot open file - `" . $arg->{_script} . "'" );
134 0 return;
135 }
136 0 my @lines = <$fh>;
137 0 close($fh);
138  
139 0 for my $line (@lines) {
140 0 chomp $line;
141 0 my @parts = split / /, $line;
142 0 for my $part (@parts) {
143 0 ▶ if ( $part =~ /[\/\\]data['"]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ m([/\\]data['"]$)) 0 0 0
144 0 $part =~ s/'//g;
145 0 $part =~ s/"//g;
146 0 ▶ if ( defined $retType ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $retType) { } 0 0 0
147 0 push @rets, $part;
148 } else {
149 0 printf "%s\n", $part;
150 }
151 }
152 }
153 }
154  
155 0 ▶ if ( not defined $retType ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $retType) { } 0 0 0
elsif ($retType) { } 0 0 0
156 0 return;
157 } elsif ($retType) {
158 0 return @rets;
159 } else {
160 0 return \@rets;
161 }
162 }
163 }
164 }
165  
166 ########################################################
167  
168 0 ▶sub chart {
Subroutine chart: not called CC=4 SCAR=30.0
Pod documented
169 0 my %params;
170  
171 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
172 0 ( $params{title} ) = @_;
173 } else {
174 0 ▶ if ( ( @_ % 2 ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 1) 0 0 0
175 0 $params{title} = shift;
176 }
177 0 my %args = @_;
178 0 for ( keys(%args) ) {
179 0 $params{$_} = $args{$_};
180 }
181 }
182  
183 return Chart::Gnuplot->new(
184 gnuplot => $ENV{PERLSHELL_GNUPLOT},
185 terminal => $ENV{PERLSHELL_GNUPLOT_TERM},
186 0 %params
187 );
188 }
189  
190 0 ▶sub dataset {
Subroutine dataset: not called CC=4 SCAR=30.0
Pod documented
191 0 my %params;
192  
193 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
194 0 ( $params{ydata} ) = @_;
195 } else {
196 0 ▶ if ( ( @_ % 2 ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 1) 0 0 0
197 0 $params{ydata} = shift;
198 }
199 0 my %args = @_;
200 0 for ( keys(%args) ) {
201 0 $params{$_} = $args{$_};
202 }
203 }
204  
205 0 return Chart::Gnuplot::DataSet->new(%params);
206 }
207  
208 0 ▶sub _help {
Subroutine _help: not called CC=1 SCAR=6.9
209 0 my ($section) = @_;
210  
211 0 pod2usage(
212 -verbose => 99,
213 -exitval => "NOEXIT",
214 -sections => $section,
215 -input => pod_where( {-inc => 1}, __PACKAGE__ )
216 );
217 }
218  
219 0 1;
220  
221 __END__
« lib/App/PerlShell/Plugin/TextCSV.pm ↑ Summary lib/App/PerlShell/Plugin/Macros.pm »