File Coverage

alienfile
Criterion Covered Total %
statement 15 26 57.6
branch n/a
path n/a
condition n/a
subroutine 4 7 57.1
pod n/a
total 19 33 57.5


line stmt bran path cond sub pod time code
1 1       1   245271 use alienfile;
  1           3  
  1           10  
2                
3 1       1   211 use File::Which;
  1           2  
  1           53  
4 1       1   6 use version 0.77;
  1           41  
  1           10  
5                
6               for my $gnuplot (
7               ( $ENV{'GNUPLOT_BINARY'} ? $ENV{'GNUPLOT_BINARY'} : () ),
8               'gnuplot'
9               ) {
10               plugin 'Probe::CommandLine' => (
11               command => $gnuplot,
12               args => [ '--version' ],
13               match => qr/^gnuplot ([0-9\.]+ patchlevel [0-9]+)/,
14               version => qr/^gnuplot ([0-9\.]+ patchlevel [0-9]+)/,
15               );
16               }
17                
18               meta->around_hook( probe => sub {
19               my $orig = shift;
20               my $build = shift;
21                
22               eval {
23               unshift @INC, '../../lib', 'lib';
24               require Alien::Gnuplot;
25               };
26                
27               my $install_type = $orig->($build, @_);
28                
29               $build->log("Checking @{[ $build->runtime_prop->{command} ]}");
30               eval {
31               Alien::Gnuplot->check_gnuplot(
32               map { -f $_ ? $_ : which($_) } $build->runtime_prop->{command}
33               );
34               1;
35               } or do {
36               $build->log($@);
37               return 'share';
38               };
39                
40               # Fix up the version from output to include the patchlevel as a dotted
41               # version component.
42               if( exists $build->runtime_prop->{version} ) {
43               $build->runtime_prop->{version} =~ s/^([0-9\.]+) patchlevel ([0-9]+)$/$1.$2/;
44               }
45                
46               # Check against minimum version.
47               my $got_version = version->parse($build->runtime_prop->{version});
48               if( version->parse($Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION) > $got_version ) {
49               $build->log(<
50               Gnuplot seems to exist on your system, but it is version @{[ $build->runtime_prop->{version} ]}.
51               The minimum recommended version is $Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION.
52               EOF
53               return 'share';
54               } else {
55               $build->log(<
56               Gnuplot version $got_version meets minimum version
57               requirement of Gnuplot version $Alien::Gnuplot::GNUPLOT_RECOMMENDED_VERSION.
58               EOF
59               }
60                
61               {
62               # Check for Windows piped input bug.
63                
64               # Range (exclusive) where bug is present.
65               my @exclusive_range = map version->parse($_), ( '5.2.8', '5.4.6' );
66                
67               if( $^O eq 'MSWin32'
68               && $exclusive_range[0] < $got_version
69               && $got_version < $exclusive_range[1] ) {
70               $build->log(<
71               Gnuplot version $got_version on Windows has a known problem.
72                
73               Gnuplot between versions (@{[ join ", ", @exclusive_range ]}) exclusive fails
74               to work properly when given piped input. See
75               for more information.
76               EOF
77               return 'share';
78               }
79               }
80                
81               return $install_type;
82               });
83                
84                
85               # Separate hook after the above to give hints about installation to the system.
86               meta->around_hook( probe => sub {
87               my $orig = shift;
88               my $build = shift;
89                
90               my $install_type = $orig->($build, @_);
91                
92               # Map[ $^O, Tuple[ Name, Command, InstallCommand, Maybe[URL] ] ]
93               #
94               # NOTE: If the URL is defined, this is a self-installed package manager
95               # (i.e., for systems that do not come with a standard package manager), so
96               # print out its information regardless of whether it is installed.
97               my %os_installers = (
98               darwin => [
99               ['MacPorts','port', 'port install gnuplot', 'https://www.macports.org/'],
100               ['Fink' ,'fink', 'fink install gnuplot', 'https://www.finkproject.org/'],
101               ['Homebrew','brew', 'brew install gnuplot', 'https://brew.sh/'],
102               ],
103               linux => [
104               [ 'YUM', 'yum' , 'yum install gnuplot' , undef ],
105               [ 'APT', 'apt-get', 'apt-get install gnuplot', undef ],
106               ],
107               MSWin32 => [
108               ['Chocolatey', 'choco', 'choco install gnuplot', 'https://chocolatey.org/' ],
109               ],
110               );
111                
112               if( $install_type eq 'share' and exists $os_installers{$^O} ) {
113               $build->log(<
114                
115               Gnuplot seems to not exist on your system. You can use the following package
116               manager(s) to install Gnuplot to your system.
117                
118               EOF
119               for my $manager (@{ $os_installers{$^O} }) {
120               next if ! defined $manager->[3] && ! which( $manager->[1] );
121               $build->log(<
122               - $manager->[0]@{[ defined $manager->[3] ? " (available at <$manager->[3]>)" : "" ]}:
123               \$ $manager->[2]
124                
125               EOF
126               }
127               }
128                
129               return $install_type;
130               });
131                
132                
133               sub do_binary_release_mswin32 {
134 0       0   0 requires 'Alien::7zip' => '0.03';
135 0           0 requires 'Alien::Build::CommandSequence';
136                
137 0           0 start_url 'https://sourceforge.net/projects/gnuplot/files/gnuplot/5.4.6/gp546-win64-mingw-2.7z/download';
138 0           0 plugin 'Download';
139 0           0 extract [ '%{sevenzip} x %{.install.download}' ];
140 0           0 plugin 'Build::Copy';
141               gather sub {
142 0       0   0 my ($build) = @_;
143 0           0 $build->runtime_prop->{'style'} = 'binary';
144 0           0 };
145               }
146                
147               sub do_source_release {
148 1       1   5 start_url 'https://sourceforge.net/projects/gnuplot/files/gnuplot/5.4.6/gnuplot-5.4.6.tar.gz/download';
149 1           55 plugin 'Download';
150 1           178098 plugin 'Extract' => 'tar.gz';
151 1           85278 plugin 'Build::Autoconf';
152 1           11183 build [
153               '%{configure}',
154               '%{make}',
155               '%{make} install',
156               ];
157               gather sub {
158 0       0     my ($build) = @_;
159 0             $build->runtime_prop->{'style'} = 'source';
160 1           127 };
161               }
162                
163               share {
164               if( $^O eq 'MSWin32' ) {
165               do_binary_release_mswin32;
166               } else {
167               do_source_release;
168               }
169               }