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.3514_04'; # TRIAL |
5
|
|
|
|
|
|
|
$Dancer::GetOpt::VERSION = '1.351404'; |
6
|
168
|
|
|
168
|
|
56603
|
use strict; |
|
168
|
|
|
|
|
292
|
|
|
168
|
|
|
|
|
4232
|
|
7
|
168
|
|
|
168
|
|
750
|
use warnings; |
|
168
|
|
|
|
|
325
|
|
|
168
|
|
|
|
|
4215
|
|
8
|
|
|
|
|
|
|
|
9
|
168
|
|
|
168
|
|
2016
|
use Dancer::Config 'setting'; |
|
168
|
|
|
|
|
319
|
|
|
168
|
|
|
|
|
7278
|
|
10
|
168
|
|
|
168
|
|
97408
|
use Getopt::Long; |
|
168
|
|
|
|
|
1469093
|
|
|
168
|
|
|
|
|
686
|
|
11
|
168
|
|
|
168
|
|
81000
|
use FindBin; |
|
168
|
|
|
|
|
146315
|
|
|
168
|
|
|
|
|
6200
|
|
12
|
168
|
|
|
168
|
|
1009
|
use File::Spec; |
|
168
|
|
|
|
|
308
|
|
|
168
|
|
|
|
|
42510
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $options = { |
15
|
|
|
|
|
|
|
port => setting('port'), |
16
|
|
|
|
|
|
|
daemon => setting('daemon'), |
17
|
|
|
|
|
|
|
confdir => setting('confdir') || setting('appdir'), |
18
|
|
|
|
|
|
|
environment => 'development', |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub arg_to_setting { |
22
|
8
|
|
|
8
|
0
|
15
|
my ($option, $value) = @_; |
23
|
8
|
|
|
|
|
31
|
setting($option => $value); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub process_args { |
27
|
106
|
|
|
106
|
0
|
2789
|
my $help = 0; |
28
|
|
|
|
|
|
|
GetOptions( |
29
|
|
|
|
|
|
|
'help' => \$help, |
30
|
4
|
|
|
4
|
|
1835
|
'port=i' => sub { arg_to_setting(@_) }, |
31
|
2
|
|
|
2
|
|
771
|
'daemon' => sub { arg_to_setting(@_) }, |
32
|
1
|
|
|
1
|
|
417
|
'environment=s' => sub { arg_to_setting(@_) }, |
33
|
1
|
|
|
1
|
|
388
|
'confdir=s' => sub { arg_to_setting(@_) }, |
34
|
106
|
50
|
|
|
|
1212
|
) || usage_and_exit(); |
35
|
|
|
|
|
|
|
|
36
|
106
|
50
|
|
|
|
38504
|
usage_and_exit() if $help; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
0
|
0
|
0
|
sub usage_and_exit { print_usage() && exit(0) } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub print_usage { |
42
|
1
|
|
|
1
|
0
|
342
|
my $app = File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript ); |
43
|
1
|
|
|
|
|
19
|
print <
|
44
|
|
|
|
|
|
|
\$ $app [options] |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Options: |
47
|
|
|
|
|
|
|
--daemon Run in background (false) |
48
|
|
|
|
|
|
|
--port=XXXX Port number to bind to (3000) |
49
|
|
|
|
|
|
|
--confdir=PATH Path the config dir (appdir if not specified) |
50
|
|
|
|
|
|
|
--environment=ENV Environment to use (development) |
51
|
|
|
|
|
|
|
--help Display usage information |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
OPTIONS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
--daemon |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
When this flag is set, the Dancer script will detach from the terminal and will |
58
|
|
|
|
|
|
|
run in background. This is perfect for production environment but is not handy |
59
|
|
|
|
|
|
|
during the development phase. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
--port=XXXX |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This lets you change the port number to use when running the process. By |
64
|
|
|
|
|
|
|
default, the port 3000 will be used. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
--confdir=PATH |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
By default, Dancer looks in the appdir for config files (config.yml and |
69
|
|
|
|
|
|
|
environments files). You can change this with specifying an alternate path to |
70
|
|
|
|
|
|
|
the configdir option. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Dancer will then look in that directory for a file config.yml and the |
73
|
|
|
|
|
|
|
appropriate environement configuration file. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
If not specified, confdir points to appdir. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
--environment=ENV |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Which environment to use. By default this value is set to development. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
EOF |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
'Dancer::GetOpt'; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |