in reply to What does "-" in a use statement do?

The leading "-" does what it does everywhere else in Perl too, so looking at use only tells you where to look next, because what you see is the use Module LIST form. So you will next be looking at how Perl parses a list, and elements of a list.

See perlop on symbolic unary operators, which explains that -bareword is the same as "-bareword". So your expression above would be identical to:

use App::Cmd::Setup "-app";

Replies are listed 'Best First'.
Re^2: What does "-" in a use statement do?
by nysus (Parson) on Jan 27, 2018 at 13:56 UTC

    OK, thanks. But now my question is, how is it possible for App::Cmd::Setup to export something called -app? I didn't think identifiers could start with a dash.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      Nowhere in use does it say that the LIST should be a list of identifiers.

      If you read the documentation of App::Cmd::Setup, I presume that there it will also not talk about a list of identifiers that get exported, especially no identifier named -app.

      If you further read use (and the associated require) you will find that one of the things that use does is call a subroutine import if it exists. And that subroutine is called with all the parameters from the LIST part of the use statement.

      What that import subroutine does depends on the module. If the module uses the import subroutine from Exporter like the following:

      use Exporter 'import';

      ... then it will get the behaviour you seem to expect, of exporting subroutine names and variable names on demand.

      But most likely, App::Cmd::Setup does something different.

        Ah, got it. So basically, the list passed to use can be used for just about anything, not just importing code. In this case, App::Cmd::Setup is just using it to identify what the package is (a command or an app) and to be able to pass in variables. Very interesting. Thanks!

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        Do you happen to know if here is there is an agreed upon word for describing how the -app bit is used? Perhaps something like "package initializer"?

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks