Skip to content

Commit 6a2abcb

Browse files
committed
PGPLOT rationalise construction
1 parent 42a1d02 commit 6a2abcb

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

lib/PDL/Graphics/Simple/PGPLOT.pm

+11-24
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ sub new {
9999
my $pkg = shift;
100100
my $opt_in = shift;
101101
my $opt = { iparse( $new_defaults, $opt_in ) };
102-
103-
my $pgw;
104-
102+
105103
# Force a recheck on failure, in case the user fixed PGPLOT.
106104
# Also loads PDL::Graphics::PGPLOT::Window.
107105
unless(check()) {
@@ -114,7 +112,7 @@ sub new {
114112
my $dev;
115113

116114
if( $opt->{type} =~ m/^i/i) {
117-
$dev = ( defined($opt->{output}) ? $opt->{output} : "" ) . "/$mod->{disp_dev}";
115+
$dev = ( $opt->{output} // "" ) . "/$mod->{disp_dev}";
118116
} else {
119117
my $ext;
120118

@@ -129,8 +127,7 @@ sub new {
129127
$opt->{output} .= ".png";
130128
}
131129

132-
our $mod;
133-
unless( $filetypes->{$ext} and $mod->{devices}->{$filetypes->{$ext}} ) {
130+
unless ($filetypes->{$ext} and $mod->{devices}{$filetypes->{$ext}}) {
134131
my($fh);
135132
($fh, $conv_tempfile) = tempfile('pgs_pgplot_XXXX');
136133
close $fh;
@@ -142,21 +139,15 @@ sub new {
142139
}
143140
}
144141

145-
($ENV{'PGPLOT_PS_WIDTH'}) = $opt->{size}->[0] * 1000;
146-
($ENV{'PGPLOT_PS_HEIGHT'}) = $opt->{size}->[1] * 1000;
142+
$ENV{PGPLOT_PS_WIDTH} = $opt->{size}[0] * 1000;
143+
$ENV{PGPLOT_PS_HEIGHT} = $opt->{size}[1] * 1000;
147144

148-
my @params = ( 'size => [$opt->{size}->[0], $opt->{size}->[1] ]' );
149-
if( defined($opt->{multi}) ) {
150-
push(@params, 'nx=>$opt->{multi}->[0]');
151-
push(@params, 'ny=>$opt->{multi}->[1]');
152-
}
153-
154-
my $creator = 'pgwin( $dev, { '. join(",", @params) . '} );';
155-
$pgw = eval $creator;
156-
print STDERR $@ if($@);
157-
145+
my @params = (size => [@{$opt->{size}}[0,1]]);
146+
push @params, nx=>$opt->{multi}[0], ny=>$opt->{multi}[1]
147+
if defined $opt->{multi};
148+
my $pgw = pgwin( $dev, { @params } );
158149
my $me = { opt=>$opt, conv_fn=>$conv_tempfile, obj=>$pgw };
159-
return bless($me, 'PDL::Graphics::Simple::PGPLOT');
150+
return bless $me;
160151
}
161152

162153
our $pgplot_methods = {
@@ -375,12 +366,8 @@ sub DESTROY {
375366

376367
if (defined $me->{type} and $me->{type} =~ m/^f/i) {
377368
eval { $me->{obj}->close; };
378-
379-
my $file = ( ($me->{conv_fn}) ? $me->{conv_fn} : $me->{output} );
380369
if ($me->{conv_fn}) {
381-
my $a;
382-
$a = rim($me->{conv_fn}) ;
383-
wim($a, $me->{opt}->{output});
370+
wim(rim($me->{conv_fn}), $me->{opt}{output});
384371
unlink($me->{conv_fn});
385372
}
386373
}

0 commit comments

Comments
 (0)