line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::GetOpt; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Process command-line options for Dancer scripts |
4
|
|
|
|
|
|
|
$Dancer::GetOpt::VERSION = '1.3521'; |
5
|
167
|
|
|
167
|
|
68578
|
use strict; |
|
167
|
|
|
|
|
382
|
|
|
167
|
|
|
|
|
4986
|
|
6
|
167
|
|
|
167
|
|
963
|
use warnings; |
|
167
|
|
|
|
|
391
|
|
|
167
|
|
|
|
|
5107
|
|
7
|
|
|
|
|
|
|
|
8
|
167
|
|
|
167
|
|
2633
|
use Dancer::Config 'setting'; |
|
167
|
|
|
|
|
400
|
|
|
167
|
|
|
|
|
7787
|
|
9
|
167
|
|
|
167
|
|
126137
|
use Getopt::Long; |
|
167
|
|
|
|
|
1776496
|
|
|
167
|
|
|
|
|
847
|
|
10
|
167
|
|
|
167
|
|
93639
|
use FindBin; |
|
167
|
|
|
|
|
178833
|
|
|
167
|
|
|
|
|
7615
|
|
11
|
167
|
|
|
167
|
|
1238
|
use File::Spec; |
|
167
|
|
|
|
|
435
|
|
|
167
|
|
|
|
|
53333
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $options = { |
14
|
|
|
|
|
|
|
port => setting('port'), |
15
|
|
|
|
|
|
|
daemon => setting('daemon'), |
16
|
|
|
|
|
|
|
confdir => setting('confdir') || setting('appdir'), |
17
|
|
|
|
|
|
|
environment => 'development', |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub arg_to_setting { |
21
|
8
|
|
|
8
|
0
|
17
|
my ($option, $value) = @_; |
22
|
8
|
|
|
|
|
26
|
setting($option => $value); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub process_args { |
26
|
105
|
|
|
105
|
0
|
4734
|
my $help = 0; |
27
|
|
|
|
|
|
|
GetOptions( |
28
|
|
|
|
|
|
|
'help' => \$help, |
29
|
4
|
|
|
4
|
|
2186
|
'port=i' => sub { arg_to_setting(@_) }, |
30
|
2
|
|
|
2
|
|
946
|
'daemon' => sub { arg_to_setting(@_) }, |
31
|
1
|
|
|
1
|
|
466
|
'environment=s' => sub { arg_to_setting(@_) }, |
32
|
1
|
|
|
1
|
|
468
|
'confdir=s' => sub { arg_to_setting(@_) }, |
33
|
105
|
50
|
|
|
|
1403
|
) || usage_and_exit(); |
34
|
|
|
|
|
|
|
|
35
|
105
|
50
|
|
|
|
46591
|
usage_and_exit() if $help; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
0
|
0
|
0
|
sub usage_and_exit { print_usage() && exit(0) } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub print_usage { |
41
|
1
|
|
|
1
|
0
|
464
|
my $app = File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript ); |
42
|
1
|
|
|
|
|
1414
|
print <
|
43
|
|
|
|
|
|
|
\$ $app [options] |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Options: |
46
|
|
|
|
|
|
|
--daemon Run in background (false) |
47
|
|
|
|
|
|
|
--port=XXXX Port number to bind to (3000) |
48
|
|
|
|
|
|
|
--confdir=PATH Path the config dir (appdir if not specified) |
49
|
|
|
|
|
|
|
--environment=ENV Environment to use (development) |
50
|
|
|
|
|
|
|
--help Display usage information |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
OPTIONS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
--daemon |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
When this flag is set, the Dancer script will detach from the terminal and will |
57
|
|
|
|
|
|
|
run in background. This is perfect for production environment but is not handy |
58
|
|
|
|
|
|
|
during the development phase. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
--port=XXXX |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This lets you change the port number to use when running the process. By |
63
|
|
|
|
|
|
|
default, the port 3000 will be used. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
--confdir=PATH |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
By default, Dancer looks in the appdir for config files (config.yml and |
68
|
|
|
|
|
|
|
environments files). You can change this with specifying an alternate path to |
69
|
|
|
|
|
|
|
the configdir option. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Dancer will then look in that directory for a file config.yml and the |
72
|
|
|
|
|
|
|
appropriate environement configuration file. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
If not specified, confdir points to appdir. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
--environment=ENV |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Which environment to use. By default this value is set to development. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
EOF |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
'Dancer::GetOpt'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |