This file is indexed.

/usr/share/perl5/Alien/Gnuplot.pm is in libalien-gnuplot-perl 1.033-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
=head1 NAME

Alien::Gnuplot - Find and verify functionality of the gnuplot executable.

=head1 SYNOPSIS

 package MyGnuplotter;

 use strict;

 use Alien::Gnuplot;

 $gnuplot = $Alien::Gnuplot::executable;

 `$gnuplot < /tmp/plotfile`;

 1;

=head1 DESCRIPTION

Alien::Gnuplot verifies existence and sanity of the gnuplot external
application.  It only declares one access method,
C<Alien::Gnuplot::load_gnuplot>, which does the actual work and is
called automatically at load time.  Alien::Gnuplot doesn't have any
actual plotting methods - making use of gnuplot, once it is found and
verified, is up to you or your client module.

Using Alien::Gnuplot checks for existence of the executable, verifies
that it runs properly, and sets several global variables to describe
the properties of the gnuplot it found:

=over 3

=item * C<$Alien::Gnuplot::executable> 

gets the path to the gnuplot executable.

=item * C<$Alien::Gnuplot::version> 

gets the self-reported version number of the executable.

=item * C<$Alien::Gnuplot::pl> 

gets the self-reported patch level.

=item * C<@Alien::Gnuplot::terms> 

gets a list of the names of all supported terminal devices.

=item * C<%Alien::Gnuplot::terms> 

gets a key for each supported terminal device; values are the 1-line
description from gnuplot.  This is useful for testing whether a
particular terminal is supported.

=item * C<@Alien::Gnuplot::colors> 

gets a list of the names of all named colors recognized by this gnuplot.

=item * C<%Alien::Gnuplot::colors> 

gets a key for each named color; values are the C<#RRGGBB> form of the color.
This is useful for decoding colors, or for checking whether a particular color
name is recognized.  All the color names are lowercase alphanumeric.

=back

You can point Alien::Gnuplot to a particular path for gnuplot, by
setting the environment variable GNUPLOT_BINARY to the path.  Otherwise
your path will be searched (using File::Spec) for the executable file.

If there is no executable application in your path or in the location
pointed to by GNUPLOT_BINARY, then the module throws an exception.
You can also verify that it has not completed successfully, by
examining $Alien::Gnuplot::version, which is undefined in case of
failure and contains the gnuplot version string on success.

If you think the global state of the gnuplot executable may have
changed, you can either reload the module or explicitly call
C<Alien::Gnuplot::load_gnuplot()> to force a fresh inspection of
the executable.

=head1 INSTALLATION STRATEGY

When you install Alien::Gnuplot, it checks that gnuplot itself is
installed as well.  If it is not, then Alien::Gnuplot attempts to 
use one of several common package managers to install gnuplot for you.
If it can't find one of those, if dies (and refuses to install), printing
a friendly message about how to get gnuplot before throwing an error.

In principle, gnuplot could be automagically downloaded and built, 
but it is distributed via Sourceforge -- which obfuscates interior
links, making such tools surprisingly difficult to write.

=head1 CROSS-PLATFORM BEHAVIOR

On POSIX systems, including Linux and MacOS, Alien::Gnuplot uses
fork/exec to invoke the gnuplot executable and asynchronously monitor
it for hangs.  Microsoft Windows process control is more difficult, so
if $^O contains "MSWin32", a simpler system call is used, that is
riskier -- it involves waiting for the unknown executable to complete.

=head1 REPOSITORIES

Gnuplot's main home page is at L<http://www.gnuplot.info>.

Alien::Gnuplot development is at L<http://github.com/drzowie/Alien-Gnuplot>.

A major client module for Alien::Gnuplot is PDL::Graphics::Gnuplot, which
can be found at L<http://github.com/drzowie/PDL-Graphics-Gnuplot>.
PDL is at L<http://pdl.perl.org>.

=head1 AUTHOR

Craig DeForest <craig@deforest.org>

(with special thanks to Chris Marshall, Juergen Mueck, and
Sisyphus for testing and debugging on the Microsoft platform)

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2013 Craig DeForest

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

package Alien::Gnuplot;

use strict;
our $DEBUG = 0; # set to 1 for some debugging output

use File::Spec;
use File::Temp qw/tempfile/;
use Time::HiRes qw/usleep/;
use POSIX ":sys_wait_h";

# VERSION here is for CPAN to parse -- it is the version of the module itself.  But we
# overload the system VERSION to compare a required version against gnuplot itself, rather
# than against the module version.

our $VERSION = '1.033';

# On install, try to make sure at least this version is present.
our $GNUPLOT_RECOMMENDED_VERSION = '4.6';  

our $executable;  # Holds the path to the found gnuplot
our $version;     # Holds the found version number
our $pl;          # Holds the found patchlevel
our @terms;
our %terms;
our @colors;
our %colors;

sub VERSION {
    my $module =shift;
    my $req_v = shift;
    unless($req_v <= $version) {
	die qq{

Alien::Gnuplot: Found gnuplot version $version, but you requested $req_v. 
You should upgrade gnuplot, either by reinstalling Alien::Gnuplot or 
getting it yourself from L<http://www.gnuplot.info>.

};
    }
}


sub load_gnuplot {
##############################
# Search the path for the executable
#
    my $exec_path;
    if($ENV{'GNUPLOT_BINARY'}) {
	$exec_path = $ENV{'GNUPLOT_BINARY'};
    } else {
	my $exec_str = "gnuplot";
	my @path = File::Spec->path();
	for my $dir(@path) {
	    $exec_path = File::Spec->catfile( $dir, $exec_str );
	    last if( -x $exec_path );
	    $exec_path .= ".exe";
	    last if( -x $exec_path );
	}
    }
    
    unless(-x $exec_path) { 
	die q{
Alien::Gnuplot: no executable gnuplot found!  If you have gnuplot,
you can put its exact location in your GNUPLOT_BINARY environment 
variable or make sure your PATH contains it.  If you do not have
gnuplot, you can reinstall Alien::Gnuplot to get it, or get
it yourself from L<http://www.gnuplot.info>.
};
    }
    
##############################
# Execute the executable to make sure it's really gnuplot, and parse
# out its reported version.  This is complicated by gnuplot's shenanigans
# with STDOUT and STDERR, so we fork and redirect everything to a file.
# The parent process gives the daughter 2 seconds to report progress, then
# kills it dead.
    my($pid);
    my ($undef, $file) = tempfile();

    # Create command file
    open FOO, ">${file}_gzinta";
    print FOO "show version\nset terminal\n\n\n\n\n\n\n\n\n\nprint \"CcColors\"\nshow colornames\n\n\n\n\n\n\n\nprint \"FfFinished\"\nexit\n";
    close FOO;

    if($^O =~ /MSWin32/i) {

	if( $exec_path =~ m/([\"\*\?\<\>\|])/ ) {
	    die "Alien::Gnuplot: Invalid character '$1' in path to gnuplot -- I give up" ;
	}
	
	# Microsoft Windows sucks at IPC (and many other things), so
	# use "system" instead of civilized fork/exec.
	# This leaves us vulnerable to gnuplot itself hanging, but 
	# sidesteps the problem of waitpid hanging on Strawberry Perl.
	open FOO, ">&STDOUT";
	open BAR, ">&STDERR";
	open STDOUT,">$file";
	open STDERR,">$file";
	system(qq{"$exec_path" < ${file}_gzinta});
	open STDOUT,">&FOO";
	open STDERR,">&BAR";
	close FOO;
	close BAR;
    } else {
	$pid = fork();
	if(defined($pid)) {
	    if(!$pid) {
		# daughter
		open BAR, ">&STDERR"; # preserve stderr
		eval { 
		    open STDOUT, ">$file";
		    open STDERR, ">&STDOUT";
		    open STDIN, "<${file}_gzinta";
		    no warnings; 
		    exec($exec_path);
		    print BAR "Execution of $exec_path failed!\n";
		    exit(1);
		}; 
		print STDERR "Alien::Gnuplot: Unknown problems spawning '$exec_path' to probe gnuplot.\n";
		exit(2); # there was a problem!
	    } else {
		# parent
		# Assume we're more POSIX-compliant...
		if($DEBUG) { print "waiting for pid $pid (up to 20 iterations of 100ms)"; flush STDOUT; }
		for (1..20) {
		    if($DEBUG) { print "."; flush STDOUT; }
		    if(waitpid($pid,WNOHANG)) {
			$pid=0;
			last;
		    }
		    usleep(1e5);
		}
		if($DEBUG) { print "\n"; flush STDOUT; }
		
		if($pid) {
		    if( $DEBUG) { print "gnuplot didn't complete.  Killing it dead...\n"; flush STDOUT; }
		    kill 9,$pid;   # zap
		    waitpid($pid,0); # reap
		}
	    } #end of parent case
	} else {
	    # fork returned undef - error.
	    die "Alien::Gnuplot: Couldn't fork to test gnuplot! ($@)\n";
	}
    }
    
##############################
# Read what gnuplot had to say, and clean up our mess...
    open FOO, "<$file";
    my @lines = <FOO>;
    close FOO;
    unlink $file;
    unlink $file."_gzinta";
    
##############################
# Whew.  Now parse out the 'GNUPLOT' and version number...
    my $lines = join("", map { chomp $_; $_} @lines);
    $lines =~ s/\s+G N U P L O T\s*//  or  die qq{
Alien::Gnuplot: the executable '$exec_path' appears not to be gnuplot,
or perhaps there was a problem running it.  You can remove it or set
your GNUPLOT_BINARY variable to an actual gnuplot.
};
    
    $lines =~ m/Version (\d+\.\d+) (patchlevel (\d+))?/ or die qq{
Alien::Gnuplot: the executable file $exec_path claims to be gnuplot, but 
I could not parse a version number from its output.  Sorry, I give up.

};
    
    $version = $1;
    $pl = $3;
    $executable = $exec_path;
    
##############################
# Parse out available terminals and put them into the 
# global list and hash.
    @terms = ();
    %terms = ();
    my $reading_terms = 0;
    for my $line(@lines) {
	last if($line =~ m/CcColors/);
	if(!$reading_terms) {
	    if($line =~ m/^Available terminal types\:/) {
		$reading_terms = 1;
	    }
	} else {
	    $line =~ s/^Press return for more\:\s*//;
	    $line =~ m/^\s*(\w+)\s(.*[^\s])\s*$/ || next;
	    push(@terms, $1);
	    $terms{$1} = $2;
	}
    }
    
##############################
# Parse out available colors and put them into that global list and hash.
    @colors = ();
    %colors = ();
    
    for my $line(@lines) {
	last if($line =~ m/FfFinished/);
	next unless( $line =~ m/\s+([\w\-0-9]+)\s+(\#......)/);
	$colors{$1} = $2;
    }
    @colors = sort keys %colors;
}


load_gnuplot();


1;