line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# App::Cmdline::Options::Basic |
3
|
|
|
|
|
|
|
# Author: Martin Senger |
4
|
|
|
|
|
|
|
# For copyright and disclaimer see the POD. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# ABSTRACT: set of basic options for command-line applications |
7
|
|
|
|
|
|
|
# PODNAME: App::Cmdline::Options::Basic |
8
|
|
|
|
|
|
|
#----------------------------------------------------------------- |
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
10
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package App::Cmdline::Options::Basic; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.1.2'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @OPT_SPEC = ( |
17
|
|
|
|
|
|
|
[ 'h' => "display a short usage message" ], |
18
|
|
|
|
|
|
|
[ 'version|v' => "display a version" ], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
22
|
|
|
|
|
|
|
# Return definition of my options |
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub get_opt_spec { |
25
|
1
|
|
|
1
|
0
|
5
|
return @OPT_SPEC; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
29
|
|
|
|
|
|
|
# Do typical actions with my options. |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# Why am I first trying with $opt->can? Just in case, somebody called |
32
|
|
|
|
|
|
|
# composed_of (which instaled a call here) but has not returned (from |
33
|
|
|
|
|
|
|
# opt_spec) what the composed_of returned him). |
34
|
|
|
|
|
|
|
# ---------------------------------------------------------------- |
35
|
|
|
|
|
|
|
sub validate_opts { |
36
|
1
|
|
|
1
|
0
|
2
|
my ($class, $app, $caller, $opt, $args) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# show help and exit |
39
|
1
|
50
|
33
|
|
|
21
|
if ($opt->can ('h') and $opt->h) { |
40
|
0
|
|
|
|
|
0
|
print "Usage: " . $caller->usage(); |
41
|
0
|
0
|
|
|
|
0
|
if ($^S) { die "Okay\n" } else { exit (0) }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# show version and exit |
45
|
1
|
50
|
33
|
|
|
43
|
if ($opt->can ('version') and $opt->version) { |
46
|
|
|
|
|
|
|
## no critic |
47
|
1
|
|
|
1
|
|
6
|
no strict; # because the $VERSION will be added only when |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
48
|
1
|
|
|
1
|
|
6
|
no warnings; # the distribution is fully built up |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
121
|
|
49
|
0
|
|
|
|
|
0
|
print ${"${app}::VERSION"} . "\n"; |
|
0
|
|
|
|
|
0
|
|
50
|
0
|
0
|
|
|
|
0
|
if ($^S) { die "Okay\n" } else { exit (0) }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
11
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
App::Cmdline::Options::Basic - set of basic options for command-line applications |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 VERSION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
version 0.1.2 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# In your module that represents a command-line application: |
72
|
|
|
|
|
|
|
sub opt_spec { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
return $self->check_for_duplicates ( |
75
|
|
|
|
|
|
|
[ 'check|c' => "only check the configuration" ], |
76
|
|
|
|
|
|
|
..., |
77
|
|
|
|
|
|
|
$self->composed_of ( |
78
|
|
|
|
|
|
|
'App::Cmdline::Options::Basic', # here are the basic options added |
79
|
|
|
|
|
|
|
'App::Cmdline::Options::DB', # here may be other options |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DESCRIPTION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This is a kind of a I module, defining a particular set of |
87
|
|
|
|
|
|
|
command-line options and their validation. See more about how to write |
88
|
|
|
|
|
|
|
a module that represents a command-line application and that uses this |
89
|
|
|
|
|
|
|
set of options in L. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 OPTIONS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Particularly, this module specifies the basic options, usually used by |
94
|
|
|
|
|
|
|
any command-line application: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
[ 'h' => "display a short usage message" ], |
97
|
|
|
|
|
|
|
[ 'version|v' => "display a version" ], |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 -h |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
It prints a short usage message, something like this: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Usage: myapp [non-bundled short or long options] |
104
|
|
|
|
|
|
|
-h display a short usage message |
105
|
|
|
|
|
|
|
-v --version display a version |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 --version |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
It print the version of the application and exits in one of the two |
110
|
|
|
|
|
|
|
possible ways: If it is called from and C expression, it dies |
111
|
|
|
|
|
|
|
(so you can catch it and continue). Otherwise, it exists with the exit |
112
|
|
|
|
|
|
|
code zero. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Martin Senger |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Martin Senger, CBRC - KAUST (Computational Biology Research Center - King Abdullah University of Science and Technology) All Rights Reserved. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
123
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |