MoarVM の Configure.pl を Perl6 で書こうとした話
Perl が書けなかったので、MoarVM の ./Configure.pl を Perl6 で書いて理解してみようと思った:
use v6; use Getopt::Long; constant $NAME = 'moar'; constant $GENLIST = 'build/gen.list'; sub MAIN() { my Bool $failed = False; my %args; my %defaults; my %config; get-options( %args, <help|? debug:s optimize:s instrument! coverage os=s shell=s toolchain=s compiler=s ar=s cc=s ld=s make=s has-sha has-libuv static has-libtommath has-libatomic_ops has-dyncall has-libffi pkgconfig=s build=s host=s big-endian jit! enable-jit prefix=s bindir=s libdir=s mastdir=s make-install asan ubsan valgrind telemeh> ); say $args; # pod2usage( True ) $; # say 'Welcome to MoarVM!'; }
そもそも、Perl6 の Getopt::Long
の definition が Perl の Getopt::Long
と違う可能性が微レ存だったので、いきなりそこで躓いた。
それに、Perl6 の Getopt::Long
は = が必須みたいなので、Perl の Getopt::Long
とは全然違う感じがする。
use v6; use Getopt::Long; # # Perl5 の Getopt::Long のように実装されているなら、以下が動くはず: # my $capture = Getopt::Long.new( <help|?> ); # # 今のところ、動かない………。 # say $capture;
Getopt::Tiny
というのもあるんだけど、それも真偽値は =!
が必要。
use v6; use Getopt::Tiny; my Hash $opts = {help => False, version => False}; get-options( $opts, <help=! verbose=!> ); say $opts;
ということで、Getopt::OldFashion を書くことにした。
こんな風に書けるはず:
use v6; use Getopt::OldFashion; my %opts = get-options( <help|? version verbose> ); say %opts;