NAME

{{$dist->name =~ s/-/::/gr}} - Add the command abstract here

```

Take a moment to study the template. Notice the code inside the double set of curly braces. The double curly braces tell the templating system `Dist::Zilla` uses to replace the curly braces and the code inside them with the result of the expression between the curly braces.

So what is this bit of code doing, exactly?

To understand it, you have to know that `$dist->name` is the same name as the string you provide for the distribution when you use the `dzil new` command except that instad of `::` to delimit module directories, it uses a `-` character. So, for example, if we create a new distribution called `App::sayhi` (which we will do shortly), `$dist->name` is `App-sayhi`. The regular expression inside the curly braces replace the dash in the name with a `::`. As mentioned, it's the job of the `[GatherDir::Template]` to perform the substitutions found in this template.

In case you're wondering, `$dist` is the `Dist::Zilla` object overseeing everything and `name`, of course, is the method for generating the name of our distribution.

The command template is modeled after the example in the `App::Cmd::Simple` module documentation, the module you are using to create this app. The `run` method we see in the template file is provided by this module. Refer to the `App::Cmd::Simple` documentation for more details.

OK, now save the command file to `skel/bin/the_command`. `the_command` file name is arbitrary and acts as a placeholder in the blueprint. When it comes time to process the blueprint, you'll want the name of this file to change to the name of the command.

#### Changing the Command Name

To make that happen, we use of the `rename` parameter that `[GatherDir::Template]` accepts. Reopen your `profile.ini` command and add the following line to the end of the `[GatherDir::Template]` section and save the file:

`rename.the_command = $dist->name =~ s/^App-//r`

This snippet tells the plugin to change the name of any file named `the_command` to the last part of the distribution name. As pointed out alredy, the `$dist->name` is the same as the distribution name we supplied to the `dzil new` command except with dashes in place of `::`. The first part of of `$dist-name` gets stripped away and what's left behind is used as the command's name.

### Modifying the Module Template

Your remaining task modifies the blueprint's module template file. Replace the existing `Module.pm` file in the `command` blueprint directory with this code:

```prettyprint

package {{$name}}; use strict; use warnings; use base qw(App::Cmd::Simple);

sub opt_spec { return ( [ "option1|a", "do option 1" ], ); }

sub validate_args { my ($self, $opt, $args) = @_;

# no args allowed but options
$self->usage_error("No args allowed") if @$args;
}

sub execute { my ($self, $opt, $args) = @_;

if ($opt->{option1}) {
    # do option 1 stuff
} else {
    # do regular stuff
}
}

1;

NAME

{{$name}} - Add the module abstract here

```

Notice, the use of the `{{$name}}` in the template. The `$name` variable is the same as the distribution name provided to `dzil new` precisely as it was input on the command line with the `::` in tact. As for how the rest of the code works, take a look at the `App::Cmd::Simple` documentation.

## Set Up Your Work Area with the `new` Command and the `-p` Argument

It's time to see if you accurately followed instructions. Jump to the `~/dzil_tutorial` directory and issue the following command:

`dzil new App::sayhi -p app`

This tells `dzil` to set up a new module work area with the distribution name "App::sayhi". The `-p` option supplies the `app` ~~profile~~ blueprint to the command to use it to generate a new work area and populate it with files according to your blueprint's instructions.

If you see errors after running the command, read them carefully and resolve them.

## Getting `sayhi` to Say "Hi"

Now that `Dist::Zilla` has generated the work area, only a few simple changes are required to get a useful command. Fire up your text editor to edit the `lib/sayhi.pm` module to add/modify the following lines (or just cut and paste the entire code listing further down):

* Add `use Greetings;` somewhere near the top

In the `opt_spec` function:

* replace `option1|a` with `shout|s` * replace `do option 1` to `shout it`

In the `execute` funciton:

* change `$opt->{option1}` to `$opt->{shout}` * replace `#do option 1 stuff` with `&Greetings::shout_hw;` * replace `#do regular stuff` with `&Greetings::hw;`

In the pod:

* change `Add the module abstract here` to `Backend interface for the 'sayhi' command`

Here is the entire finished module for your copy and paste convenience:

```prettyprint

package App::sayhi; use strict; use warnings; use Greetings; use base qw(App::Cmd::Simple);

sub opt_spec { return ( [ "shout|s", "shout it" ], ); }

sub validate_args { my ($self, $opt, $args) = @_;

# no args allowed but options!
$self->usage_error("No args allowed") if @$args;
}

sub execute { my ($self, $opt, $args) = @_;

if ($opt->{shout}) {
  &Greetings::shout_hw;
} else {
  &Greetings::hw;
}
}

1;

NAME

App::sayhi - Backend interface for the 'sayhi' command

```

Change the documentation in the `bin/sayhi` file so the abstract reads:

`command line greetings`

Finally, you may also need to install the `App::Cmd` module:

`cpanm App::Cmd`

Now test your module to make sure there are no errors:

`dzil test`

We will talk about testing in much more detail soon. If you didn't get an `All tests successful` message near the bottom of the test output, review the instructions above and double check your blueprint and module modifications. The errors can help you track down the problem.

If the tests all passed, install the module with:

`dzil install`

Notice there is no need to issue the `build` or `release` subcommand first. You can just go right ahead and install it.

If you installed the `Greetings` module from the earlier tutorial, you can have hours of endless fun printing "Hello, World!" right from the command line. To print a standard greeting, issue the `sayhi` command with no arguments. To shout it, do `sayhi --shout` or `sayhi -s`. If you forget how the command works, just use the `-h` option for a quick reminder.