blib/lib/Dancer/GetOpt.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 33.3% 2 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 4 totaltotal 77.7% 49 / 63 SCAR 14.0
CC
4
Cov
84%
usage_and_exit
6.0
process_args
3.1
BEGIN
1.0
CRAP 4.1
« blib/lib/Dancer/Hook/Properties.pm ↑ Summary blib/lib/Dancer/Handler/Debug.pm »
1 package Dancer::GetOpt;
2 176 our $AUTHORITY = 'cpan:SUKRIA';
3 # ABSTRACT: Process command-line options for Dancer scripts
4 176 $Dancer::GetOpt::VERSION = '1.3520';
5 176 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 176 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 176 ▶use Dancer::Config 'setting';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 176 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 176 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 176 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 176 ▶my $options = {
Condition33%1/3
setting('confdir') || setting('appdir')
l!l&&r!l&&!r
00176
MC/DC0%0/2
setting('confdir') || setting('appdir')
setting('confdir') setting('appdir')
Truth table33%1/3
A || B
A= setting('confdir')B= setting('appdir')
ABresult
1X1
011
000
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 ▶ my ($option, $value) = @_;
Subroutine arg_to_setting: called CC=1 SCAR=0.0
Pod undocumented
22 8 setting($option => $value);
23 }
24  
25 sub process_args {
26 105 ▶ my $help = 0;
Subroutine process_args: called CC=3 SCAR=11.2
Pod undocumented
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
BranchTrueFalseTotal
&GetOptions("help", \$help, "port=i", sub { arg_to_setting(@_); } , "daemon", sub { arg_to_setting(@_); } , "environment=s", sub { arg_to_setting(@_); } , "confdir=s", sub { arg_to_setting(@_); } ) or usage_and_exit() 0 105 105
34  
35 105 ▶ usage_and_exit() if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 105 105
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
BranchTrueFalseTotal
print_usage() and exit 0 0 0 0
39  
40 sub print_usage {
41 1 ▶ my $app = File::Spec->catfile( $FindBin::RealBin, $FindBin::RealScript );
Subroutine print_usage: called CC=1 SCAR=0.0
Pod undocumented
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 176 'Dancer::GetOpt';
85  
86 __END__
« blib/lib/Dancer/Hook/Properties.pm ↑ Summary blib/lib/Dancer/Handler/Debug.pm »