├── .github └── workflows │ └── windows.yml ├── .gitignore ├── Changes ├── LICENSE ├── README.md ├── helpfile.txt ├── psperl.ps1 ├── src └── PSPerl.ps1 └── t └── basic.t /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: windows 2 | on: 3 | push: 4 | branches: 5 | - '*' 6 | tags-ignore: 7 | - '*' 8 | pull_request: 9 | 10 | jobs: 11 | Test-PSPerl: 12 | runs-on: windows-latest 13 | strategy: 14 | fail-fast: true 15 | steps: 16 | - name: Set git to use LF 17 | run: | 18 | git config --global core.autocrlf false 19 | git config --global core.eol lf 20 | - uses: actions/checkout@v2 21 | - name: psperl -Setup 22 | run: .\psperl.ps1 -Setup 23 | - name: psperl -Init 24 | run: .\psperl.ps1 -Init 25 | - name: psperl -Version 26 | run: .\psperl.ps1 -Version 27 | - name: psperl -Available 28 | run: psperl -Available 29 | - name: psperl -Install perl64-5.30.1.1 30 | run: psperl -Install perl64-5.30.1.1 31 | - name: psperl -Switch perl64-5.30.1.1 32 | run: psperl -Switch perl64-5.30.1.1 33 | - name: perl -V 34 | run: perl -V 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | project.lock.json 4 | *-tests.xml 5 | /debug/ 6 | /staging/ 7 | /Packages/ 8 | *.nuget.props 9 | /_config/ 10 | /_zips/ 11 | /_perls/ 12 | /_libs/ 13 | /_locals/ 14 | 15 | # dotnet cli install/uninstall scripts 16 | dotnet-install.ps1 17 | dotnet-install.sh 18 | dotnet-uninstall-pkgs.sh 19 | dotnet-uninstall-debian-packages.sh 20 | 21 | # VS auto-generated solution files for project.json solutions 22 | *.xproj 23 | *.xproj.user 24 | *.suo 25 | 26 | # VS auto-generated files for csproj files 27 | *.csproj.user 28 | 29 | # Visual Studio IDE directory 30 | .vs/ 31 | 32 | # VSCode directories that are not at the repository root 33 | /**/.vscode/ 34 | 35 | # Project Rider IDE files 36 | .idea.powershell/ 37 | 38 | # Ignore executables 39 | *.exe 40 | *.msi 41 | *.appx 42 | *.msix 43 | 44 | # Ignore binaries and symbols 45 | *.pdb 46 | *.dll 47 | *.wixpdb 48 | 49 | # Ignore packages 50 | *.deb 51 | *.tar.gz 52 | *.zip 53 | *.rpm 54 | *.pkg 55 | *.nupkg 56 | *.AppImage 57 | 58 | # default location for produced nuget packages 59 | /nuget-artifacts 60 | 61 | # resgen output 62 | gen 63 | 64 | # Per repo profile 65 | .profile.ps1 66 | 67 | # macOS 68 | .DS_Store 69 | .DocumentRevisions-V100 70 | .fseventsd 71 | .Spotlight-V100 72 | .TemporaryItems 73 | .Trashes 74 | .VolumeIcon.icns 75 | .com.apple.timemachine.donotpresent 76 | .AppleDB 77 | .AppleDesktop 78 | Network Trash Folder 79 | Temporary Items 80 | .apdisk 81 | .AppleDouble 82 | .LSOverride 83 | 84 | # TestsResults 85 | TestsResults*.xml 86 | ParallelXUnitResults.xml 87 | 88 | # Resharper settings 89 | PowerShell.sln.DotSettings.user 90 | *.msp 91 | StyleCop.Cache 92 | 93 | # Ignore SelfSignedCertificate autogenerated files 94 | test/tools/Modules/SelfSignedCertificate/ 95 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | Changes log for PSPerl 2 | 3 | 0.1.2 2021 4 | 5 | 0.1.1 2021-04-14 6 | * Removed TravisCI testing 7 | * Altered the Setup() method to create the directory for the 8 | $Profile if it doesn't yet exist 9 | * Created a GitHub Workflow for testing purposes 10 | * Reverted to https://strawberryperl.com/releases.json 11 | 12 | 0.1.0 2020-06-29 13 | * Switch to https://strawberry.perl.bot/releases.json 14 | - Gets us HTTPS, and it's faster than strawberryperl.com 15 | * Add a -Version or -V command to show version information 16 | * Begin some structure for creating a -Local or -Lib command 17 | to deal with local::lib 18 | * Get some tags/releases back-filled 19 | * Added the Changes log 20 | 21 | 0.0.2 2020-04-30 22 | * Store the current version we're running in the environment 23 | * Fix for non-English Windows installs (thanks xenu) 24 | * Fix for error handling (thanks xenu) 25 | 26 | 0.0.1 2020-03-18 27 | * Initial Release: 28 | * psperl -Available 29 | * psperl -Init 30 | * psperl -List 31 | * psperl -Install 32 | * psperl -Use 33 | * psperl -Switch 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is copyright (c) 2019 by Chase Whitener. 2 | 3 | This is free software; you can redistribute it and/or modify it under 4 | the same terms as the Perl 5 programming language system itself. 5 | 6 | Terms of the Perl programming language system itself 7 | 8 | a) the GNU General Public License as published by the Free 9 | Software Foundation; either version 1, or (at your option) any 10 | later version, or 11 | b) the "Artistic License" 12 | 13 | --- The GNU General Public License, Version 1, February 1989 --- 14 | 15 | This software is Copyright (c) 2019 by Chase Whitener. 16 | 17 | This is free software, licensed under: 18 | 19 | The GNU General Public License, Version 1, February 1989 20 | 21 | GNU GENERAL PUBLIC LICENSE 22 | Version 1, February 1989 23 | 24 | Copyright (C) 1989 Free Software Foundation, Inc. 25 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | 27 | Everyone is permitted to copy and distribute verbatim copies 28 | of this license document, but changing it is not allowed. 29 | 30 | Preamble 31 | 32 | The license agreements of most software companies try to keep users 33 | at the mercy of those companies. By contrast, our General Public 34 | License is intended to guarantee your freedom to share and change free 35 | software--to make sure the software is free for all its users. The 36 | General Public License applies to the Free Software Foundation's 37 | software and to any other program whose authors commit to using it. 38 | You can use it for your programs, too. 39 | 40 | When we speak of free software, we are referring to freedom, not 41 | price. Specifically, the General Public License is designed to make 42 | sure that you have the freedom to give away or sell copies of free 43 | software, that you receive source code or can get it if you want it, 44 | that you can change the software or use pieces of it in new free 45 | programs; and that you know you can do these things. 46 | 47 | To protect your rights, we need to make restrictions that forbid 48 | anyone to deny you these rights or to ask you to surrender the rights. 49 | These restrictions translate to certain responsibilities for you if you 50 | distribute copies of the software, or if you modify it. 51 | 52 | For example, if you distribute copies of a such a program, whether 53 | gratis or for a fee, you must give the recipients all the rights that 54 | you have. You must make sure that they, too, receive or can get the 55 | source code. And you must tell them their rights. 56 | 57 | We protect your rights with two steps: (1) copyright the software, and 58 | (2) offer you this license which gives you legal permission to copy, 59 | distribute and/or modify the software. 60 | 61 | Also, for each author's protection and ours, we want to make certain 62 | that everyone understands that there is no warranty for this free 63 | software. If the software is modified by someone else and passed on, we 64 | want its recipients to know that what they have is not the original, so 65 | that any problems introduced by others will not reflect on the original 66 | authors' reputations. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | GNU GENERAL PUBLIC LICENSE 72 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 73 | 74 | 0. This License Agreement applies to any program or other work which 75 | contains a notice placed by the copyright holder saying it may be 76 | distributed under the terms of this General Public License. The 77 | "Program", below, refers to any such program or work, and a "work based 78 | on the Program" means either the Program or any work containing the 79 | Program or a portion of it, either verbatim or with modifications. Each 80 | licensee is addressed as "you". 81 | 82 | 1. You may copy and distribute verbatim copies of the Program's source 83 | code as you receive it, in any medium, provided that you conspicuously and 84 | appropriately publish on each copy an appropriate copyright notice and 85 | disclaimer of warranty; keep intact all the notices that refer to this 86 | General Public License and to the absence of any warranty; and give any 87 | other recipients of the Program a copy of this General Public License 88 | along with the Program. You may charge a fee for the physical act of 89 | transferring a copy. 90 | 91 | 2. You may modify your copy or copies of the Program or any portion of 92 | it, and copy and distribute such modifications under the terms of Paragraph 93 | 1 above, provided that you also do the following: 94 | 95 | a) cause the modified files to carry prominent notices stating that 96 | you changed the files and the date of any change; and 97 | 98 | b) cause the whole of any work that you distribute or publish, that 99 | in whole or in part contains the Program or any part thereof, either 100 | with or without modifications, to be licensed at no charge to all 101 | third parties under the terms of this General Public License (except 102 | that you may choose to grant warranty protection to some or all 103 | third parties, at your option). 104 | 105 | c) If the modified program normally reads commands interactively when 106 | run, you must cause it, when started running for such interactive use 107 | in the simplest and most usual way, to print or display an 108 | announcement including an appropriate copyright notice and a notice 109 | that there is no warranty (or else, saying that you provide a 110 | warranty) and that users may redistribute the program under these 111 | conditions, and telling the user how to view a copy of this General 112 | Public License. 113 | 114 | d) You may charge a fee for the physical act of transferring a 115 | copy, and you may at your option offer warranty protection in 116 | exchange for a fee. 117 | 118 | Mere aggregation of another independent work with the Program (or its 119 | derivative) on a volume of a storage or distribution medium does not bring 120 | the other work under the scope of these terms. 121 | 122 | 3. You may copy and distribute the Program (or a portion or derivative of 123 | it, under Paragraph 2) in object code or executable form under the terms of 124 | Paragraphs 1 and 2 above provided that you also do one of the following: 125 | 126 | a) accompany it with the complete corresponding machine-readable 127 | source code, which must be distributed under the terms of 128 | Paragraphs 1 and 2 above; or, 129 | 130 | b) accompany it with a written offer, valid for at least three 131 | years, to give any third party free (except for a nominal charge 132 | for the cost of distribution) a complete machine-readable copy of the 133 | corresponding source code, to be distributed under the terms of 134 | Paragraphs 1 and 2 above; or, 135 | 136 | c) accompany it with the information you received as to where the 137 | corresponding source code may be obtained. (This alternative is 138 | allowed only for noncommercial distribution and only if you 139 | received the program in object code or executable form alone.) 140 | 141 | Source code for a work means the preferred form of the work for making 142 | modifications to it. For an executable file, complete source code means 143 | all the source code for all modules it contains; but, as a special 144 | exception, it need not include source code for modules which are standard 145 | libraries that accompany the operating system on which the executable 146 | file runs, or for standard header files or definitions files that 147 | accompany that operating system. 148 | 149 | 4. You may not copy, modify, sublicense, distribute or transfer the 150 | Program except as expressly provided under this General Public License. 151 | Any attempt otherwise to copy, modify, sublicense, distribute or transfer 152 | the Program is void, and will automatically terminate your rights to use 153 | the Program under this License. However, parties who have received 154 | copies, or rights to use copies, from you under this General Public 155 | License will not have their licenses terminated so long as such parties 156 | remain in full compliance. 157 | 158 | 5. By copying, distributing or modifying the Program (or any work based 159 | on the Program) you indicate your acceptance of this license to do so, 160 | and all its terms and conditions. 161 | 162 | 6. Each time you redistribute the Program (or any work based on the 163 | Program), the recipient automatically receives a license from the original 164 | licensor to copy, distribute or modify the Program subject to these 165 | terms and conditions. You may not impose any further restrictions on the 166 | recipients' exercise of the rights granted herein. 167 | 168 | 7. The Free Software Foundation may publish revised and/or new versions 169 | of the General Public License from time to time. Such new versions will 170 | be similar in spirit to the present version, but may differ in detail to 171 | address new problems or concerns. 172 | 173 | Each version is given a distinguishing version number. If the Program 174 | specifies a version number of the license which applies to it and "any 175 | later version", you have the option of following the terms and conditions 176 | either of that version or of any later version published by the Free 177 | Software Foundation. If the Program does not specify a version number of 178 | the license, you may choose any version ever published by the Free Software 179 | Foundation. 180 | 181 | 8. If you wish to incorporate parts of the Program into other free 182 | programs whose distribution conditions are different, write to the author 183 | to ask for permission. For software which is copyrighted by the Free 184 | Software Foundation, write to the Free Software Foundation; we sometimes 185 | make exceptions for this. Our decision will be guided by the two goals 186 | of preserving the free status of all derivatives of our free software and 187 | of promoting the sharing and reuse of software generally. 188 | 189 | NO WARRANTY 190 | 191 | 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 192 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 193 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 194 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 195 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 196 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 197 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 198 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 199 | REPAIR OR CORRECTION. 200 | 201 | 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 202 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 203 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 204 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 205 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 206 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 207 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 208 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 209 | POSSIBILITY OF SUCH DAMAGES. 210 | 211 | END OF TERMS AND CONDITIONS 212 | 213 | Appendix: How to Apply These Terms to Your New Programs 214 | 215 | If you develop a new program, and you want it to be of the greatest 216 | possible use to humanity, the best way to achieve this is to make it 217 | free software which everyone can redistribute and change under these 218 | terms. 219 | 220 | To do so, attach the following notices to the program. It is safest to 221 | attach them to the start of each source file to most effectively convey 222 | the exclusion of warranty; and each file should have at least the 223 | "copyright" line and a pointer to where the full notice is found. 224 | 225 | 226 | Copyright (C) 19yy 227 | 228 | This program is free software; you can redistribute it and/or modify 229 | it under the terms of the GNU General Public License as published by 230 | the Free Software Foundation; either version 1, or (at your option) 231 | any later version. 232 | 233 | This program is distributed in the hope that it will be useful, 234 | but WITHOUT ANY WARRANTY; without even the implied warranty of 235 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 236 | GNU General Public License for more details. 237 | 238 | You should have received a copy of the GNU General Public License 239 | along with this program; if not, write to the Free Software 240 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA 241 | 242 | 243 | Also add information on how to contact you by electronic and paper mail. 244 | 245 | If the program is interactive, make it output a short notice like this 246 | when it starts in an interactive mode: 247 | 248 | Gnomovision version 69, Copyright (C) 19xx name of author 249 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 250 | This is free software, and you are welcome to redistribute it 251 | under certain conditions; type `show c' for details. 252 | 253 | The hypothetical commands `show w' and `show c' should show the 254 | appropriate parts of the General Public License. Of course, the 255 | commands you use may be called something other than `show w' and `show 256 | c'; they could even be mouse-clicks or menu items--whatever suits your 257 | program. 258 | 259 | You should also get your employer (if you work as a programmer) or your 260 | school, if any, to sign a "copyright disclaimer" for the program, if 261 | necessary. Here a sample; alter the names: 262 | 263 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 264 | program `Gnomovision' (a program to direct compilers to make passes 265 | at assemblers) written by James Hacker. 266 | 267 | , 1 April 1989 268 | Ty Coon, President of Vice 269 | 270 | That's all there is to it! 271 | 272 | 273 | --- The Artistic License 1.0 --- 274 | 275 | This software is Copyright (c) 2019 by Chase Whitener. 276 | 277 | This is free software, licensed under: 278 | 279 | The Artistic License 1.0 280 | 281 | The Artistic License 282 | 283 | Preamble 284 | 285 | The intent of this document is to state the conditions under which a Package 286 | may be copied, such that the Copyright Holder maintains some semblance of 287 | artistic control over the development of the package, while giving the users of 288 | the package the right to use and distribute the Package in a more-or-less 289 | customary fashion, plus the right to make reasonable modifications. 290 | 291 | Definitions: 292 | 293 | - "Package" refers to the collection of files distributed by the Copyright 294 | Holder, and derivatives of that collection of files created through 295 | textual modification. 296 | - "Standard Version" refers to such a Package if it has not been modified, 297 | or has been modified in accordance with the wishes of the Copyright 298 | Holder. 299 | - "Copyright Holder" is whoever is named in the copyright or copyrights for 300 | the package. 301 | - "You" is you, if you're thinking about copying or distributing this Package. 302 | - "Reasonable copying fee" is whatever you can justify on the basis of media 303 | cost, duplication charges, time of people involved, and so on. (You will 304 | not be required to justify it to the Copyright Holder, but only to the 305 | computing community at large as a market that must bear the fee.) 306 | - "Freely Available" means that no fee is charged for the item itself, though 307 | there may be fees involved in handling the item. It also means that 308 | recipients of the item may redistribute it under the same conditions they 309 | received it. 310 | 311 | 1. You may make and give away verbatim copies of the source form of the 312 | Standard Version of this Package without restriction, provided that you 313 | duplicate all of the original copyright notices and associated disclaimers. 314 | 315 | 2. You may apply bug fixes, portability fixes and other modifications derived 316 | from the Public Domain or from the Copyright Holder. A Package modified in such 317 | a way shall still be considered the Standard Version. 318 | 319 | 3. You may otherwise modify your copy of this Package in any way, provided that 320 | you insert a prominent notice in each changed file stating how and when you 321 | changed that file, and provided that you do at least ONE of the following: 322 | 323 | a) place your modifications in the Public Domain or otherwise make them 324 | Freely Available, such as by posting said modifications to Usenet or an 325 | equivalent medium, or placing the modifications on a major archive site 326 | such as ftp.uu.net, or by allowing the Copyright Holder to include your 327 | modifications in the Standard Version of the Package. 328 | 329 | b) use the modified Package only within your corporation or organization. 330 | 331 | c) rename any non-standard executables so the names do not conflict with 332 | standard executables, which must also be provided, and provide a separate 333 | manual page for each non-standard executable that clearly documents how it 334 | differs from the Standard Version. 335 | 336 | d) make other distribution arrangements with the Copyright Holder. 337 | 338 | 4. You may distribute the programs of this Package in object code or executable 339 | form, provided that you do at least ONE of the following: 340 | 341 | a) distribute a Standard Version of the executables and library files, 342 | together with instructions (in the manual page or equivalent) on where to 343 | get the Standard Version. 344 | 345 | b) accompany the distribution with the machine-readable source of the Package 346 | with your modifications. 347 | 348 | c) accompany any non-standard executables with their corresponding Standard 349 | Version executables, giving the non-standard executables non-standard 350 | names, and clearly documenting the differences in manual pages (or 351 | equivalent), together with instructions on where to get the Standard 352 | Version. 353 | 354 | d) make other distribution arrangements with the Copyright Holder. 355 | 356 | 5. You may charge a reasonable copying fee for any distribution of this 357 | Package. You may charge any fee you choose for support of this Package. You 358 | may not charge a fee for this Package itself. However, you may distribute this 359 | Package in aggregate with other (possibly commercial) programs as part of a 360 | larger (possibly commercial) software distribution provided that you do not 361 | advertise this Package as a product of your own. 362 | 363 | 6. The scripts and library files supplied as input to or produced as output 364 | from the programs of this Package do not automatically fall under the copyright 365 | of this Package, but belong to whomever generated them, and may be sold 366 | commercially, and may be aggregated with this Package. 367 | 368 | 7. C or perl subroutines supplied by you and linked into this Package shall not 369 | be considered part of this Package. 370 | 371 | 8. The name of the Copyright Holder may not be used to endorse or promote 372 | products derived from this software without specific prior written permission. 373 | 374 | 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 375 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 376 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 377 | 378 | The End 379 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/genio/psperl.svg?branch=master)](https://travis-ci.org/genio/psperl) 2 | 3 | # NAME 4 | 5 | PSPerl - Manage Strawberry Perl (Portable) installations in your $env:HOMEPATH 6 | 7 | # SYNOPSIS 8 | 9 | A typical install, selection, and use case would look something like this: 10 | 11 | ```PowerShell 12 | PS C:\Users\genio> git clone https://github.com/genio/psperl.git _psperl 13 | PS C:\Users\genio> cd _psperl 14 | PS C:\Users\genio\_psperl> .\psperl.ps1 -Setup 15 | PS C:\Users\genio\_psperl> .\psperl.ps1 -Init 16 | PS C:\Users\genio\_psperl> cd .. 17 | PS C:\Users\genio> psperl -Available 18 | ... 19 | PS C:\Users\genio> psperl -Install perl64-5.30.0.1 20 | PS C:\Users\genio> psperl -Switch perl64-5.30.0.1 21 | PS C:\Users\genio> perl -v 22 | 23 | This is perl 5, version 30, subversion 0 (v5.30.0) built for MSWin32-x86-multi-thread-64int 24 | 25 | Copyright 1987-2019, Larry Wall 26 | 27 | Perl may be copied only under the terms of either the Artistic License or the 28 | GNU General Public License, which may be found in the Perl 5 source kit. 29 | 30 | Complete documentation for Perl, including FAQ lists, should be found on 31 | this system using "man perl" or "perldoc perl". If you have access to the 32 | Internet, point your browser at http://www.perl.org/, the Perl Home Page. 33 | 34 | PS C:\Users\genio> 35 | ``` 36 | 37 | Then, every subsequent time you load up PowerShell, you can forego the installation, etc. 38 | 39 | ```PowerShell 40 | PS C:\Users\genio> perl -v 41 | 42 | This is perl 5, version 30, subversion 0 (v5.30.0) built for MSWin32-x86-multi-thread-64int 43 | 44 | Copyright 1987-2019, Larry Wall 45 | 46 | Perl may be copied only under the terms of either the Artistic License or the 47 | GNU General Public License, which may be found in the Perl 5 source kit. 48 | 49 | Complete documentation for Perl, including FAQ lists, should be found on 50 | this system using "man perl" or "perldoc perl". If you have access to the 51 | Internet, point your browser at http://www.perl.org/, the Perl Home Page. 52 | 53 | PS C:\Users\genio> 54 | ``` 55 | 56 | # INSTALLATION 57 | 58 | ```PowerShell 59 | git clone https://github.com/genio/psperl.git 60 | cd psperl 61 | .\psperl.ps1 -Setup 62 | ``` 63 | 64 | Setting things up couldn't be easier. Basically, all you need to do is check out this repository or download it as a .zip file and extract it somewhere. Once you have it sitting in some folder, navigate to that folder in PowerShell and run the setup command: `.\psperl.ps1 -Setup`. 65 | 66 | That will open your `$Profile` and add the following lines: 67 | ```PowerShell 68 | # PSPerl Initialize 69 | & C:\Users\genio\_psperl\psperl.ps1 -Init 70 | ``` 71 | 72 | That addition to your profile will handle ensuring that PSPerl is always in your PowerShell's `$env:Path` environment variable. From that point, you could just run `psperl -available` to get a list of available Portable [Strawberry Perls](http://strawberryperl.com) to install. 73 | 74 | # DESCRIPTION 75 | 76 | [Strawberry Perl](http://strawberryperl.com) is a Perl built to run on Windows. It's a vanilla Perl install that the Perl community has put together so that you don't have to go through the hassle of trying to get all of the prerequisites and other things necessary to build Perl yourself done. 77 | 78 | Thank you, Strawberry Perl! 79 | 80 | # COMMANDS 81 | 82 | PSPerl has a few commands to help you through the process of getting a working version of Perl installed. 83 | 84 | ## Available 85 | 86 | ```PowerShell 87 | psperl -Available # Shows you a list of all available installations 88 | psperl -Available -major 10 # shows you a list of all Perls available on v5.10 89 | ``` 90 | 91 | The `Available` command will grab the list of releases from [Strawberry Perl's JSON file](http://strawberryperl.com/releases.json) and parse out which releases are available in Portable form -release types found [here](http://strawberryperl.com/releases.html). The information coming from Strawberry Perl's site will be cached locally on your hard drive as a JSON file that we will use from that point on so we don't hit their servers too often and to speed up your experience. This local cache will time out after an hour and a half, at which time we'll grab another copy from Strawberry's site. 92 | 93 | It will spit out a list of all of the Perl versions you can install for use on your installation combination of Windows and PowerShell. This part is a bit different from other brew-style installers because we try to account for your `64-bit` vs `32-bit` vs `32-bit with USE_64_BIT_INT`. 94 | 95 | ### 64-bit Windows, 64-bit PowerShell 96 | 97 | This is what you could expect to see on this platform: 98 | 99 | ```PowerShell 100 | PS C:\Users\genio> psperl -Available 101 | We're using a 64-bit PowerShell on a 64-bit Windows OS. 102 | On 64-bit Windows: 103 | 32-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT Perls without problem. 104 | You _can_ use 64-bit Perls, but may run into trouble. RISK 105 | 64-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT, or 64-bit Perls. 106 | On 32-bit Windows: 107 | You can only use 32-bit or 32-bit with USE_64_BIT_INT Perls 108 | 109 | The current release for each major Perl: 110 | 111 | 64-bit Perls: 112 | - perl64-5.30.0.1 113 | - perl64-5.28.2.1 114 | - perl64-5.26.3.1 115 | - perl64-5.24.4.1 116 | - perl64-5.22.3.1 117 | - perl64-5.20.3.3 118 | - perl64-5.18.4.1 119 | - perl64-5.16.3.1 120 | - perl64-5.14.4.1 121 | 122 | 32-bit with USE_64_BIT_INT Perls: 123 | - perl32w64int-5.30.0.1 124 | - perl32w64int-5.28.2.1 125 | - perl32w64int-5.26.3.1 126 | - perl32w64int-5.24.4.1 127 | - perl32w64int-5.22.3.1 128 | - perl32w64int-5.20.3.3 129 | - perl32w64int-5.18.4.1 130 | 131 | 32-bit Perls: 132 | - perl32-5.30.0.1 133 | - perl32-5.28.2.1 134 | - perl32-5.26.3.1 135 | - perl32-5.24.4.1 136 | - perl32-5.22.3.1 137 | - perl32-5.20.3.3 138 | - perl32-5.18.4.1 139 | - perl32-5.16.3.1 140 | - perl32-5.14.4.1 141 | - perl32-5.12.3.0 142 | - perl32-5.10.1.2 143 | 144 | PS C:\Users\genio> 145 | ``` 146 | 147 | ### 64-bit Windows, 32-bit PowerShell 148 | 149 | This is what you could expect to see on this platform: 150 | 151 | ```PowerShell 152 | PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> psperl -Available 153 | We're using a 32-bit PowerShell on a 64-bit Windows OS. 154 | On 64-bit Windows: 155 | 32-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT Perls without problem. 156 | You _can_ use 64-bit Perls, but may run into trouble. RISK 157 | 64-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT, or 64-bit Perls. 158 | On 32-bit Windows: 159 | You can only use 32-bit or 32-bit with USE_64_BIT_INT Perls 160 | 161 | The current release for each major Perl: 162 | 163 | 64-bit Perls (RISKY on a 32-bit PS): 164 | - perl64-5.30.0.1 165 | - perl64-5.28.2.1 166 | - perl64-5.26.3.1 167 | - perl64-5.24.4.1 168 | - perl64-5.22.3.1 169 | - perl64-5.20.3.3 170 | - perl64-5.18.4.1 171 | - perl64-5.16.3.1 172 | - perl64-5.14.4.1 173 | 174 | 32-bit with USE_64_BIT_INT Perls: 175 | - perl32w64int-5.30.0.1 176 | - perl32w64int-5.28.2.1 177 | - perl32w64int-5.26.3.1 178 | - perl32w64int-5.24.4.1 179 | - perl32w64int-5.22.3.1 180 | - perl32w64int-5.20.3.3 181 | - perl32w64int-5.18.4.1 182 | 183 | 32-bit Perls: 184 | - perl32-5.30.0.1 185 | - perl32-5.28.2.1 186 | - perl32-5.26.3.1 187 | - perl32-5.24.4.1 188 | - perl32-5.22.3.1 189 | - perl32-5.20.3.3 190 | - perl32-5.18.4.1 191 | - perl32-5.16.3.1 192 | - perl32-5.14.4.1 193 | - perl32-5.12.3.0 194 | - perl32-5.10.1.2 195 | 196 | PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> 197 | ``` 198 | 199 | ### 32-bit Windows 200 | And, finally, on this platform, you'd see: 201 | 202 | ```PowerShell 203 | PS C:\Users\genio> psperl -Available 204 | We're using a 32-bit PowerShell on a 32-bit Windows OS. 205 | On 64-bit Windows: 206 | 32-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT Perls without problem. 207 | You _can_ use 64-bit Perls, but may run into trouble. RISK 208 | 64-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT, or 64-bit Perls. 209 | On 32-bit Windows: 210 | You can only use 32-bit or 32-bit with USE_64_BIT_INT Perls 211 | 212 | The current release for each major Perl: 213 | 214 | 32-bit with USE_64_BIT_INT Perls: 215 | - perl32w64int-5.30.0.1 216 | - perl32w64int-5.28.2.1 217 | - perl32w64int-5.26.3.1 218 | - perl32w64int-5.24.4.1 219 | - perl32w64int-5.22.3.1 220 | - perl32w64int-5.20.3.3 221 | - perl32w64int-5.18.4.1 222 | 223 | 32-bit Perls: 224 | - perl32-5.30.0.1 225 | - perl32-5.28.2.1 226 | - perl32-5.26.3.1 227 | - perl32-5.24.4.1 228 | - perl32-5.22.3.1 229 | - perl32-5.20.3.3 230 | - perl32-5.18.4.1 231 | - perl32-5.16.3.1 232 | - perl32-5.14.4.1 233 | - perl32-5.12.3.0 234 | - perl32-5.10.1.2 235 | 236 | PS C:\Users\genio> 237 | ``` 238 | 239 | 240 | 241 | 242 | 243 | ## Install 244 | 245 | ```PowerShell 246 | PS C:\Users\genio> psperl -Install perl64-5.30.0.1 247 | PS C:\Users\genio> psperl -Install perl32w64int-5.30.0.1 248 | PS C:\Users\genio> psperl -Install perl32-5.30.0.1 249 | ``` 250 | 251 | Once you've selected which version of Perl you'd like to use from the list supplied in the `Available` command, you'd just need to install it. 252 | 253 | This command will download the Portable Perl zip file from Strawberry Perl's site and store it locally in the `_zips` directory. It will then check that we got the expected file size and SHA1 checksum match. If it's not the right size or checksum, we'll remove the zip file and fail. 254 | 255 | Given that we have the right file, we'll extract the zip file into your `_perls` directory. If we're installing `perl32w64int-5.30.0.1` then the path to that Perl would be `psperl_home_dir\_perls\perl32w64int-5.30.0.1`. So, if you installed PSPerl in `C:\Users\genio\_psperl`, the full path to that directory would be `C:\Users\genio\_psperl\_perls\perl32w64int-5.30.0.1`. 256 | 257 | Just installing the version of Perl does _not_ make it ready for you to use immediately. This is simply because you may not yet want to work on that version. If you're using v5.30 and wanted to install another version, say v5.28, to test with, you can install that new version but you'd still be on v5.30 until you decide to change it with the `Use` or `Switch` commands. 258 | 259 | ## List 260 | 261 | ```PowerShell 262 | PS C:\Users\genio> psperl -List # Shows you a list of the Perls you have 263 | ``` 264 | 265 | The `List` command will show you a listing of which Perls you currently have installed. 266 | 267 | 268 | ### Switch 269 | 270 | ```PowerShell 271 | PS C:\Users\genio> psperl -Switch perl64-5.30.0.1 272 | PS C:\Users\genio> psperl -Switch perl32w64int-5.30.0.1 273 | PS C:\Users\genio> psperl -Switch perl32-5.30.0.1 274 | ``` 275 | 276 | The `Switch` command can be used to change your current environment setup to use any version of Perl we've already installed. This will be made persistent as we'll store the current version in our local config directory and every time you start a PowerShell session, we'll setup your environment for the selected version of Perl. 277 | 278 | You can change which Perl you're using as many times as you'd like during a session, though you can only use one Perl at a time. 279 | 280 | ### Use 281 | 282 | ```PowerShell 283 | PS C:\Users\genio> psperl -Use perl64-5.30.0.1 284 | PS C:\Users\genio> psperl -Use perl32w64int-5.30.0.1 285 | PS C:\Users\genio> psperl -Use perl32-5.30.0.1 286 | ``` 287 | 288 | The `Use` command works almost exactly as the `Switch` command does, but it isn't persistent. With this command, we just start using a different version of Perl, but we haven't switched our preference to that one. If my current preference is Perl v5.28 and it's what I have setup to start on my PowerShell sessions, I could temporarily use Perl v5.30 with this command. If I close my session and re-open it, I'll be back on Perl v5.28. 289 | 290 | You can change which Perl you're using as many times as you'd like during a session, though you can only use one Perl at a time. 291 | 292 | # AUTHOR 293 | 294 | Chase Whitener `` 295 | 296 | # COPYRIGHT & LICENSE 297 | 298 | Copyright 2019, Chase Whitener, All Rights Reserved. 299 | 300 | You may use, modify, and distribute this package under the 301 | same terms as Perl itself. 302 | -------------------------------------------------------------------------------- /helpfile.txt: -------------------------------------------------------------------------------- 1 | NAME 2 | psperl 3 | 4 | SYNTAX 5 | psperl [-Command] 6 | psperl [-Command ] 7 | 8 | VERBS 9 | -Available 10 | The `Available` command will grab the list of releases from 11 | Strawberry Perl's JSON file: 12 | http://strawberryperl.com/releases.json 13 | and parse out which releases are available in Portable form 14 | -release types found here: 15 | http://strawberryperl.com/releases.html 16 | -Init 17 | The Init command is usually just added to your $Profile so that psperl 18 | is always in your PowerShell's $env:Path environment variable. From 19 | that point, you could just run any other psperl command. 20 | -Install 21 | Once you've selected which version of Perl you'd like to use 22 | from the list supplied in the `Available` command, you'd just need 23 | to install it. 24 | This command will download the Portable Perl zip file from 25 | Strawberry Perl's site, store it locally, check its checksum, 26 | unzip it, and have it available to use later. 27 | -List 28 | Show a listing of which Perls are currently installed. An asterisk 29 | (*) indicates the version currently in use. 30 | -Setup 31 | Ensure all directories are in place, and that you have $Profile setup 32 | and in place. It will add a few lines to your $Profile to initialize 33 | the application and ensure everything's in your $env:Path correctly. 34 | -Switch 35 | Change your current environment setup to use any version of 36 | Perl already installed. This will be made persistent as we'll 37 | store the current version in our local config directory and 38 | every time you start a PowerShell session, we'll setup your 39 | environment for the selected version of Perl. 40 | You can change which Perl you're using as many times as you'd 41 | like during a session, though you can only use one Perl at a 42 | time. 43 | -Use 44 | Almost exactly the same as the `Switch` command. However, it's not 45 | persistent. 46 | With this command, we just start using a different version of Perl, 47 | but we haven't switched our preference to that one. If the current 48 | preference is Perl v5.28 and it's what is setup to start on 49 | PowerShell sessions, we could temporarily use Perl v5.30 with this 50 | command. If the session's closed and re-opened, it'll be back on 51 | Perl v5.28. 52 | You can change which Perl you're using as many times as you'd 53 | like during a session, though you can only use one Perl at a 54 | time. 55 | -Version 56 | Displays the verson of PSPerl you're currently using. 57 | -------------------------------------------------------------------------------- /psperl.ps1: -------------------------------------------------------------------------------- 1 | # command line arguments 2 | param ( 3 | [switch]$available = $false, 4 | [switch]$init = $false, 5 | [switch]$setup = $false, 6 | [switch]$list = $false, 7 | [switch]$version = $false, 8 | [switch]$v = $false, 9 | [string]$install = '', 10 | [string]$switch = '', 11 | [string]$use = '', 12 | [int]$major = 0 13 | ) 14 | 15 | # Make sure we only attempt to work for PowerShell v5 and greater 16 | # this allows the use of classes. 17 | if ($PSVersionTable.PSVersion.Major -lt 5) { 18 | throw "PowerShell v5.0+ is required for psperl. https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6"; 19 | } 20 | $psperl_path = (Split-Path -parent $MyInvocation.MyCommand.Definition); 21 | $env:PSPERL_ROOT = $psperl_path; 22 | $env:PSPERL_VERSION = '0.1.2'; 23 | 24 | # Import our classes 25 | . "$($psperl_path)\src\PSPerl.ps1"; 26 | $psperl = [PSPerl]::new($psperl_path, $Profile); 27 | 28 | $global:DebugPreference = 'Continue' 29 | if ($setup) { $psperl.Setup(); } 30 | elseif ($init) { $psperl.Init(); } 31 | elseif ($available) { 32 | [int]$ps_bits = $psperl.ArchPS(); 33 | [int]$os_bits = $psperl.ArchOS(); 34 | Write-Host("We're using a $($ps_bits)-bit PowerShell on a $($os_bits)-bit Windows OS."); 35 | Write-Host("On 64-bit Windows:"); 36 | Write-Host(" 32-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT Perls without problem."); 37 | Write-Host(" You _can_ use 64-bit Perls, but may run into trouble. RISK"); 38 | Write-Host(" 64-bit PowerShell: You can use 32-bit, 32-bit USE_64_BIT_INT, or 64-bit Perls."); 39 | Write-Host("On 32-bit Windows:"); 40 | Write-Host(" You can only use 32-bit or 32-bit with USE_64_BIT_INT Perls"); 41 | Write-Host(""); 42 | [array]$data = $psperl.AvailablePerls(); 43 | if ($major -gt 0) { 44 | Write-Host("Perls available where major version is: $($major)"); 45 | Write-Host(""); 46 | if ($os_bits -eq 64) { 47 | [String]$message = '64-bit Perls'; 48 | if ($ps_bits -ne 64) { $message = "$($message) (RISKY on a 32-bit PS)"} 49 | Write-Host("$($message):"); 50 | ForEach($row in ($data | Where-Object {($_.x64) -And ($_.major -eq $major)})) { 51 | Write-Host(" - $($row.install_name)"); 52 | } 53 | } 54 | Write-Host(""); 55 | Write-Host("32-bit with USE_64_BIT_INT Perls:") 56 | ForEach($row in ($data | Where-Object {(-Not $_.x64) -And ($_.USE_64_BIT_INT) -And ($_.major -eq $major)})) { 57 | Write-Host(" - $($row.install_name)"); 58 | } 59 | Write-Host(""); 60 | Write-Host("32-bit Perls:") 61 | ForEach($row in ($data | Where-Object {(-Not $_.x64) -And (-Not $_.USE_64_BIT_INT) -And ($_.major -eq $major)})) { 62 | Write-Host(" - $($row.install_name)"); 63 | } 64 | } 65 | else { 66 | Write-Host("The current release for each major Perl:"); 67 | Write-Host(""); 68 | if ($os_bits -eq 64) { 69 | [String]$message = '64-bit Perls'; 70 | if ($ps_bits -ne 64) { $message = "$($message) (RISKY on a 32-bit PS)"} 71 | Write-Host("$($message):"); 72 | ForEach($row in ($data | Where-Object {($_.x64)} | Group-Object -Property major | Sort-Object -Descending -Property Name)) { 73 | Write-Host(" - $($row | ForEach-Object {$_.Group[0].install_name})"); 74 | } 75 | } 76 | Write-Host(""); 77 | Write-Host("32-bit with USE_64_BIT_INT Perls:") 78 | ForEach($row in ($data | Where-Object {(-Not $_.x64) -And ($_.USE_64_BIT_INT)} | Group-Object -Property major | Sort-Object -Descending -Property Name)) { 79 | Write-Host(" - $($row | ForEach-Object {$_.Group[0].install_name})"); 80 | } 81 | Write-Host(""); 82 | Write-Host("32-bit Perls:") 83 | ForEach($row in ($data | Where-Object {(-Not $_.x64) -And (-Not $_.USE_64_BIT_INT)} | Group-Object -Property major | Sort-Object -Descending -Property Name)) { 84 | Write-Host(" - $($row | ForEach-Object {$_.Group[0].install_name})"); 85 | } 86 | } 87 | Write-Host(""); 88 | } 89 | elseif ($install) { 90 | Write-Host("You'd like to install version $($install). Let's see what we can do."); 91 | [array]$data = $psperl.AvailablePerls(); 92 | 93 | # grep through our available perls for the one specified by name. 94 | # this "grep" (Where-Object) is insane. If only one thing is found, it doesn't 95 | # return a list with one item. It just returns the item. If more than one are 96 | # found, then you get a list of items. -sigh 97 | # List form: $found.GetType() = 'System.Object[]' 98 | # Single Object form: $found.GetType() = 'System.Management.Automation.PSCustomObject' 99 | $found = $data | Where-Object {$_.install_name -eq $install}; 100 | 101 | # if nothing is found, a null thingy is returned. This can be tested with a simple truthiness test 102 | if (-Not $found) { 103 | throw "No installable version of Perl found by the name $($install). Try `"psperl -available`" to get a list of available perl installations."; 104 | } 105 | # check to see if we got just one. 106 | if ($found -is 'System.Object') { 107 | $psperl.Install($found); 108 | } 109 | else { 110 | throw "Unexpected results `"$($found.GetType())`" searching for `"$($install)`". Try `"psperl -available`" to get a list of available perl installations."; 111 | } 112 | } 113 | elseif ($switch) { $psperl.Use($switch, $true); } 114 | elseif ($use) { $psperl.Use($use, $false); } 115 | elseif ($list) { 116 | Write-Host("Perls installed on your system: "); 117 | Write-Host(""); 118 | ForEach ($dir in (Get-ChildItem -Path "$($env:PSPERL_ROOT)\_perls" -Directory)) { 119 | if ($dir.Name -eq $env:PSPERL_CURRENT) { 120 | Write-Host -NoNewline " * "; 121 | } 122 | else { 123 | Write-Host -NoNewline " "; 124 | } 125 | 126 | Write-Host $dir.Name; 127 | } 128 | } 129 | elseif ($version -or $v) { 130 | Write-Host("This is PSPerl v$($env:PSPERL_VERSION)"); 131 | Write-Host(""); 132 | Write-Host("Directories of note:"); 133 | Write-Host("$($env:PSPERL_ROOT)\_config"); 134 | Write-Host("$($env:PSPERL_ROOT)\_locals"); 135 | Write-Host("$($env:PSPERL_ROOT)\_perls"); 136 | Write-Host("$($env:PSPERL_ROOT)\_zips"); 137 | Write-Host(""); 138 | Write-Host("https://github.com/genio/psperl"); 139 | Write-Host(""); 140 | } 141 | else { 142 | Get-Content -Path "$($env:PSPERL_ROOT)\helpfile.txt" | Write-Host 143 | } 144 | # To turn on Debugging, $global:DebugPreference = 'Continue' 145 | # To turn off Debugging, $global:DebugPreference = 'SilentlyContinue' 146 | 147 | exit; 148 | -------------------------------------------------------------------------------- /src/PSPerl.ps1: -------------------------------------------------------------------------------- 1 | class PSPerl { 2 | hidden [String] $URL; 3 | hidden [String] $rootPath; 4 | hidden [String] $profilePath; 5 | hidden [System.Object] $settings; 6 | 7 | # Constructor 8 | PSPerl([string]$rootPath, [string]$profilePath) { 9 | if(![System.IO.Directory]::Exists($rootPath)) { 10 | throw "Invalid root path provided"; 11 | } 12 | $this.URL = 'https://strawberryperl.com/releases.json'; 13 | $this.rootPath = $rootPath; 14 | $this.profilePath = $profilePath; 15 | $this.LoadSettings(); 16 | $this.SaveSettings(); 17 | } 18 | 19 | # Return the operating system's bitness. will be 64 or 32 20 | [int] ArchOS() { 21 | $the_bits = (Get-CimInstance Win32_OperatingSystem).OSArchitecture; 22 | if ($the_bits -match '64') { return 64; } 23 | elseif ($the_bits -match '32') { return 32; } 24 | throw "Invalid OS Architecture? We don't know what to do with a `"$($the_bits)`" architecture"; 25 | } 26 | 27 | # return the current PowerShell's bitness. will be 64 or 32. might not be the same as the OS 28 | [int] ArchPS() { 29 | $the_bits = [System.Runtime.InterOpServices.Marshal]::SizeOf([System.IntPtr]::Zero)*8; 30 | if ($the_bits -eq '64') { return 64; } 31 | elseif ($the_bits -eq '32') { return 32; } 32 | throw "Invalid PowerShell Architecture? We don't know what to do with a $($the_bits)-bit PowerShell"; 33 | } 34 | 35 | # get an array of available Portable Perl versions 36 | [Array] AvailablePerls() { 37 | [String]$cache_file = "$($this.rootPath)\_config\_release_cache.json"; 38 | [Array]$all_portables = @(); 39 | # check to see if we have a cached copy of the data first 40 | if (Test-Path $cache_file -NewerThan (Get-Date).AddHours(-1).AddMinutes(-30)) { 41 | $all_portables = (Get-Content -Raw -Path $cache_file | ConvertFrom-Json) 42 | return $all_portables; 43 | } 44 | 45 | # Ensures that Invoke-WebRequest uses TLS 1.2 46 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 47 | $res = Invoke-RestMethod -Uri $this.URL -Method Get -Headers @{'Accept'='Application/json'} 48 | 49 | foreach ($row in $res) { 50 | # only use the info for the ones with the portable edition 51 | if ([bool]($row.PSobject.Properties.Name -contains 'edition') -And [bool]($row.edition.PSObject.Properties.Name -contains 'portable')) { 52 | # move edition info into the base object 53 | $row | Add-Member -Name "sha1" -Type NoteProperty -Value $row.edition.portable.sha1; 54 | $row | Add-Member -Name "sha256" -Type NoteProperty -Value $row.edition.portable.sha256; 55 | $row | Add-Member -Name "size" -Type NoteProperty -Value $row.edition.portable.size; 56 | $row | Add-Member -Name "url" -Type NoteProperty -Value $row.edition.portable.url; 57 | $row.PSObject.Properties.Remove('edition'); 58 | # add some extra object members for version lookup simplicity later 59 | [int]$perl, [int]$major, [int]$minor, [int]$rel = $row.version.split('.'); 60 | $row | Add-Member -Name "Perl" -Type NoteProperty -Value $perl; 61 | $row | Add-Member -Name "major" -Type NoteProperty -Value $major; 62 | $row | Add-Member -Name "minor" -Type NoteProperty -Value $minor; 63 | $row | Add-Member -Name "rel" -Type NoteProperty -Value $rel; 64 | # add an x64 and a 'USE_64_BIT_INT' field that's true/false 65 | $row | Add-Member -Name "x64" -Type NoteProperty -Value $false; 66 | $row | Add-Member -Name "USE_64_BIT_INT" -Type NoteProperty -Value $false; 67 | $row | Add-Member -Name "install_name" -Type NoteProperty -Value "perl32-$($row.version)"; 68 | if ($row.archname -clike "*x64*") { 69 | $row.x64 = $true; 70 | $row.install_name = "perl64-$($row.version)"; 71 | } 72 | else { 73 | if ($row.archname -clike "*-64int") { 74 | $row.USE_64_BIT_INT = $true; 75 | $row.install_name = "perl32w64int-$($row.version)"; 76 | } 77 | } 78 | $all_portables += , $row; 79 | } 80 | } 81 | # on a 64-bit OS, we can use either 32- or 64-bit Portables 82 | if ($this.ArchOS() -eq 32) { 83 | # on a 32-bit OS, filter out all 64-bit Portables 84 | $all_portables = @(,($all_portables | Where-Object {-Not $_.x64})) 85 | } 86 | # save our data to the cache file 87 | $all_portables | ConvertTo-Json -depth 100 -Compress | Out-File $cache_file 88 | return $all_portables; 89 | } 90 | 91 | [void] ClearEnvironment() { 92 | # Write-Output "Cleaning your environment of any and all Perl variables"; 93 | # remove any set Perl/local::lib variables 94 | if (Test-Path 'env:TERM') { Remove-Item env:\TERM } 95 | if (Test-Path 'env:PERL_JSON_BACKEND') { Remove-Item env:\PERL_JSON_BACKEND } 96 | if (Test-Path 'env:PERL_YAML_BACKEND') { Remove-Item env:\PERL_YAML_BACKEND } 97 | if (Test-Path 'env:PERL5LIB') { Remove-Item env:\PERL5LIB } 98 | if (Test-Path 'env:PERL5OPT') { Remove-Item env:\PERL5OPT } 99 | if (Test-Path 'env:PERL_MM_OPT') { Remove-Item env:\PERL_MM_OPT } 100 | if (Test-Path 'env:PERL_MB_OPT') { Remove-Item env:\PERL_MB_OPT } 101 | if (Test-Path 'env:PERL_LOCAL_LIB_ROOT') { Remove-Item env:\PERL_LOCAL_LIB_ROOT } 102 | if (Test-Path 'env:PSPERL_CURRENT') { Remove-Item env:\PSPERL_CURRENT } 103 | 104 | # Write-Output "Path to PSPerl is: $($this.rootPath)" 105 | # Go through the PATH and remove Perl-related items 106 | $good_array = @(); 107 | $array = $env:Path.split(";", [System.StringSplitOptions]::RemoveEmptyEntries) | Select-Object -uniq 108 | Foreach ($item in $array) { 109 | if (-not $item.StartsWith($($this.rootPath))) { 110 | $good_array += ,$item; 111 | } 112 | } 113 | $env:Path = $good_array -join ';' 114 | return; 115 | } 116 | 117 | [void] Init() { 118 | $this.ClearEnvironment(); 119 | $env:Path = "$($this.rootPath);$env:Path"; 120 | if ($this.settings.current) { $this.Use($this.settings.current, $false); } 121 | return; 122 | } 123 | 124 | [void] Install([System.Object]$perl_obj) { 125 | Write-Host("Attempting to install $($perl_obj.install_name)"); 126 | [String]$pathDir = "$($this.rootPath)\_perls\$($perl_obj.install_name)"; 127 | if ([System.IO.Directory]::Exists($pathDir)) { 128 | Write-Host(""); 129 | Write-Host("Perl $($perl_obj.install_name) is already installed. Try using it with:"); 130 | Write-Host(""); 131 | Write-Host(" psperl -use $($perl_obj.install_name) # temporary. this session"); 132 | Write-Host(" psperl -switch $($perl_obj.install_name) # permanent. this and every subsequent session"); 133 | Write-Host(""); 134 | return; 135 | } 136 | 137 | [String]$pathZip = "$($this.rootPath)\_zips\$($perl_obj.install_name).zip"; 138 | if (![System.IO.File]::Exists($pathZip)) { 139 | # 150743342 140 | Write-Host("Downloading $($perl_obj.url). This may take some time as it's $($perl_obj.size) bytes."); 141 | Invoke-WebRequest -Uri $perl_obj.url -OutFile $pathZip 142 | } 143 | 144 | # we SHOULD now have the file 145 | if ([System.IO.File]::Exists($pathZip)) { 146 | # check to make sure we got the right size file 147 | [int]$size = (Get-Item $pathZip).length; 148 | if ($size -ne $perl_obj.size) { 149 | Remove-Item -Path $pathZip -Force; 150 | throw "The file we have is $($size) bytes but we expected $($perl_obj.size). Deleting the file."; 151 | } 152 | # check the SHA1 checksums 153 | [String]$checksum = (Get-FileHash -Path $pathZip -Algorithm SHA1).hash; 154 | if ($checksum -ne $perl_obj.sha1) { 155 | Remove-Item -Path $pathZip -Force; 156 | throw "The file's SHA1 checksum is off. Deleting the file."; 157 | } 158 | } 159 | else { 160 | throw "We tried to download the file, but we didn't get it."; 161 | } 162 | 163 | # extract the zip into the directory 164 | Write-Host("Found $($pathZip) with the correct size and SHA1 checksum. Extracting."); 165 | $this.ExtractArchive($pathZip, $pathDir); 166 | Write-Host(""); 167 | Write-Host("Installed $($perl_obj.install_name) in $($pathDir). Try using it with:"); 168 | Write-Host(""); 169 | Write-Host(" psperl -use $($perl_obj.install_name) # temporary. this session"); 170 | Write-Host(" psperl -switch $($perl_obj.install_name) # permanent. this and every subsequent session"); 171 | Write-Host(""); 172 | } 173 | 174 | [void] ExtractArchive([String]$archive_path, [String]$out_dir) { 175 | # tar.exe from Cygwin or MSYS may struggle with Windows-style paths so 176 | # ensure we are using the one that came with Windows 10 177 | $tar_path = "$env:WINDIR\system32\tar.exe"; 178 | if ([System.IO.File]::Exists($tar_path)) { 179 | [void](New-Item -ItemType Directory -Path $out_dir -Force); 180 | & $tar_path -xf $archive_path -C $out_dir; 181 | if (-Not $?) { 182 | Remove-Item -Recurse -Force $out_dir; 183 | throw "Unable to extract the archive."; 184 | } 185 | } 186 | else { 187 | # Expand-Archive is much slower than tar, so we only use it as a 188 | # fallback 189 | Expand-Archive $archive_path -DestinationPath $out_dir; 190 | } 191 | } 192 | 193 | [array] InstalledPerls() { 194 | return [Array]((Get-ChildItem -dir "$($this.rootPath)\_perls").Name); 195 | } 196 | 197 | # Load in some info about what it is we're doing here. 198 | [void] LoadSettings() { 199 | # start out here 200 | $this.settings = New-Object -TypeName PSCustomObject -Property @{ 201 | current = '' 202 | is_on = $true 203 | }; 204 | # we could be attempting to read settings prior to setup 205 | if (![System.IO.Directory]::Exists("$($this.rootPath)\_config")) { 206 | return; 207 | } 208 | 209 | [String]$settingsPath = "$($this.rootPath)\_config\settings.json"; 210 | if (Test-Path $settingsPath) { 211 | [System.Object]$temp = (Get-Content -Raw -Path $settingsPath | ConvertFrom-Json); 212 | if ($temp.PSobject.Properties.Name -contains 'current') { $this.settings.current = [string]$temp.current; } 213 | if ($temp.PSobject.Properties.Name -contains 'is_on') { $this.settings.is_on = [bool]$temp.is_on; } 214 | } 215 | if (($this.settings.current) -And (-Not $this.InstalledPerls().Contains($this.settings.current))) { 216 | $this.settings.current = ''; 217 | } 218 | return; 219 | } 220 | 221 | # Load in some info about what it is we're doing here. 222 | [void] SaveSettings() { 223 | # we could be attempting to save settings prior to setup 224 | if (![System.IO.Directory]::Exists("$($this.rootPath)\_config")) { 225 | return; 226 | } 227 | [String]$settingsPath = "$($this.rootPath)\_config\settings.json"; 228 | $this.settings | ConvertTo-Json -depth 100 | Out-File $settingsPath 229 | return; 230 | } 231 | 232 | [void] Setup() { 233 | # check to ensure the $this.profilePath exists 234 | if (![System.IO.File]::Exists($this.profilePath)) { 235 | if (![System.IO.Directory]::Exists($this.profilePath)) { 236 | $profileDir = (Split-Path -parent $this.profilePath) 237 | Write-Host("You don't yet have the profile directory $($profileDir). We'll create it now."); 238 | New-Item -ItemType Directory $profileDir -ErrorAction SilentlyContinue 239 | } 240 | Write-Host("You don't yet have a profile at $($this.profilePath). We'll set that up now."); 241 | # this is like touch filename in linux 242 | New-Item -ItemType file $this.profilePath 243 | } 244 | $init_content = "# PSPerl Initialize`r`n& $($this.rootPath)\psperl.ps1 -Init" 245 | $found = Select-String -Quiet -Pattern "^# PSPerl Init" -Path $this.profilePath 246 | if (-not $found) { 247 | Add-Content -Path $this.profilePath -Value "`r`n$init_content" 248 | } 249 | 250 | # check to ensure the config directory exists 251 | if(![System.IO.Directory]::Exists("$($this.rootPath)\_config")) { 252 | Write-Host("You don't yet have a configuration directory."); 253 | # this is like touch filename in linux 254 | New-Item -ItemType directory "$($this.rootPath)\_config" 255 | } 256 | # check to ensure the \_zips directory exists 257 | if(![System.IO.Directory]::Exists("$($this.rootPath)\_zips")) { 258 | # this is like touch filename in linux 259 | New-Item -ItemType directory "$($this.rootPath)\_zips" 260 | } 261 | # check to ensure the config\perls directory exists 262 | if(![System.IO.Directory]::Exists("$($this.rootPath)\_perls")) { 263 | # this is like touch filename in linux 264 | New-Item -ItemType directory "$($this.rootPath)\_perls" 265 | } 266 | 267 | Write-Host("Your profile is located at: $($this.profilePath)"); 268 | Write-Host("Your config directory is at: $($this.rootPath)\_config"); 269 | return; 270 | } 271 | 272 | [void] Use([string]$perl_install, [bool]$persistent = $false) { 273 | if (-Not $this.InstalledPerls().Contains($perl_install)) { 274 | throw "$($perl_install) isn't yet installed. Try installing it."; 275 | } 276 | $this.ClearEnvironment(); 277 | $env:PSPERL_CURRENT = $perl_install; 278 | $env:PATH = "$($this.rootPath);$($env:PATH)"; 279 | # which perl will we be using? 280 | [string]$path = "$($this.rootPath)\_perls\$($perl_install)"; 281 | 282 | $env:PATH = "$($path)\perl\site\bin;$($path)\perl\bin;$($path)\c\bin;$($env:PATH)"; 283 | 284 | # setup local::lib stuff 285 | # [String]$lib_path = "$($this.rootPath)\_libs\$($perl_install)\$($lib_name)"; 286 | # $lib_path = $lib_path.Replace("\", "/"); 287 | # $env:PATH = "$($lib_path)/bin;$($env:PATH)"; 288 | # perl -Mlocal::lib="$($lib_path)" *>$null; 289 | # $env:PERL5LIB = "$($lib_path)/lib/perl5"; 290 | # $env:PERL_LOCAL_LIB_ROOT= "$($lib_path)"; 291 | # $env:PERL_MB_OPT = $("--install_base `"$($lib_path)`""); 292 | # $env:PERL_MM_OPT = $("INSTALL_BASE=$($lib_path)"); 293 | if ($persistent) { 294 | $this.settings.current = $perl_install; 295 | $this.SaveSettings(); 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /t/basic.t: -------------------------------------------------------------------------------- 1 | 2 | use strict; 3 | use warnings; 4 | use version; 5 | use Test::More; 6 | 7 | ( my $travis_perl_version = $ENV{TRAVIS_PERL_VERSION} ) =~ 8 | s/^perl[^-]+\-([0-9]+\.[0-9]+\.[0-9]+).*$/$1/; 9 | $travis_perl_version = version->parse($travis_perl_version); 10 | 11 | note "perl executable is $^X"; 12 | 13 | is $^V, $travis_perl_version, 14 | "$^V matches $travis_perl_version ($ENV{TRAVIS_PERL_VERSION})"; 15 | 16 | done_testing; 17 | --------------------------------------------------------------------------------