line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Balancer::Role::Command; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Modern::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
580
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Namespace::Dispatch; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with qw( HTTP::Balancer::Role |
10
|
|
|
|
|
|
|
MooseX::Getopt::Dashes ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
around _usage_format => sub { |
13
|
|
|
|
|
|
|
my $orig = shift; |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
my $command_name = $self->command_name; |
16
|
|
|
|
|
|
|
my $ordinary_args = join " ", map { "<$_>" } $self->ordinary_args; |
17
|
|
|
|
|
|
|
"usage: %c $command_name $ordinary_args %o"; |
18
|
|
|
|
|
|
|
}; |
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
|
|
|
|
|
|
|
sub prepare { |
41
|
|
|
|
|
|
|
my ($self, ) = @_; |
42
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub command_name { |
54
|
|
|
|
|
|
|
my ($self, ) = @_; |
55
|
|
|
|
|
|
|
my $ref = ref($self) || $self; |
56
|
|
|
|
|
|
|
$ref =~ s{HTTP::Balancer::Command::}{}; |
57
|
|
|
|
|
|
|
$ref =~ s{::}{ }g; |
58
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub ordinary_args { |
70
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub argv { |
82
|
|
|
|
|
|
|
my ($self, $position) = @_; |
83
|
|
|
|
|
|
|
$self->extra_argv->[$position] or $self->usage->die; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
no Moose::Role; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |