Cartonはマジにcool

Perl弱者のわたしが、Cartonを使ってみたのでメモ。
Carton使えばインフラ側の人たち相当捗ると思う。


$ ls -a ./carton/
. .. carton_test.pl
$
$ cd ./carton/
$
$ cat carton_test.pl
#!/usr/bin/env perl

use strict;
use warnings;

use Data::UUID;

my $uuid = Data::UUID->new;
$uuid = $uuid->create_str();

print "UUID is $uuid\n";
$

Makefile.PLをつくる


use inc::Module::Install;
name 'carton_test';
version '0.1';

requires 'Data::UUID', 1.217;

WriteAll;

こんな感じのものですね。バージョン指定ある場合は指定を。

叩いてみる。


$ carton install
Installing modules using Makefile.PL
You have ExtUtils::MakeMaker (6.57_05)
Successfully installed Data-UUID-1.217
1 distribution installed
Complete! Modules were installed into local
$
$ ls -a
. .carton MYMETA.json Makefile carton.lock inc
.. META.yml MYMETA.yml Makefile.PL carton_test.pl local
$
$ carton list
Data-UUID-1.217
$

モジュールがいっぱいある場合には tree 見ても面白いですね。

これで ./local/lib/perl5 配下に使われるモジュールが入ると。
私みたいな情弱はいないと思うんですけど、システム内に入ってる場合にも
関係なしに ./local/lib/perl5 に入るものかと思っていました。
そういうショボイ間違え方すると @fujiwaraさんからイスを頂くことになります。
気をつけましょう。

そして、デプロイというか、別サーバに持って行って動かしてみます。

Carton用のPATHも追加しておきます。


#!/usr/bin/env perl

use strict;
use warnings;

use File::Spec;
use File::Basename;
use lib File::Spec->catdir(dirname(__FILE__), 'local', 'lib', 'perl5');

use Data::UUID;

my $uuid = Data::UUID->new;
$uuid = $uuid->create_str();

print "UUID is $uuid\n";

別のサーバで


$ perl carton_test.pl
Can't locate Data/UUID.pm in @INC (@INC contains: local/lib/perl5 /usr/lib... .) at carton_test.pl line 10.
BEGIN failed--compilation aborted at carton_test.pl line 10.

見つからないいわれますね。

carton installしてみる


$ carton install
Installing modules using Makefile.PL
Successfully installed ExtUtils-MakeMaker-6.62 (upgraded from 6.30)
Successfully installed ExtUtils-Install-1.54 (upgraded from 1.33)
You have Pod::Man (1.37)
You have Data::Dumper (2.121_08)
You have DirHandle (1.00)
You have File::Copy (2.09)
You have File::Spec (3.12)
You have Carp (1.04)
You have File::Compare (1.1003)
You have File::Find (1.10)
You have File::Path (1.08)
You have File::Basename (2.74)
You have Cwd (3.12)
You have ExtUtils::MakeMaker (6.62)
Successfully installed Data-UUID-1.217
3 distributions installed
Complete! Modules were installed into local
$

入りましたね。

実行してみる


$ perl carton_test.pl
UUID is 78279B22-9F0C-11E1-83C4-414E7E0ED1A3


COOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOL!!