@@ -5,104 +5,87 @@ use 5.006002;
55use strict;
66use warnings;
77
8- use Getopt::Long;
9- use version;
8+ use Config;
109
11- use constant THIS_PERL => version-> parse( $] );
12- use constant PERL_5_10 => version-> parse( ' v5.10.0' );
13- use constant PERL_5_10_1 => version-> parse( ' v5.10.1' );
14- use constant PERL_5_12 => version-> parse( ' v5.12.0' );
15-
16- unless ( caller ) {
17- my %opt ;
18-
19- GetOptions( \%opt ,
20- qw{ verbose } ,
21- ) or die " Bad option\n " ;
10+ our $VERSION = ' 2.000004' ;
2211
12+ use constant THIS_PERL => " $] " ;
2313
14+ unless ( caller ) {
2415 my $env_hash = compute_environment();
2516
2617 my $env_text ;
2718 $env_text .= " $_ =$env_hash ->{$_ }\n " for sort keys %{ $env_hash };
2819
29- $opt {verbose } and print $env_text ;
30-
31- defined $ENV {GITHUB_ENV }
32- and $ENV {GITHUB_ENV } ne ' '
33- or die " Environment variable GITHUB_ENV undefined or empty\n " ;
34- open my $fh , ' >>:encoding(utf-8)' , $ENV {GITHUB_ENV }
35- or die " Can not open $ENV {GITHUB_ENV}: $! \n " ;
36-
37- print { $fh } $env_text ;
38-
39- close $fh ;
20+ if ( defined ( $ENV {GITHUB_ENV } ) && $ENV {GITHUB_ENV } ne ' ' ) {
21+ open my $fh , ' >>:encoding(utf-8)' , $ENV {GITHUB_ENV }
22+ or die " Can not open $ENV {GITHUB_ENV}: $! \n " ;
23+ print { $fh } $env_text ;
24+ close $fh ;
25+ } else {
26+ print $env_text ;
27+ die " Environment variable GITHUB_ENV undefined or empty\n " ;
28+ }
4029}
4130
4231sub compute_environment {
4332 my $is_windows = {
4433 MSWin32 => 1,
4534 dos => 1,
4635 }-> {$^O} || ' ' ;
47- my $is_unix = $is_windows ? ' ' : 1;
48- my $my_home ;
36+ my %env = (
37+ MY_MAKE => $Config {make },
38+ MY_WANT_MODULES => join ( ' ' , want_modules() ),
39+ );
40+
4941 {
42+ # Finding the actual cpanm logs under Windows is a pain. $HOME
43+ # does not point to the right place, but
44+ # File::HomeDir->my_home() does. It turns out that under
45+ # Windows, the Portable module (another Adam Kennedy creation)
46+ # hooks itself into File::HomeDir. I don't know how it does its
47+ # magic, but it is NOT equivalent to File::HomeDir::Windows.
5048 local $@ = undef ;
49+ my $src ;
5150 eval {
5251 require File::HomeDir;
53- $my_home = File::HomeDir-> my_home();
54- print " Home from File::HomeDir\n " ;
52+ $env {MY_PORTABLE_HOME } = File::HomeDir-> my_home();
53+ # Windows seems to need a Posix path or bash glob doesn't
54+ # work.
55+ $is_windows
56+ and $env {MY_PORTABLE_HOME } =~ tr | \\| /| ;
57+ no warnings qw{ once } ;
58+ $src = $File::HomeDir::IMPLEMENTED_BY ;
5559 1;
5660 } or do {
57- $my_home = $ENV {HOME };
58- print " Home from \ $ HOME\n " ;
61+ $env { MY_PORTABLE_HOME } = $ENV {HOME };
62+ $src = ' $HOME' ;
5963 };
64+ print " MY_PORTABLE_HOME from $src is $env {MY_PORTABLE_HOME}\n " ;
6065 }
61- my @want_modules = want_modules();
62- my %env = (
63- MY_HOME => $my_home ,
64- MY_IS_GITHUB_ACTION => 1,
65- MY_IS_UNIX => $is_unix ,
66- MY_IS_WINDOWS => $is_windows ,
67- MY_TOOLCHAIN_EUMM => -e ' Makefile.PL' ? 1 : ' ' ,
68- MY_TOOLCHAIN_MB => -e ' Build.PL' ? 1 : ' ' ,
69- MY_WANT_MODULES => " @want_modules " ,
70- );
7166
7267 $is_windows
7368 and @env { qw{ LINES COLUMNS } } = ( 24, 80 );
7469
7570 return \%env ;
7671}
7772
78- # FIXME Not all my distros need HTML-Tagset. Figure out a way to handle
79- # this other than by bashing this script. This is not straightforward
80- # because HTML-Tagset is probably not a direct dependency .
73+ # NOTE that we rely on the templating system's perl::Type module to
74+ # compute recursive dependencies to figure out which possibly-indirect
75+ # dependencies we need to handle under old Perls .
8176sub want_modules {
8277 my ( $perl_ver ) = @_ ;
8378 defined $perl_ver
8479 or $perl_ver = THIS_PERL;
85- if ( $perl_ver >= PERL_5_12 ) {
86- return ;
87- } elsif ( $perl_ver >= PERL_5_10_1 ) {
88- # NOTE that, thus far, XSLoader, Test-Deep, and Perl-Critic are
89- # only needed for Perl-Critic policies, and maybe not all of
90- # those.
91- # NOTE that, thus far, HTML-Tagset is only needed for modules
92- # that make use of libwww-perl, directly or indirectly.
93- return qw{
94- RRA/podlators-4.14.tar.gz
95- } ;
96- } elsif ( $perl_ver >= PERL_5_10 ) {
97- return qw{
98- RRA/podlators-4.14.tar.gz
99- } ;
100- } else {
101- return qw{
102- SMUELLER/ExtUtils-ParseXS-3.30.tar.gz
103- RRA/podlators-4.14.tar.gz
104- } ;
80+ foreach (
81+ [ qw{ 5.010001 } ],
82+ [
qw{ 5.000000 [email protected] } ],
83+ ) {
84+ my ( $version , @want ) = @{ $_ };
85+ $perl_ver >= $version
86+ and return @want ;
10587 }
88+ die " Bug - Unsupported perl version $] " ;
10689}
10790
108911;
@@ -116,42 +99,27 @@ environment.PL - Customize GitHub Actions environment
11699=head1 SYNOPSIS
117100
118101 .github/workflows/environment.PL
119- .github/workflows/environment.PL --verbose
120102
121103=head1 OPTIONS
122104
123- =head2 --verbose
124-
125- If this Boolean option is asserted, the environment variables defiend
126- are written to standard output.
127-
128- The default is C<--no-verbose > .
105+ None.
129106
130107=head1 DETAILS
131108
132109This Perl script adds environment variables to the GitHub Actions
133110environment. The following environment variables are added:
134111
135- =head2 MY_HOME
136-
137- The job's home directory, as determined by
138- L<File::HomeDir|File::HomeDir> .
139-
140- =head2 MY_IS_GITHUB_ACTION
112+ =head2 COLUMNS
141113
142- Always true (i.e. C<'1' > ) .
114+ Windows only. C<'80' > .
143115
144- =head2 MY_IS_UNIX
116+ =head2 LINES
145117
146- True (i.e. C<1 > ) if running under some flavor of Unix, and false (i.e.
147- C<'' > ) otherwise. At the moment this is the Boolean inverse of
148- L<MY_IS_WINDOWS|/MY_IS_WINDOWS> .
118+ Windows only. C<'24' > .
149119
150- =head2 MY_IS_WINDOWS
120+ =head2 MY_MAKE
151121
152- True (i.e. C<1 > ) if running under Windows, and false (i.e. C<'' > )
153- othewise. At the moment this is true if C<$^O > is C<'MSWin32' > or
154- C<'dos' > .
122+ The value of C<$Config{make} > .
155123
156124=head2 MY_WANT_MODUKES
157125
@@ -173,19 +141,18 @@ that describes the environment variables to be added to the environment.
173141
174142=head2 want_modules
175143
176- This subroutine takes an optional L<version|version> object representing
177- a Perl version, and returns a list of modules or distributions to be
178- installed that version B<before > module prerequisites are
179- processed. If no argument is provided, the version of the
180- currently-running Perl is assumed.
144+ This subroutine takes an optional Perl version, and returns a list of
145+ modules or distributions to be installed that version B<before > module
146+ prerequisites are processed. If no argument is provided, the version of
147+ the currently-running Perl is assumed.
181148
182149=head1 AUTHOR
183150
184151Thomas R. Wyant, III F<wyant at cpan dot org>
185152
186153=head1 COPYRIGHT AND LICENSE
187154
188- Copyright (C) 2022 by Thomas R. Wyant, III
155+ Copyright (C) 2025 by Thomas R. Wyant, III
189156
190157This program is free software; you can redistribute it and/or modify it
191158under the same terms as Perl 5.10.0. For more details, see the full text
0 commit comments