Profile of App/Cmd/Command/help.pm

← Index
NYTProf Performance Profile «line view»
For script/ponapi
Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:09 2016

Filename | /usr/local/share/perl/5.18.2/App/Cmd/Command/help.pm
Statements | Executed 10 statements in 270µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 12µs | 24µs | Module::Runtime::::BEGIN@1.12 Module::Runtime::BEGIN@1.12
1 | 1 | 1 | 12µs | 16µs | Module::Runtime::::BEGIN@2.13 Module::Runtime::BEGIN@2.13
1 | 1 | 1 | 9µs | 9µs | App::Cmd::Command::help::::BEGIN@7App::Cmd::Command::help::BEGIN@7
1 | 1 | 1 | 4µs | 4µs | App::Cmd::Command::help::::BEGIN@6App::Cmd::Command::help::BEGIN@6
1 | 1 | 1 | 2µs | 2µs | App::Cmd::Command::help::::command_namesApp::Cmd::Command::help::command_names
0 | 0 | 0 | 0s | 0s | App::Cmd::Command::help::::executeApp::Cmd::Command::help::execute
0 | 0 | 0 | 0s | 0s | App::Cmd::Command::help::::usage_descApp::Cmd::Command::help::usage_desc

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 | 2 | 22µs | 2 | 36µs | # spent 24µs (12+12) within Module::Runtime::BEGIN@1.12 which was called: # once (12µs+12µs) by Module::Runtime::require_module at line 1 use strict; # spent 24µs making 1 call to Module::Runtime::BEGIN@1.12 # spent 12µs making 1 call to strict::import
2 | 2 | 34µs | 2 | 21µs | # spent 16µs (12+5) within Module::Runtime::BEGIN@2.13 which was called: # once (12µs+5µs) by Module::Runtime::require_module at line 2 use warnings; # spent 16µs making 1 call to Module::Runtime::BEGIN@2.13 # spent 5µs making 1 call to warnings::import
3 |  |  |  |  |
4 |  |  |  |  | package App::Cmd::Command::help;
5 | 1 | 400ns |  |  | $App::Cmd::Command::help::VERSION = '0.330';
6 | 2 | 26µs | 1 | 4µs | # spent 4µs within App::Cmd::Command::help::BEGIN@6 which was called: # once (4µs+0s) by Module::Runtime::require_module at line 6 use App::Cmd::Command; # spent 4µs making 1 call to App::Cmd::Command::help::BEGIN@6
7 | 1 | 182µs | 1 | 9µs | # spent 9µs within App::Cmd::Command::help::BEGIN@7 which was called: # once (9µs+0s) by Module::Runtime::require_module at line 7 BEGIN { our @ISA = 'App::Cmd::Command'; } # spent 9µs making 1 call to App::Cmd::Command::help::BEGIN@7
8 |  |  |  |  |
9 |  |  |  |  | # ABSTRACT: display a command's help screen
10 |  |  |  |  |
11 |  |  |  |  | #pod =head1 DESCRIPTION
12 |  |  |  |  | #pod
13 |  |  |  |  | #pod This command will either list all of the application commands and their
14 |  |  |  |  | #pod abstracts, or display the usage screen for a subcommand with its
15 |  |  |  |  | #pod description.
16 |  |  |  |  | #pod
17 |  |  |  |  | #pod =head1 USAGE
18 |  |  |  |  | #pod
19 |  |  |  |  | #pod The help text is generated from three sources:
20 |  |  |  |  | #pod
21 |  |  |  |  | #pod =for :list
22 |  |  |  |  | #pod * The C<usage_desc> method
23 |  |  |  |  | #pod * The C<description> method
24 |  |  |  |  | #pod * The C<opt_spec> data structure
25 |  |  |  |  | #pod
26 |  |  |  |  | #pod The C<usage_desc> method provides the opening usage line, following the
27 |  |  |  |  | #pod specification described in L<Getopt::Long::Descriptive>. In some cases,
28 |  |  |  |  | #pod the default C<usage_desc> in L<App::Cmd::Command> may be sufficient and
29 |  |  |  |  | #pod you will only need to override it to provide additional command line
30 |  |  |  |  | #pod usage information.
31 |  |  |  |  | #pod
32 |  |  |  |  | #pod The C<opt_spec> data structure is used with L<Getopt::Long::Descriptive>
33 |  |  |  |  | #pod to generate the description of the options.
34 |  |  |  |  | #pod
35 |  |  |  |  | #pod Subcommand classes should override the C<discription> method to provide
36 |  |  |  |  | #pod additional information that is prepended before the option descriptions.
37 |  |  |  |  | #pod
38 |  |  |  |  | #pod For example, consider the following subcommand module:
39 |  |  |  |  | #pod
40 |  |  |  |  | #pod package YourApp::Command::initialize;
41 |  |  |  |  | #pod
42 |  |  |  |  | #pod # This is the default from App::Cmd::Command
43 |  |  |  |  | #pod sub usage_desc {
44 |  |  |  |  | #pod my ($self) = @_;
45 |  |  |  |  | #pod my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
46 |  |  |  |  | #pod return "$desc [DIRECTORY]";
47 |  |  |  |  | #pod }
48 |  |  |  |  | #pod
49 |  |  |  |  | #pod sub description {
50 |  |  |  |  | #pod return "The initialize command prepares the application...";
51 |  |  |  |  | #pod }
52 |  |  |  |  | #pod
53 |  |  |  |  | #pod sub opt_spec {
54 |  |  |  |  | #pod return (
55 |  |  |  |  | #pod [ "skip-refs|R", "skip reference checks during init", ],
56 |  |  |  |  | #pod [ "values|v=s@", "starting values", { default => [ 0, 1, 3 ] } ],
57 |  |  |  |  | #pod );
58 |  |  |  |  | #pod }
59 |  |  |  |  | #pod
60 |  |  |  |  | #pod ...
61 |  |  |  |  | #pod
62 |  |  |  |  | #pod That module would generate help output like this:
63 |  |  |  |  | #pod
64 |  |  |  |  | #pod $ yourapp help initialize
65 |  |  |  |  | #pod yourapp initialize [-Rv] [long options...] [DIRECTORY]
66 |  |  |  |  | #pod
67 |  |  |  |  | #pod The initialize command prepares the application...
68 |  |  |  |  | #pod
69 |  |  |  |  | #pod --help This usage screen
70 |  |  |  |  | #pod -R --skip-refs skip reference checks during init
71 |  |  |  |  | #pod -v --values starting values
72 |  |  |  |  | #pod
73 |  |  |  |  | #pod =cut
74 |  |  |  |  |
75 |  |  |  |  | sub usage_desc { '%c help [subcommand]' }
76 |  |  |  |  |
77 | 1 | 3µs |  |  | # spent 2µs within App::Cmd::Command::help::command_names which was called: # once (2µs+0s) by App::Cmd::_load_default_plugin at line 288 of App/Cmd.pm sub command_names { qw/help --help -h -?/ }
78 |  |  |  |  |
79 |  |  |  |  | sub execute {
80 |  |  |  |  | my ($self, $opts, $args) = @_;
81 |  |  |  |  |
82 |  |  |  |  | if (!@$args) {
83 |  |  |  |  | print $self->app->usage->text . "\n";
84 |  |  |  |  |
85 |  |  |  |  | print "Available commands:\n\n";
86 |  |  |  |  |
87 |  |  |  |  | $self->app->execute_command( $self->app->_prepare_command("commands") );
88 |  |  |  |  | } else {
89 |  |  |  |  | my ($cmd, $opt, $args) = $self->app->prepare_command(@$args);
90 |  |  |  |  |
91 |  |  |  |  | local $@;
92 |  |  |  |  | my $desc = $cmd->description;
93 |  |  |  |  | $desc = "\n$desc" if length $desc;
94 |  |  |  |  |
95 |  |  |  |  | my $ut = join "\n",
96 |  |  |  |  | eval { $cmd->usage->leader_text },
97 |  |  |  |  | $desc,
98 |  |  |  |  | eval { $cmd->usage->option_text };
99 |  |  |  |  |
100 |  |  |  |  | print "$ut\n";
101 |  |  |  |  | }
102 |  |  |  |  | }
103 |  |  |  |  |
104 | 1 | 2µs |  |  | 1;
105 |  |  |  |  |
106 |  |  |  |  | __END__