File Coverage

blib/lib/ExtUtils/ModuleMaker/Opts.pm
Criterion Covered Total %
statement 41 41 100.0
branch 38 42 90.4
condition n/a
subroutine 8 8 100.0
pod 2 3 66.6
total 89 94 94.6


line stmt bran cond sub pod time code
1             package ExtUtils::ModuleMaker::Opts;
2 1     1   742 use strict;
  1         2  
  1         25  
3 1     1   5 use warnings;
  1         1  
  1         45  
4             our $VERSION = "0.62";
5 1     1   606 use Getopt::Long;
  1         8589  
  1         5  
6 1     1   150 use Carp;
  1         3  
  1         100  
7              
8             sub new {
9 12     12 1 47812 my $class = shift;
10 12         34 my $eumm_package = shift;
11 12         27 my $eumm_script = shift;
12              
13 12         31 my $data = {};
14 12         39 $data->{NAME} = $class;
15             {
16 12         30 eval "require $eumm_package";
  12         764  
17 1     1   6 no strict 'refs';
  1         2  
  1         467  
18 12         51 $data->{VERSION} = ${$eumm_package . "::VERSION"};
  12         76  
19             }
20 12         39 $data->{PACKAGE} = $eumm_package;
21 12         30 $data->{SCRIPT} = $eumm_script;
22              
23 12         61 Getopt::Long::Configure("bundling");
24 12         479 my %opts;
25              
26             GetOptions(
27             # flags indicating on/off
28             "build_system|build-system|b" => \$opts{b},
29             "compact|c" => \$opts{c},
30             "changes_in_pod|changes-in-pod|C" => \$opts{C},
31             "help|h" => \$opts{h},
32             "no_interactive|no-interactive|I" => \$opts{I},
33             "no_pod|no-pod|P" => \$opts{P},
34             "no_new_method|no-new-method|q" => \$opts{q},
35             "save_as_defaults|save-as-defaults|s" => \$opts{s},
36             "verbose|V" => \$opts{V},
37              
38             # take string
39             # adenlopruvw
40             "abstract|a=s" => \$opts{a},
41             "alt_build|alt-build|d=s" => \$opts{d},
42             "email|e=s" => \$opts{e},
43             "name|n=s" => \$opts{n},
44             "license|l=s" => \$opts{l},
45             "organization|o=s" => \$opts{o},
46             "cpanid|p=s" => \$opts{p},
47             "permissions|r=s" => \$opts{r},
48             "author|u=s" => \$opts{u},
49             "version|v=s" => \$opts{v},
50             "website|w=s" => \$opts{w},
51              
52 12 50       161 ) or croak("Error in command line arguments\n");
53 12 100       35091 if ($opts{h}) {
54 2         11 print Usage($eumm_script, $eumm_package);
55 2         43 return;
56             }
57              
58             my %standard_options = (
59             # bcCIPqsV
60             ( ( $opts{b} ) ? ( BUILD_SYSTEM => 'Module::Build' ) : () ),
61             ( ( $opts{c} ) ? ( COMPACT => $opts{c} ) : () ),
62             ( ( $opts{C} ) ? ( CHANGES_IN_POD => $opts{C} ) : () ),
63             INTERACTIVE => ( ( $opts{I} ) ? 0 : 1 ),
64             ( ( $opts{P} ) ? ( NEED_POD => 0 ) : () ),
65             ( ( $opts{q} ) ? ( NEED_NEW_METHOD => 0 ) : () ),
66             ( ( $opts{s} ) ? ( SAVE_AS_DEFAULTS => $opts{s} ) : () ),
67             ( ( $opts{V} ) ? ( VERBOSE => $opts{V} ) : () ),
68              
69             # adenlopruvw
70             ( ( $opts{a} ) ? ( ABSTRACT => $opts{a} ) : () ),
71             ( ( $opts{d} ) ? ( ALT_BUILD => $opts{d} ) : () ),
72             ( ( $opts{e} ) ? ( EMAIL => $opts{e} ) : () ),
73             ( ( $opts{n} ) ? ( NAME => $opts{n} ) : () ),
74             ( ( $opts{l} ) ? ( LICENSE => $opts{l} ) : () ),
75             ( ( $opts{o} ) ? ( ORGANIZATION => $opts{o} ) : () ),
76             ( ( $opts{p} ) ? ( CPANID => $opts{p} ) : () ),
77             ( ( $opts{r} ) ? ( PERMISSIONS => $opts{r} ) : () ),
78             ( ( $opts{u} ) ? ( AUTHOR => $opts{u} ) : () ),
79             ( ( $opts{v} ) ? ( VERSION => $opts{v} ) : () ),
80             ( ( $opts{w} ) ? ( WEBSITE => $opts{w} ) : () ),
81              
82             USAGE_MESSAGE => Usage(
83             $data->{SCRIPT},
84             $data->{PACKAGE},
85             $data->{VERSION},
86 10 100       230 ),
    100          
    100          
    50          
    100          
    100          
    50          
    100          
    100          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
87             );
88              
89 10         107 $data->{STANDARD_OPTIONS} = { %standard_options };
90              
91 10         124 return bless $data, $class;
92             }
93              
94              
95             sub get_standard_options {
96 10     10 1 7078 my $self = shift;
97 10         25 return %{ $self->{STANDARD_OPTIONS} };
  10         101  
98             }
99              
100             sub Usage {
101 12     12 0 45 my ($script, $eumm_package) = @_;
102 12         130 my $message = <
103             modulemaker [-CIPVbch] [-n module_name] [-a abstract]
104             [-u author_name] [-p author_CPAN_ID] [-o organization]
105             [-w author_website] [-e author_e-mail]
106             [-l license_name] [-v version] [-s save_selections_as_defaults ]
107              
108             Currently Supported Features
109             -a|--abstract Specify (in quotes) an abstract for this extension
110             -b|--build_system Use Module::Build as build system for this extension
111             -c|--compact Flag for compact base directory name
112             -C|--changes_in_pod Omit creating the Changes file, add HISTORY heading to stub POD
113             -d|--alt_build Call methods which override default methods from this module
114             -e|--email Specify author's e-mail address
115             -h|--help Display this help message and exit
116             -I|--no_interactive Disable INTERACTIVE mode, the command line arguments better be complete
117             -l|--license Specify a license for this extension
118             -n|--name Specify a name to use for the extension (required)
119             -o|--organization Specify (in quotes) author's organization
120             -p|--cpanid Specify author's CPAN ID
121             -P|--no_pod Flag to omit the stub POD section from module
122             -q|--no_new_method Flag to omit a constructor from module
123             -r|--permissions Specify permissions
124             -s|--save_as_defaults Flag to save selections as new personal default values
125             -u|--author Specify (in quotes) author's name
126             -v|--version Specify an initial version number for this extension
127             -V|--verbose Flag for verbose messages during module creation
128             -w|--website Specify author's web site
129              
130             $script
131             $eumm_package version: $VERSION
132             ENDOFUSAGE
133              
134 12         107 return ($message);
135             }
136              
137             1;
138              
139             ################### DOCUMENTATION ###################
140              
141             =head1 NAME
142              
143             ExtUtils::ModuleMaker::Opts - Process command-line options for F
144              
145             =head1 SYNOPSIS
146              
147             use ExtUtils::ModuleMaker::Opts;
148              
149             $eumm_package = q{ExtUtils::ModuleMaker};
150             $eumm_script = q{modulemaker};
151              
152             $opt = ExtUtils::ModuleMaker::Opts->new(
153             $eumm_package,
154             $eumm_script,
155             );
156              
157             $mod = ExtUtils::ModuleMaker::Interactive->new(
158             $opt->get_standard_options()
159             );
160              
161             =head1 DESCRIPTION
162              
163             The methods in this package provide processing of command-line options for
164             F, the command-line utility associated with Perl extension
165             ExtUtils::ModuleMaker, and for similar utilities associated with Perl
166             extensions which subclass ExtUtils::ModuleMaker.
167              
168             =head1 METHODS
169              
170             =head2 C
171              
172             Usage : $opt = ExtUtils::ModuleMaker::Opts->new($package,$script) from
173             inside a command-line utility such as modulemaker
174             Purpose : Creates an ExtUtils::ModuleMaker::Opts object
175             Returns : An ExtUtils::ModuleMaker::Opts object
176             Argument : Two arguments:
177             1. String holding 'ExtUtils::ModuleMaker' or a package
178             subclassed therefrom, e.g., 'ExtUtils::ModuleMaker::PBP'.
179             2. String holding 'modulemaker' or the name of a command-line
180             utility similar to 'modulemaker' and found in the
181             'scripts/' directory of the distribution named in
182             argument 1
183              
184             =head2 C
185              
186             Usage : %standard_options = $opt->get_standard_options from
187             inside a command-line utility such as modulemaker
188             Purpose : Provide arguments to ExtUtils::ModuleMaker::Interactive::new()
189             or to the constructor of the 'Interactive' package of a
190             distribution subclassing ExtUtils::ModuleMaker
191             Returns : A hash suitable for passing to
192             ExtUtils::ModuleMaker::Interactive::new() or similar constructor
193             Argument : n/a
194              
195             =head1 SEE ALSO
196              
197             F, F,
198             F, F,
199             F.
200              
201             =cut
202