Alien-Gnuplot-1.033/000755 000770 000000 00000000000 13054055537 014474 5ustar00zowiewheel000000 000000 Alien-Gnuplot-1.033/Changes000644 000770 000000 00000001014 13054055512 015754 0ustar00zowiewheel000000 000000 Revision history for Alien-Gnuplot 1.033 2017-02-24 - bumb version number again and fix MANIFEST problem 1.032 2017-02-23 - bump version number to get around a CPAN funny 1.031 2015-10-04 - slightly more tolerant logic on the terminfo parsing avoids a problem where some terminals were being ignored on some systems. 1.030 2013-11-13 - switch tempfile() call to no-arguments version, to ensure /tmp is used in POSIX systems 1.020 2013-10-28 - fixes to Microsoft Windows support Alien-Gnuplot-1.033/lib/000755 000770 000000 00000000000 13054055537 015242 5ustar00zowiewheel000000 000000 Alien-Gnuplot-1.033/Makefile.PL000644 000770 000000 00000016006 12622252635 016447 0ustar00zowiewheel000000 000000 use strict; use ExtUtils::MakeMaker; sub parseversion { my $version; open GP, 'lib/Alien/Gnuplot.pm' or die "Couldn't open lib/Alien/Gnuplot.pm"; for(){ if(m/our \$VERSION = \'([\d\.]+b?)\'/) {$version = $1;} last if($version); } die "Couldn't parse version from Gnuplot.pm" unless($version); close GP; return $version; } sub MY::libscan { package MY; my ($self, $file) = @_; # Don't install the README.pod or any .pl file return undef if $file =~ /\.pl$|^README.pod/; return $self->SUPER::libscan ($file); } ######################################## ######################################## # reroute the main POD into a separate README.pod if requested. This is here # purely to generate a README.pod for the github front page my $POD_header = <README.pod' or die "Couldn't open README.pod"; print README $POD_header; while () { if (/^=/../^=cut/) { print README; } } } ################################################################################ ################################################################################ ## Here we check for a working gnuplot. What better way to do that than by ## executing our own library? { my $get_msg = ''; eval q{ do q{./lib/Alien/Gnuplot.pm}; $get_msg = $@;}; unless($get_msg) { if($Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION > $Alien::Gnuplot::version) { $get_msg = qq{ Gnuplot seems to exist on your system, but it is version $Alien::Gnuplot::version. The minimum recommended version is $Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION. } } } if($get_msg) { print $get_msg ; my $install_flag; if( (-t STDIN or $^O =~ m/MSWin/) and ! ( $ENV{AUTOMATED_TESTING} or $ENV{PERL_MM_USE_DEFAULT} ) ) { print "\nGnuplot seems to not exist on your system. Shall I try to install it? [Y/n]> "; $a = ; $install_flag = !($a =~ m/^\s*n/i); unless($install_flag) { print qq{ Okay, I won't install gnuplot. You can still install the Alien::Gnuplot module, but it will fail on load until you install the gnuplot executable yourself. }; } } else { if($ENV{PERL_MM_USE_DEFAULT}) { $install_flag = 1; print qq{ Gnuplot seems to not exist on your system, and you set PERL_MM_USE_DEFAULT -- so I'll try to install it for you. }; } else { print qq{ Gnuplot seems to not exist on your system, and this is not an interactive session, so I can't ask if you want to install it. I'll install the module, but it'll fail on load until you install the gnuplot executable yourself. }; } } if($install_flag) { print "Attempting to install/upgrade gnuplot on your system....\n\n"; if( install_gnuplot_binary() ) { print "\nGnuplot installation was successful!\n"; } else { die qq{ Couldn't find gnuplot, and couldn't get it from the standard package managers. I'd try to download the packages from sourceforge, but there are roadblocks that make it hard to automate. You can get gnuplot from the DOWNLOAD link here: "http://gnuplot.info". }; } # end of binary conditional } # end of prompt conditional } # end of get_msg condition } # end of convenience block ############################## ############################## ## ## install_gnuplot_binary routine -- called ## from deep in the install conditional above. ## ## The strategy is to try to get a late-model ## binary from the Usual Suspects, and fall back ## to compiling it. ## ## On success, return 1; on failure return 0. ## Try not to crash. sub install_gnuplot_binary { local($|) = 1; ############################## # if($^O eq 'darwin') { ############################## # Binary distros on mac - try macports, fink, homebrew for my $manager( ['macports','port','http://macports.org'], ['fink','fink','http://www.finkproject.org'], ['homebrew','brew','http://mxcl.github.com/homebrew/'] ) { print "Trying $manager->[0] (you can get it at $manager->[2])..."; my $l = `which $manager->[1]`; if($l) { print "\n"; print STDERR `$manager->[1] install gnuplot`; my $msg; eval q{ do q{lib/Alien/Gnuplot.pm}; $msg = $@; } ; if( (!$msg) and ($Alien::Gnuplot::version >= $Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION)) { print "Success!\n"; return 1; # Success - return 1 } else { return 0; # Failure - give up (once you find one package manager don't use any other) } } else { print "no $manager->[0]\n"; } } # end of manager loop return 0; } # end of macos case elsif($^O eq 'linux') { # The linux package managers generally ask for keyboard feedback (e.g. yum), # so we have to spawn, exec, and wait to make sure the manager gets that feedback. for my $manager( 'yum','apt-get' ) { print "Trying $manager..."; my $l = `which $manager`; if($l) { my $pid = fork(); die "Couldn't fork!" unless(defined($pid)); unless($pid) { ## daughter exec "$manager install gnuplot"; exit(-1); # never get here } waitpid($pid,0); # wait for the install to finish my $msg; eval q{ do q{lib/Alien/Gnuplot.pm}; $msg = $@ }; if( (!$msg) and ($Alien::Gnuplot::version >= $Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION) ) { print "Success!\n"; return 1; # Success - return 1 } else { print "Hmmm, that didn't seem to work.\n"; return 0; # Failure - give up (once you find one package manager don't use any other) } } # end of found-this-manager conditional } # end of manager loop return 0; } # end of linux case else { return 0; ## We're not a system where we know how to do binary installs } } ############################## ############################## ## Write a generic Makefile that puts the module in place. Include a postamble ## that will also make the source code, if necessary. WriteMakefile( NAME => 'Alien::Gnuplot', AUTHOR => 'Craig DeForest ', VERSION => parseversion(), ABSTRACT_FROM => 'lib/Alien/Gnuplot.pm', ($ExtUtils::MakeMaker::VERSION >= 6.3002 ? ('LICENSE'=> 'perl') : ()), PREREQ_PM => { 'Time::HiRes' => 0, 'File::Temp' => 0, 'HTTP::Tiny' => 0, 'POSIX' => 0, 'File::Spec' => 0 }, META_ADD => { resources => { homepage => 'http://github.com/drzowie/Alien-Gnuplot', repository => 'git://github.com/drzowie/Alien-Gnuplot.git', bugtracker => 'craig@deforest.org' } }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Alien-Gnuplot-* src/*[0-9]' }, ); Alien-Gnuplot-1.033/MANIFEST000644 000770 000000 00000000372 13054055540 015621 0ustar00zowiewheel000000 000000 Changes lib/Alien/Gnuplot.pm Makefile.PL MANIFEST This list of files README.pod META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Alien-Gnuplot-1.033/META.json000644 000770 000000 00000002275 13054055537 016123 0ustar00zowiewheel000000 000000 { "abstract" : "Find and verify functionality of the gnuplot executable.", "author" : [ "Craig DeForest " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Alien-Gnuplot", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "File::Spec" : "0", "File::Temp" : "0", "HTTP::Tiny" : "0", "POSIX" : "0", "Time::HiRes" : "0" } } }, "release_status" : "stable", "resources" : { "homepage" : "http://github.com/drzowie/Alien-Gnuplot", "repository" : { "url" : "git://github.com/drzowie/Alien-Gnuplot.git" } }, "version" : "1.033" } Alien-Gnuplot-1.033/META.yml000644 000770 000000 00000001275 13054055537 015752 0ustar00zowiewheel000000 000000 --- abstract: 'Find and verify functionality of the gnuplot executable.' author: - 'Craig DeForest ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Alien-Gnuplot no_index: directory: - t - inc requires: File::Spec: 0 File::Temp: 0 HTTP::Tiny: 0 POSIX: 0 Time::HiRes: 0 resources: homepage: http://github.com/drzowie/Alien-Gnuplot repository: git://github.com/drzowie/Alien-Gnuplot.git version: 1.033 Alien-Gnuplot-1.033/README.pod000644 000770 000000 00000010336 13054055531 016132 0ustar00zowiewheel000000 000000 =head1 OVERVIEW Alien::Gnuplot is intended for distribution via CPAN. This repository stores the history for the Alien::Gnuplot module on CPAN. Install the module via CPAN. =cut =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, 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 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. Alien::Gnuplot development is at L. A major client module for Alien::Gnuplot is PDL::Graphics::Gnuplot, which can be found at L. PDL is at L. =head1 AUTHOR Craig DeForest (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 Alien-Gnuplot-1.033/lib/Alien/000755 000770 000000 00000000000 13054055537 016272 5ustar00zowiewheel000000 000000 Alien-Gnuplot-1.033/lib/Alien/Gnuplot.pm000644 000770 000000 00000023526 13054055464 020267 0ustar00zowiewheel000000 000000 =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, 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 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. Alien::Gnuplot development is at L. A major client module for Alien::Gnuplot is PDL::Graphics::Gnuplot, which can be found at L. PDL is at L. =head1 AUTHOR Craig DeForest (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. }; } } 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. }; } ############################## # 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 = ; 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;