Creating a Perl 6 module containing Perl 5 utility scripts in bin /

Perl 6 script in Perl 5 module distribution

I can include the Perl 6 script in the distribution of the Perl 5 module:

# Create a new module
dzil new My::Dist
cd My-Dist/

# Add necessary boilerplate
echo '# ABSTRACT: boilerplate' >> lib/My/Dist.pm

# Create Perl 6 script in bin directory
mkdir bin
echo '#!/usr/bin/env perl6' > bin/hello.p6
echo 'put "Hello world!";' >> bin/hello.p6

# Install module
dzil install

# Test script
hello.p6
    # Hello world!

# See that it is actually installed
which hello.p6
    # ~/perl5/perlbrew/perls/perl-5.20.1/bin/hello.p6

Perl 5 script in the distribution of Perl 6 modules

However, it’s hard for me, including Perl 5 scripts in the Perl 6 distribution.

The module directory contains a file META6.jsonand a subdirectory called bin. There binis a Perl 5 file named hello.pl.

zef install .works without errors in the top directory. But when I try to start, hello.plI get an error message. Let's go find out if the Perl 6 script shell has been installed for hello.pl, and that is exactly what gives me the error. If I run the original hello.pldirectly, it works fine.

META6.json

{
"perl"         : "6.c",
"name"         : "TESTING1234",
"license"      : "Artistic-2.0",
"version"      : "0.0.2",
"auth"         : "github:author",
"authors"      : ["First Last"],
"description"  : "TESTING module creation",
"provides"     : {
                 },
"depends"      : [ ],
"test-depends" : [ "Test", "Test::META"  ]
}

bin/hello.pl

#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;

say 'Hello world!';

, hello.pl, :

===SORRY!===
Could not find Perl5 at line 2 in:
    /home/username/.perl6
    /path/to/perl6/rakudo-star-2017.07/install/share/perl6/site
    /path/to/perl6/rakudo-star-2017.07/install/share/perl6/vendor
    /path/to/perl6/rakudo-star-2017.07/install/share/perl6
    CompUnit::Repository::AbsolutePath<64730416>
    CompUnit::Repository::NQP<43359856>
    CompUnit::Repository::Perl5<43359896>

which hello.pl , /path/to/perl6/rakudo-star-2017.07/install/share/perl6/site/bin/hello.pl. :

/path/to/perl6/rakudo-star-2017.07/install/share/perl6/site/bin/hello.pl

#!/usr/bin/env perl6
sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
    CompUnit::RepositoryRegistry.run-script("hello.pl", :dist-name<TESTING1234>, :$name, :$auth, :$ver);
}

Rakudo (https://rt.perl.org/Ticket/Display.html?id=131911), , .

+4
1

cat Perl 5 Perl 6, "" (. GitHub , ).

. zef install . Rakudo Star 2017.07. run_cat Rakudo bin.

, , Perl 6 Perl 5 script Perl 6 script Perl 6.


Perl 5 script

resources/scripts/cat.pl

#!/bin/env perl
use v5.10;
use strict;
use warnings;

while(<>) {
    print;
}

Wrapper

: lib/catenate.pm6

unit module catenate;

sub cat ($filename) is export {
    run('perl',%?RESOURCES<scripts/cat.pl>,$filename);
}

: bin/run_cat

#!/bin/env perl6
use catenate;

sub MAIN ($filename) {
    cat($filename);
}

META6.json`

{
"perl"         : "6.c",
"name"         : "cat",
"license"      : "Artistic-2.0",
"version"      : "0.0.9",
"auth"         : "github:author",
"authors"      : ["First Last"],
"description"  : "file catenation utility",
"provides"     : { "catenate" : "lib/catenate.pm6" },
"test-depends" : [ "Test", "Test::META"  ],
"resources"    : [ "scripts/cat.pl" ]
}

t/cat.t

#!/bin/env perl6
use Test;

constant GREETING = 'Hello world!';
my $filename = 'test.txt';
spurt($filename, GREETING);

my $p5 = qqx{ resources/scripts/cat.pl $filename };
my $p6 = qqx{ bin/run_cat              $filename };

is $p6, $p5, 'wrapped script gives same result as original';

is $p6, GREETING, "output is '{GREETING}' as expected";

unlink $filename;

done-testing;

@moritz @ugexe , !

+1

Source: https://habr.com/ru/post/1683841/


All Articles