File: Simple.pm

package info (click to toggle)
libmoosex-app-perl 1.41-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 764 kB
  • sloc: perl: 4,004; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ============================================================================
package MooseX::App::Meta::Role::Class::Simple;
# ============================================================================

use utf8;
use 5.010;

use namespace::autoclean;
use Moose::Role;

around 'command_usage_header' => sub {
    my ($orig,$self) = @_;

    my $caller = $self->app_base;

    my $usage;
    # Get usage from command if available
    if ($self->can('command_usage')
        && $self->command_usage_predicate) {
        $usage = MooseX::App::Utils::format_text($self->command_usage);
    }

    # Autobuild usage
    unless ($usage) {
        my $command = $caller;
        my @parameter= $self->command_usage_attributes($self,'parameter');
        foreach my $attribute (@parameter) {
            if ($attribute->is_required) {
                $command .= " <".$attribute->cmd_usage_name.'>';
            } else {
                $command .= ' ['.$attribute->cmd_usage_name.']';
            }
        }
        $usage = MooseX::App::Utils::format_text("$command [long options...]
$caller --help")
    }

    return $self->command_message(
        header  => 'usage:',
        body    => $usage
    ); # LOCALIZE
};

1;