line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::JobLog::Command; |
2
|
|
|
|
|
|
|
$App::JobLog::Command::VERSION = '1.039'; |
3
|
|
|
|
|
|
|
# ABSTRACT: common functionality of App::JobLog commands |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
4903
|
use App::Cmd::Setup -command; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
37
|
|
6
|
5
|
|
|
5
|
|
2638
|
use Modern::Perl; |
|
5
|
|
|
|
|
8235
|
|
|
5
|
|
|
|
|
40
|
|
7
|
5
|
|
|
5
|
|
1938
|
use App::JobLog::Config qw(columns); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
1329
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub opt_spec { |
10
|
26
|
|
|
26
|
1
|
56
|
my ( $class, $app ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
26
|
|
|
|
|
115
|
return ( $class->options($app), [ 'help' => "this usage screen" ] ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# makes sure everything has some sort of description |
16
|
|
|
|
|
|
|
sub description { |
17
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# abstract provides default text |
20
|
0
|
|
|
|
|
0
|
my $desc = $self->full_description; |
21
|
0
|
0
|
|
|
|
0
|
unless ($desc) { |
22
|
0
|
|
|
|
|
0
|
( $desc = $self->abstract ) =~ s/^\s++|\s++$//g; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ensure initial capitalization |
25
|
5
|
|
|
5
|
|
4417
|
$desc =~ s/^(\p{Ll})/uc $1/e; |
|
5
|
|
|
|
|
54
|
|
|
5
|
|
|
|
|
148
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# add sentence-terminal punctuation as necessary |
28
|
0
|
|
|
|
|
0
|
$desc =~ s/(\w)$/$1./; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# make sure things are wrapped nicely |
32
|
0
|
|
|
|
|
0
|
_wrap( \$desc ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# space between description and options text |
35
|
0
|
|
|
|
|
0
|
$desc .= "\n"; |
36
|
0
|
|
|
|
|
0
|
return $desc; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# performs text wrapping while preserving the formatting of lines beginning with whitespace |
40
|
|
|
|
|
|
|
sub _wrap { |
41
|
0
|
|
|
0
|
|
0
|
my $desc = shift; |
42
|
0
|
|
|
|
|
0
|
require Text::WrapI18N; |
43
|
0
|
|
|
|
|
0
|
$Text::WrapI18N::columns = columns; |
44
|
0
|
|
|
|
|
0
|
my ( $current, @gathered ); |
45
|
0
|
|
|
|
|
0
|
for my $line ( $$desc =~ /^(.*?)\s*$/mg ) { |
46
|
0
|
0
|
|
|
|
0
|
if ( $line =~ /^\S/ ) { |
47
|
0
|
0
|
|
|
|
0
|
if ($current) { |
48
|
0
|
|
|
|
|
0
|
$current .= " $line"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
0
|
$current = $line; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
0
|
|
|
|
0
|
push @gathered, Text::WrapI18N::wrap( '', '', $current ) |
56
|
|
|
|
|
|
|
if defined $current; |
57
|
0
|
|
|
|
|
0
|
push @gathered, $line; |
58
|
0
|
|
|
|
|
0
|
$current = undef; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
0
|
|
|
|
0
|
push @gathered, Text::WrapI18N::wrap( '', '', $current ) |
62
|
|
|
|
|
|
|
if defined $current; |
63
|
0
|
|
|
|
|
0
|
$$desc = join "\n", @gathered; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# override to make full description |
67
|
|
|
|
0
|
0
|
|
sub full_description { } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub validate_args { |
70
|
26
|
|
|
26
|
1
|
50419
|
my ( $self, $opt, $args ) = @_; |
71
|
26
|
50
|
|
|
|
223
|
die $self->_usage_text if $opt->{help}; |
72
|
26
|
|
|
|
|
107
|
$self->validate( $opt, $args ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# obtains command name |
76
|
|
|
|
|
|
|
sub name { |
77
|
43
|
|
|
43
|
0
|
1966
|
( my $command = shift ) =~ s/.*:://; |
78
|
43
|
|
|
|
|
429
|
return $command; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# by default a command has no options other than --help |
82
|
|
|
|
0
|
0
|
|
sub options { } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# by default a command does no argument validation |
85
|
|
|
|
12
|
0
|
|
sub validate { } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# add to simple commands after argument signature so they'll complain if given arguments |
88
|
|
|
|
|
|
|
sub simple_command_check { |
89
|
0
|
|
|
0
|
0
|
|
my ( $self, $args ) = @_; |
90
|
0
|
0
|
|
|
|
|
$self->usage_error("This command does not expect any arguments! No action taken.") if @$args; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |