Skip to content

Commit 2797910

Browse files
committed
PGS::PLplot stop eval-ing new
1 parent ca35856 commit 2797910

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

lib/PDL/Graphics/Simple/PLplot.pm

+20-26
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ sub check {
5252
return $mod->{ok} unless( $force or !defined($mod->{ok}) );
5353

5454
eval { require PDL::Graphics::PLplot; PDL::Graphics::PLplot->import };
55-
if($@) {
55+
if ($@) {
5656
$mod->{ok} = 0;
5757
$mod->{msg} = $@;
5858
return 0;
@@ -62,7 +62,7 @@ sub check {
6262
my $plgDevs = plgDevs();
6363
$mod->{devices} = {map +($_=>1), keys %$plgDevs};
6464

65-
if( my ($good_dev) = grep $mod->{devices}{$_}, @DEVICES ) {
65+
if ( my ($good_dev) = grep $mod->{devices}{$_}, @DEVICES ) {
6666
$mod->{disp_dev} = $good_dev;
6767
} else {
6868
$mod->{ok} = 0;
@@ -115,16 +115,16 @@ sub new {
115115
my $conv_tempfile;
116116
my $dev;
117117
my @params;
118-
if( $opt->{type} =~ m/^i/i) {
118+
if ( $opt->{type} =~ m/^i/i) {
119119
## Interactive devices
120120
$dev = $mod->{disp_dev};
121-
if($opt->{output}) {
121+
if ($opt->{output}) {
122122
push(@params, FILE=>$opt->{output});
123123
}
124124
} else {
125125
my $ext;
126126
## File devices
127-
if( $opt->{output} =~ m/\.(\w{2,4})$/ ) {
127+
if ( $opt->{output} =~ m/\.(\w{2,4})$/ ) {
128128
$ext = $1;
129129
} else {
130130
$ext = 'png';
@@ -151,20 +151,15 @@ sub new {
151151

152152
my $me = { opt=>$opt, conv_fn=>$conv_tempfile };
153153

154-
if( defined($opt->{multi}) ) {
154+
if ( defined($opt->{multi}) ) {
155155
push(@params, SUBPAGES => [$opt->{multi}->[0], $opt->{multi}->[1]] );
156156
$me->{multi_cur} = 0;
157157
$me->{multi_n} = $opt->{multi}->[0] * $opt->{multi}->[1];
158158
}
159159

160-
my $creator = sub { my $w = PDL::Graphics::PLplot->new( @params );
161-
plsstrm($w->{STREAMNUMBER});
162-
plspause(0);
163-
return $w;
164-
};
165-
$me->{obj} = eval { &$creator };
166-
print STDERR $@ if($@);
167-
160+
$me->{obj} = my $w = PDL::Graphics::PLplot->new( @params );
161+
plsstrm($w->{STREAMNUMBER});
162+
plspause(0);
168163
return bless $me;
169164
}
170165

@@ -352,11 +347,11 @@ sub plot {
352347

353348
warn "P::G::S::PLplot: legends not implemented yet for PLplot" if($ipo->{legend});
354349

355-
while(@_) {
350+
while (@_) {
356351
my ($co, @data) = @{shift()};
357352
my @extra_opts = ();
358353

359-
if( defined($co->{style}) and $co->{style}) {
354+
if ( defined($co->{style}) and $co->{style}) {
360355
$me->{style} = $co->{style};
361356
} else {
362357
$me->{style}++;
@@ -365,7 +360,7 @@ sub plot {
365360
$ppo->{COLOR} = $colors[$me->{style}%(@colors)];
366361
$ppo->{LINESTYLE} = (($me->{style}-1) % 8) + 1;
367362

368-
if( defined($co->{width}) and $co->{width} ) {
363+
if ( defined($co->{width}) and $co->{width} ) {
369364
$ppo->{LINEWIDTH} = $co->{width};
370365
}
371366

@@ -375,25 +370,24 @@ sub plot {
375370
my %plplot_opts = (%$ppo);
376371
my $plplot_opts = \%plplot_opts;
377372

378-
if($me->{logaxis} =~ m/x/i) {
373+
if ($me->{logaxis} =~ m/x/i) {
379374
$data[0] = $data[0]->log10;
380375
}
381376

382-
if($me->{logaxis} =~ m/y/i) {
377+
if ($me->{logaxis} =~ m/y/i) {
383378
$data[1] = $data[1]->log10;
384379
}
385380

386-
if(ref($plpm) eq 'CODE') {
387-
&$plpm($me, $ipo, \@data, $plplot_opts);
381+
if (ref($plpm) eq 'CODE') {
382+
$plpm->($me, $ipo, \@data, $plplot_opts);
388383
} else {
389-
my $str= sprintf('$me->{obj}->xyplot(@data,PLOTTYPE=>"%s",%s);%s',$plpm,'%plplot_opts',"\n");
390-
eval $str;
384+
$me->{obj}->xyplot(@data,PLOTTYPE=>$plpm,%plplot_opts);
391385
}
392386
}
393387

394-
$me->{obj}->close if($me->{opt}->{type} =~ m/^f/i and !defined($me->{opt}->{multi}));
388+
$me->{obj}->close if $me->{opt}->{type} =~ m/^f/i and !defined($me->{opt}->{multi});
395389

396-
if($me->{conv_fn}) {
390+
if ($me->{conv_fn}) {
397391
$a = rim($me->{conv_fn});
398392
wim($a->mv(1,0)->slice(':,-1:0:-1'), $me->{opt}->{output});
399393
unlink($me->{conv_fn});
@@ -409,7 +403,7 @@ sub cmd_location {
409403
my @path = File::Spec->path();
410404

411405
for my $p(@path) {
412-
if(-e "${p}\\cmd.exe") {return "${p}\\cmd.exe"}
406+
if (-e "${p}\\cmd.exe") {return "${p}\\cmd.exe"}
413407
}
414408
die "Can't locate cmd.exe";
415409
}

0 commit comments

Comments
 (0)