summaryrefslogtreecommitdiff
path: root/content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md')
-rw-r--r--content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md58
1 files changed, 29 insertions, 29 deletions
diff --git a/content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md b/content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md
index 21c4298..c1d2df7 100644
--- a/content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md
+++ b/content/posts/2018/2018-03-20-perl6-introduction-to-application-programming.md
@@ -13,10 +13,10 @@ tags:
# Perl 6 - Introduction to application programming
In this tutorial, I'll be guiding you through creating a simple application in
-Perl 6. If you don't have Perl 6 installed yet, get the
-[http://rakudo.org/how-to-get-rakudo/](Rakudo Star) distribution for your OS.
-Alternatively, you can use the [https://hub.docker.com/_/rakudo-star/](Docker
-image).
+Perl 6. If you don't have Perl 6 installed yet, get the [Rakudo
+Star](http://rakudo.org/how-to-get-rakudo/) distribution for your OS.
+Alternatively, you can use the [Docker
+image](https://hub.docker.com/_/rakudo-star/).
The application itself will be a simple dice-roller. You give it a number of
dice to roll, and the number of sides the die has. We'll start off by creating
@@ -69,9 +69,9 @@ This is the name given to the module. This will be used for the directory name,
which by default in `assixt` will be `perl6-` prepended to a lower-case version
of the module name. If you ever wish to make a module that is to be shared in
the Perl 6 ecosystem, this should be unique across the entire ecosystem. If
-you're interested in some guidelines, the
-[https://pause.perl.org/pause/query?ACTION=pause_namingmodules](PAUSE
-guidelines) seem to apply pretty well to Perl 6 as well.
+you're interested in some guidelines, the [PAUSE
+guidelines](https://pause.perl.org/pause/query?ACTION=pause_namingmodules) seem
+to apply pretty well to Perl 6 as well.
For this application, we'll use `Local::App::Dicer`, but you can use whatever
name you'd prefer here.
@@ -106,7 +106,7 @@ This indicates the license under which your module is distributed. This
defaults to `GPL-3.0`, which I strongly recommend to use. The de-facto
default seems to be `Artistic-2.0`, which is also used for Perl 6 itself.
-This identifier is based on the [https://spdx.org/licenses/](SPDX license list).
+This identifier is based on the [SPDZ license list](https://spdx.org/licenses/).
Anything not mentioned in this list is not acceptable. #TODO Clarify why
## Writing your first test
@@ -170,28 +170,28 @@ subtest "Illegal rolls", {
{{< admonition title="note" >}}
Perl 6 allows mathematical characters to make your code more concise, as with
-the ≤ in the above block. If you use http://www.vim.org/[vim], you can make use
-of the https://github.com/vim-perl/vim-perl6[vim-perl6] plugin, which has an
+the ≤ in the above block. If you use [vim](http://www.vim.org/), you can make use
+of the [vim-perl6](https://github.com/vim-perl/vim-perl6) plugin, which has an
option to change the longer, ascii-based ops (in this case `\<=`) into the
shorter unicode based ops (in this case `≤`). This specific feature requires
`let g:perl6_unicode_abbrevs = 1` in your `vimrc` to be enabled with
`vim-perl6`.
If that's not an option, you can use a
-https://en.wikipedia.org/wiki/Compose_key[compose key]. If that is not viable
+[compose key](https://en.wikipedia.org/wiki/Compose_key). If that is not viable
either, you can also stick to using the ascii-based ops. Perl 6 supports both
of them.
{{< / admonition >}}
This will run 53 tests, split up in two
-[https://docs.perl6.org/language/testing#Grouping_tests](subtests). Subtests are
-used to logically group your tests. In this case, the calls that are correct
-are in one subtest, the calls that should be rejected are in another.
+[subtests](https://docs.perl6.org/language/testing#Grouping_tests). Subtests are
+used to logically group your tests. In this case, the calls that are correct are
+in one subtest, the calls that should be rejected are in another.
The `plan` keywords indicate how many tests should be run. This will help spot
errors in case your expectations were not matched. For more information on
-testing, check out [https://docs.perl6.org/language/testing](the Perl 6 docs on
-testing).
+testing, check out [the Perl 6 docs on
+testing](https://docs.perl6.org/language/testing).
We're making use of two test routines, `ok` and `throws-like`. `ok` is a
simple test: if the given statement is truthy, the test succeeds. The other
@@ -243,7 +243,7 @@ use v6.c;
unit module Local::App::Dicer;
```
-The first line is a [https://en.wikipedia.org/wiki/Shebang_(Unix)](shebang). It
+The first line is a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). It
informs the shell what to do when you try to run the file as an executable
program. In this case, it will run `false`, which immediately exits with a
non-success code. This file needs to be run as a Perl 6 module file, and
@@ -424,10 +424,10 @@ $ perl6 -Ilib bin/dicer 2 20
### The usage output
Now, we still have the trouble of illegal number input not clearly telling
-what's wrong. We can do a neat trick with
-[https://docs.perl6.org/language/functions#index-entry-USAGE](the USAGE sub) to
-achieve this. Perl 6 allows a subroutine with the name `USAGE` to be defined,
-overriding the default behaviour.
+what's wrong. We can do a neat trick with [the `USAGE`
+sub](https://docs.perl6.org/language/functions#index-entry-USAGE) to achieve
+this. Perl 6 allows a subroutine with the name `USAGE` to be defined, overriding
+the default behaviour.
Using this, we can generate a friendlier message informing the user what they
need to supply more clearly. The `USAGE` sub would look like this:
@@ -448,8 +448,8 @@ You now have a working console application in Perl 6!
## a simple GUI
But that's not all. Perl 6 has a module to create GUIs with the
-[https://www.gtk.org/](GTK library) as well. For this, we'll use the
-[https://github.com/perl6/gtk-simple](`GTK::Simple`) module.
+[GTK library](https://www.gtk.org/) as well. For this, we'll use the
+[`GTK::Simple`](https://github.com/perl6/gtk-simple) module.
You can add this module as a dependency to the `Local::App::Dicer` repository
with `assixt` as well, using the `depend` command. By default, this will also
@@ -463,11 +463,11 @@ $ assixt depend GTK::Simple
Next, we could create another executable file and call it `dicer-gtk`. However,
I can also use this moment to introduce
-[https://docs.perl6.org/language/glossary#index-entry-multi-method](multi
-methods). These are subs with the same name, but differing signatures. If a
-call to such a sub could potentially match multiple signatures, the most
-specific one will be used. We will add another `MAIN` sub, which will be called
-when `bin/dicer` is called with the `--gtk` parameter.
+[multi-methods](https://docs.perl6.org/language/glossary#index-entry-multi-method).
+These are subs with the same name, but differing signatures. If a call to such a
+sub could potentially match multiple signatures, the most specific one will be
+used. We will add another `MAIN` sub, which will be called when `bin/dicer` is
+called with the `--gtk` parameter.
We should also update the `USAGE` sub accordingly, of course. And while we're
at it, let's also include the `GTK::Simple` and `GTK::Simple::App` modules. The
@@ -526,7 +526,7 @@ in Perl 6. Any method can be given a non-positional, named parameter. This is
done by appending a `:` in front of the variable name in the sub signature.
This has already been used in our code, in `multi sub MAIN(Bool :$gtk where
$gtk == True)`. This has a couple of benefits, which are explained in the
-[https://docs.perl6.org/type/Signature#index-entry-positional_argument_%28Signature%29_named_argument_%28Signature%29](Perl 6 docs on signatures).
+[Perl 6 docs on signatures](https://docs.perl6.org/type/Signature#index-entry-positional_argument_%28Signature%29_named_argument_%28Signature%29).
### Creating the elements