| 1 | package Dancer::GetOpt; | ||||||||||||||||||||
| 2 | 183 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||||||||||
| 3 | # ABSTRACT: Process command-line options for Dancer scripts | ||||||||||||||||||||
| 4 | 183 | $Dancer::GetOpt::VERSION = '1.3522'; | |||||||||||||||||||
| 5 | 183 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 183 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 183 | ▶ | use Dancer::Config 'setting'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 183 | ▶ | use Getopt::Long; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 183 | ▶ | use FindBin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 183 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 183 | ▶ | my $options = { | ||||||||||||||||||
|
Condition33%1/3
setting('confdir') || setting('appdir')
MC/DC0%0/2
setting('confdir') || setting('appdir')
setting('confdir')
setting('appdir')
Truth table33%1/3
A || B
A= setting('confdir')B= setting('appdir')
| |||||||||||||||||||||
| 14 | port => setting('port'), | ||||||||||||||||||||
| 15 | daemon => setting('daemon'), | ||||||||||||||||||||
| 16 | confdir => setting('confdir') || setting('appdir'), | ||||||||||||||||||||
| 17 | environment => 'development', | ||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 8 | ▶ | sub arg_to_setting { | ||||||||||||||||||
|
Subroutine
arg_to_setting: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 21 | 8 | my ($option, $value) = @_; | |||||||||||||||||||
| 22 | 8 | setting($option => $value); | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 105 | ▶ | sub process_args { | ||||||||||||||||||
|
Subroutine
process_args: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||
| 26 | 105 | my $help = 0; | |||||||||||||||||||
| 27 | GetOptions( | ||||||||||||||||||||
| 28 | 'help' => \$help, | ||||||||||||||||||||
| 29 | 4 | ▶ | 'port=i' => sub { arg_to_setting(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 2 | ▶ | 'daemon' => sub { arg_to_setting(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 1 | ▶ | 'environment=s' => sub { arg_to_setting(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 1 | ▶ | 'confdir=s' => sub { arg_to_setting(@_) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 105 | ▶ | ) || usage_and_exit(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 105 | ▶ | usage_and_exit() if $help; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | sub usage_and_exit { print_usage() && exit(0) } | ||||||||||||||||||
|
Subroutine
usage_and_exit: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | sub print_usage { | ||||||||||||||||||
|
Subroutine
print_usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 41 | 1 | my $app = File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript ); | |||||||||||||||||||
| 42 | 1 | print <<EOF | |||||||||||||||||||
| 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 | 183 | 'Dancer::GetOpt'; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||