| 1 | package HTTP::Balancer::Role::Command; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use Modern::Perl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use Namespace::Dispatch; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | with qw( HTTP::Balancer::Role | |||||||||||||||||||
| 10 | MooseX::Getopt::Dashes ); | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | around _usage_format => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 13 | 0 | my $orig = shift; | |||||||||||||||||||
| 14 | 0 | my $self = shift; | |||||||||||||||||||
| 15 | 0 | my $command_name = $self->command_name; | |||||||||||||||||||
| 16 | 0 | my $ordinary_args = join " ", map { "<$_>" } $self->ordinary_args; | |||||||||||||||||||
| 17 | 0 | "usage: %c $command_name $ordinary_args %o"; | |||||||||||||||||||
| 18 | 3 | }; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | HTTP::Balancer::Role::Command - the mixin for command handlers | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | package HTTP::Balancer::Command::SomeCommand; | ||||||||||||||||||||
| 27 | use Moose; | ||||||||||||||||||||
| 28 | with qw( HTTP::Balancer::Role::Command ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 METHODS | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head2 prepare() | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | the instance method called before running. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | the method is here to be hooked with 'around' keyword of Moose. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | sub prepare { | ||||||||||||||||||
|
Subroutine
prepare: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 41 | 0 | my ($self, ) = @_; | |||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =head2 command_name | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | class and instance method | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | returns the last name of current command, lowercase, separated with whitespace. | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub command_name { | ||||||||||||||||||
|
Subroutine
command_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 54 | 0 | my ($self, ) = @_; | |||||||||||||||||||
| 55 | 0 | ▶ | my $ref = ref($self) || $self; | ||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 56 | 0 | $ref =~ s{HTTP::Balancer::Command::}{}; | |||||||||||||||||||
| 57 | 0 | $ref =~ s{::}{ }g; | |||||||||||||||||||
| 58 | 0 | return lc($ref); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head2 ordinary_args | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | returns the ordinary arguments for arbitrary command handler. | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | the method is here to be overrided and returns empty list by default. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | sub ordinary_args { | ||||||||||||||||||
|
Subroutine
ordinary_args: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 70 | 0 | qw(); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =head2 argv($position) | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | helper. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | return the ordinary argument at $position or exit with help text. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | ▶ | sub argv { | ||||||||||||||||||
|
Subroutine
argv: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 82 | 0 | my ($self, $position) = @_; | |||||||||||||||||||
| 83 | 0 | ▶ | $self->extra_argv->[$position] or $self->usage->die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 3 | ▶ | no Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 3 | 1; | |||||||||||||||||||