File: Class.pm

package info (click to toggle)
libmoosex-app-perl 1.42-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 736 kB
  • sloc: perl: 4,004; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download | duplicates (4)
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
# ============================================================================
package MooseX::App::Plugin::Depends::Meta::Class;
# ============================================================================

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

around 'command_check_attributes' => sub {
    my ($orig, $self, $command_meta, $errors, $params) = @_;
    $command_meta ||= $self;

    ATTR:
    foreach my $attribute ( $self->command_usage_attributes($command_meta, 'all') ) {
        next ATTR
            unless defined $params->{ $attribute->cmd_name_primary };
        next ATTR
            unless $attribute->can('depends')
            && ref($attribute->depends) eq 'ARRAY'
            && scalar @{ $attribute->depends } > 0;

    OPT:
    foreach my $required_option ( @{ $attribute->depends } ) {
        next OPT
            if defined $params->{$required_option};

        my $error_msg = "Option "
            . "'" . $attribute->cmd_name_primary . "'"
            . " requires '$required_option' to be defined";

        push @$errors,
            $self->command_message(
               header => $error_msg,
               type   => 'error',
            );
        }
    }

    return $self->$orig($command_meta, $errors, $params);
};

1;