LoginSignup
6

More than 5 years have passed since last update.

Windows な職場でみんなで共通の Perl を使ってる話

Last updated at Posted at 2018-12-11

この記事は Perl Advent Calendar 2018 の 12 日目の記事です。

Windows 環境な職場でみんなで共通の Perl を使っている、という話をします。

なぜ共通の Perl を使うのか

以下のような理由です。

  • 環境を統一したいため
  • (Windowsなのもあり)パッチをあてないとインストールできないモジュールがあるため
  • Perl に詳しくない人でも簡単に使えるようにするため
  • 共通の Perl を配ることで、職場内の標準ツールも同時に配ることができるため

これらを満たすために、全員で共通の Perl (以下 共通 Perl と記載) を使うようにしています。

Windows における Perl の選択肢

たくさん選択肢がありますが、楽にインストールできる代表格としては以下があります。

ほとんどのケースでどちらを使ってもよいと思いますが、今回の方法では Strawberry Perl を使います。

共通 Perl をインストールする方法

以下の手順で実施します。

管理者側の作業

最初にみんなで使うための 共通 Perl を git で管理します。
この作業は、管理者側で1回実施するだけで良いです。

  • 共通 Perl の git リポジトリを作る

使用者の作業

共通 Perl を使う人は、以下の手順を実施します。

  • 共通 Perl を設定する(初期設定)

後は、新しいモジュールを入れたり同期したり、という使い方になります。

  • 共通 Perl に新しいモジュールを入れる
  • 共通 Perl から同期する

具体的には?

書いている時点の最新版である 5.28.0.1 の 32bit 版を例として記載します。
具体的には June 2018 / 5.28.0.1 / 32bit / with USE_64_BIT_INT を使いました。

共通 Perl の git リポジトリを作る

以下から、 5.28.0.1 の Portable 版をダウンロードする。
http://strawberryperl.com/releases.html

git は *.exe 等を version 管理しないようにされている場合が多いと思うので、以下のように実行して local な .gitignore を設定しておいた方が無難です。

$ echo !* > .gitignore
$ git init . && git add . && git commit -m "strawberry-perl-5.28.0.1-32bit-portable"

あとは、どこかに push しておきます。
ここでは、例として https://example.com/sago35/perl に置きます。

$ git remote add origin https://example.com/sago35/perl
$ git push origin master

共通 Perl を設定する(初期設定)

以下から、 5.28.0.1 の MSI installer (*.msi) をダウンロードする。
普通にインストールすると C:\Strawberry にインストールされます。

01.png

その後、アンインストールではなく手動で C:\Strawberry 以下のファイルを削除します。

02.png

その後、 git clone https://example.com/sago35/perl C:\Strawberry することで git 管理された Perl がコピーされます。

$ git clone https://example.com/sago35/perl C:\Strawberry

03.png

このやり方で設定すると、インストーラ版 (MSI installer) により環境変数などが設定されるので手順がシンプルになります。

共通 Perl に新しいモジュールを入れる

普通に cpanm 等を使ってインストールした後、 git push します。
ここでは、 Array::Uniq をインストールしてみます。
この操作で、 共通 Perl が更新されます。

$ cpanm -v Array::Uniq
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   perl/lib/perllocal.pod

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        perl/site/

no changes added to commit (use "git add" and/or "git commit -a")
$ git add . && git commit -m "Install Array::Uniq"
[master 8e8258d] Install Array::Uniq
 5 files changed, 201 insertions(+)
 create mode 100644 perl/site/lib/Array/Uniq.pm
 create mode 100644 perl/site/lib/MSWin32-x86-multi-thread-64int/.meta/Array-Uniq-0.02/MYMETA.json
 create mode 100644 perl/site/lib/MSWin32-x86-multi-thread-64int/.meta/Array-Uniq-0.02/install.json
 create mode 100644 perl/site/lib/auto/Array/Uniq/.packlist```
$ git push origin master

共通 Perl から同期する

既に git 管理されているので、 git pull すると同期されます。
以下のように、先ほど追加した Array::Uniq が同期されました。

$ cd C:\Strawberry

$ git pull
Updating cb25a0d..96d08d1
Fast-forward
 perl/lib/perllocal.pod                             |  22 ++++
 perl/site/lib/Array/Uniq.pm                        | 140 +++++++++++++++++++++
 .../.meta/Array-Uniq-0.02/MYMETA.json              |  37 ++++++
 .../.meta/Array-Uniq-0.02/install.json             |   1 +
 perl/site/lib/auto/Array/Uniq/.packlist            |   1 +
 5 files changed, 201 insertions(+)
 create mode 100644 perl/site/lib/Array/Uniq.pm
 create mode 100644 perl/site/lib/MSWin32-x86-multi-thread-64int/.meta/Array-Uniq-0.02/MYMETA.json
 create mode 100644 perl/site/lib/MSWin32-x86-multi-thread-64int/.meta/Array-Uniq-0.02/install.json
 create mode 100644 perl/site/lib/auto/Array/Uniq/.packlist

もちろん使うことができます。

$ perl -MArray::Uniq -e "print uniq sort (3, 1, 2, 1, 3)"
123

まとめ

Windows で職場内共通の Perl を使う方法を記載しました。
職場ではモジュールのインストール/アップデートは、プルリクエストという形で管理しています。
今のところ、うまく回っているように感じます。

シンプルなやり方で共通化できるので、共通化させたい思いがある場合は役に立つかもしれません。

おまけ

職場内の共通ツールとしては以下のようなものを作って共有しています。

  • perltidy が共通設定でかかるようにしたスクリプト
  • 職場内の PC を wake-on-lan するためのスクリプト
  • perl や golang のひな形 (職場内共通のひな形) を作成するためのスクリプト
  • diff 結果を excel に取り込むためのスクリプト

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6