EX/Loader.pm

filter: Statementstmt 78.5% 168 / 214 Branchbran 61.0% 61 / 100 Conditioncond 19.0% 4 / 21 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 84.8% 28 / 33 Podpod 20.0% 4 / 20 totaltotal 66.6% 266 / 399 CC 68 SCAR 25.0
CC
68
Cov
70%
debug_argv
57.3
modules
30.0
expand
14.3
CRAP 12.2
« EX/Module.pm ↑ Summary EX/LabeledParam.pm »
1 package Getopt::EX::Loader;
2  
3 8 our $VERSION = "3.05";
4  
5 8 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 our @EXPORT = qw();
12 8 our %EXPORT_TAGS = ( );
13 8 our @EXPORT_OK = qw();
14  
15 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use List::Util qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use Getopt::EX::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Getopt::EX::Func qw(parse_func);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Getopt::EX::Colormap qw(colorize);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 8 our $debug = 0;
23  
24 25 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
25 25 my $class = shift;
26  
27 25 my $obj = bless {
28 BUCKETS => [],
29 BASECLASS => undef,
30 MODULE_OPT => '-M',
31 DEFAULT => 'default',
32 PARSE_MODULE_OPT => 1,
33 IGNORE_NO_MODULE => 0,
34 IGNORE_NO_FILE => 1,
35 }, $class;
36  
37 25 ▶ $obj->configure(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 25 0 25
38  
39 25 $obj;
40 }
41  
42 8 our @OPTIONS = qw(
43 RCFILE
44 BASECLASS
45 MODULE_OPT
46 DEFAULT
47 PARSE_MODULE_OPT
48 IGNORE_NO_MODULE
49 IGNORE_NO_FILE
50 );
51  
52 25 ▶sub configure {
Subroutine configure: called CC=8 SCAR=20.9
Pod documented
53 25 my $obj = shift;
54 25 my %opt = @_;
55  
56 25 for my $opt (@OPTIONS) {
57 175 ▶ next if $opt eq 'RCFILE';
Branch: 1 branch
BranchTrueFalseTotal
if $opt eq "RCFILE" 25 150 175
58 150 ▶ if (exists $opt{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt{$opt}) 25 125 150
59 25 $obj->{$opt} = delete $opt{$opt};
60 }
61 }
62  
63 25 ▶ if (my $rc = delete $opt{RCFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = delete $opt{"RCFILE"}) 8 17 25
64 8 ▶ my @rc = ref $rc eq 'ARRAY' ? @$rc : $rc;
Branch: 1 branch
BranchTrueFalseTotal
ref $rc eq 'ARRAY' ? : 0 8 8
65 8 for (@rc) {
66 8 $obj->load(FILE => $_);
67 }
68 }
69  
70 25 ▶ warn "Unknown option: ", Dumper \%opt if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 25 25
71  
72 25 $obj;
73 }
74  
75 85 ▶sub baseclass {
Subroutine baseclass: called CC=2 SCAR=7.2
Pod undocumented
76 85 my $obj = shift;
77 @_ ? $obj->{BASECLASS} = shift
78 85 ▶ : $obj->{BASECLASS};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 85 85
79 }
80  
81 207 ▶sub buckets {
Subroutine buckets: called CC=1 SCAR=0.0
Pod documented
82 207 my $obj = shift;
83 207 @{ $obj->{BUCKETS} };
84 }
85  
86 19 ▶sub append {
Subroutine append: called CC=1 SCAR=0.0
Pod undocumented
87 19 my $obj = shift;
88 19 push @{ $obj->{BUCKETS} }, @_;
89 }
90  
91 45 ▶sub load {
Subroutine load: called CC=4 SCAR=14.0
Pod undocumented
92 45 my $obj = shift;
93 45 my %arg = @_;
94 45 ▶ if ($obj->{IGNORE_NO_FILE} and my $file = $arg{FILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"IGNORE_NO_FILE"} and my $file = $arg{"FILE"}) 9 36 45
Condition66%2/3
$obj->{"IGNORE_NO_FILE"} and my $file = $arg{"FILE"}
!ll&&!rl&&r
0369
MC/DC50%1/2
$obj->{"IGNORE_NO_FILE"} and my $file = $arg{"FILE"}
$obj->{"IGNORE_NO_FILE"} my $file = $arg{"FILE"}
Truth table66%2/3
A and B
A= $obj->{"IGNORE_NO_FILE"}B= my $file = $arg{"FILE"}
ABresult
0X0
100
111
95 9 ▶ return undef unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 9 9
96 }
97 45 my $bucket =
98 Getopt::EX::Module->new(@_, BASECLASS => $obj->baseclass);
99 19 $obj->append($bucket);
100 19 $bucket;
101 }
102  
103 1 ▶sub load_file {
Subroutine load_file: called CC=1 SCAR=0.0
Pod documented
104 1 my $obj = shift;
105 1 $obj->load(FILE => shift);
106 }
107  
108 40 ▶sub load_module {
Subroutine load_module: called CC=2 SCAR=6.9
Pod documented
109 40 my $obj = shift;
110 40 my $name = shift;
111 40 ▶ if (my $mod = $obj->find_module($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod = $obj->find_module($name)) 4 36 40
112 4 return $mod;
113 }
114 36 $obj->load(MODULE => $name);
115 }
116  
117 40 ▶sub find_module {
Subroutine find_module: called CC=5 SCAR=16.1
Pod undocumented
118 40 my $obj = shift;
119 40 my $name = shift;
120 40 my $base = $obj->baseclass;
121 40 ▶ my @class = ref $base ? @$base : $base;
Branch: 1 branch
BranchTrueFalseTotal
ref $base ? : 2 38 40
122 40 for my $class (@class) {
123 43 my $module = "$class\::$name";
124 43 for ($obj->buckets) {
125 19 ▶ if ($_->module eq $module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->module eq $module) 4 15 19
126 4 return $_;
127 }
128 }
129 }
130 36 undef;
131 }
132  
133 0 ▶sub defaults {
Subroutine defaults: not called CC=1 SCAR=6.9
Pod undocumented
134 0 my $obj = shift;
135 0 map { $_->default } $obj->buckets;
136 }
137  
138 0 ▶sub calls {
Subroutine calls: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my $obj = shift;
140 0 map { $_->call } $obj->buckets;
141 }
142  
143 19 ▶sub builtins {
Subroutine builtins: called CC=1 SCAR=0.0
Pod undocumented
144 19 my $obj = shift;
145 19 map { $_->builtin } $obj->buckets;
146 }
147  
148 2 ▶sub hashed_builtins {
Subroutine hashed_builtins: called CC=1 SCAR=0.0
Pod undocumented
149 2 my $obj = shift;
150 2 my $hash = shift;
151 8 ▶ pairmap {
Subroutine __ANON__: called CC=2 SCAR=7.1
152 8 ▶ my($key) = $a =~ /^([-\w]+)/ or die;
Branch: 1 branch
BranchTrueFalseTotal
my($key) = $a =~ /^([-\w]+)/u or die 8 0 8
153 8 $hash->{$key} = $b;
154 8 $a;
155 2 } $obj->builtins;
156 }
157  
158 26 ▶sub deal_with {
Subroutine deal_with: called CC=5 SCAR=17.8
Pod undocumented
159 26 my $obj = shift;
160 26 my $argv = shift;
161  
162 26 ▶ if (my $default = $obj->{DEFAULT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $default = $obj->{"DEFAULT"}) 26 0 26
163 26 ▶ if (my $bucket = eval { $obj->load_module($default) }) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $bucket = eval { do { $obj->load_module($default) } }) { } 0 26 26
elsif (not $@ =~ /Can't locate|need to install/u) { } 0 26 26
164 0 $bucket->run_inits($argv);
165 } elsif ($@ !~ /Can't locate|need to install/) {
166 0 die $@;
167 }
168 }
169 26 ▶ $obj->modopt($argv) if $obj->{PARSE_MODULE_OPT};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"PARSE_MODULE_OPT"} 26 0 26
170 26 $obj->expand($argv);
171 26 $obj;
172 }
173  
174 67 ▶sub modopt {
Subroutine modopt: called CC=6 SCAR=18.2
Pod undocumented
175 67 my $obj = shift;
176 67 my $argv = shift;
177  
178 67 ▶ my $start = $obj->{MODULE_OPT} // return ();
Condition50%1/2
$obj->{"MODULE_OPT"} // (return ())
l!l
670
MC/DC0%0/1
$obj->{"MODULE_OPT"} // (return ())
$obj->{"MODULE_OPT"}
Truth table50%1/2
A
A= $obj->{"MODULE_OPT"}
Aresult
11
00
179 67 ▶ $start eq '' and return ();
Branch: 1 branch
BranchTrueFalseTotal
$start eq "" and return () 0 67 67
180 67 my $start_re = qr/\Q$start\E/;
181 67 my @modules;
182 67 ▶ while (@$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$argv) 75 3 78
183 75 ▶ if (my($modpart) = ($argv->[0] =~ /^$start_re(.+)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($modpart) = $argv->[0] =~ /^$start_re(.+)/u) 11 64 75
184 11 debug_argv($argv);
185 11 ▶ if (my $mod = $obj->parseopt($modpart, $argv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod = $obj->parseopt($modpart, $argv)) { } 11 0 11
186 11 push @modules, $mod;
187 } else {
188 0 last;
189 }
190 11 next;
191 }
192 64 last;
193 }
194 67 @modules;
195 }
196  
197 11 ▶sub parseopt {
Subroutine parseopt: called CC=6 SCAR=23.0
Pod undocumented
198 11 my $obj = shift;
199 11 my($mod, $argv) = @_;
200 11 my $call;
201  
202 ##
203 ## Check -Mmod::func(arg) or -Mmod::func=arg
204 ##
205 11 ▶ if ($mod =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ s/ ^ (?<name> \w+ (?: :: \w+)* ) (?: :: (?<call> \w+ (?: (?<P>[(]) | = ) ## start with '(' or '=' (?<arg> [^)]* ) ## optional arg list (?(<P>) [)] | ) ## close ')' or none ) )? $ /$+{"name"}/ux) 11 0 11
206 ^ (?<name> \w+ (?: :: \w+)* )
207 (?:
208 ::
209 (?<call>
210 \w+
211 (?: (?<P>[(]) | = ) ## start with '(' or '='
212 (?<arg> [^)]* ) ## optional arg list
213 (?(<P>) [)] | ) ## close ')' or none
214 )
215 )?
216 $
217 }{$+{name}}x) {
218 11 $call = $+{call};
219 }
220  
221 11 ▶ my $bucket = eval { $obj->load_module($mod) } or do {
Branch: 1 branch
BranchTrueFalseTotal
my $bucket = eval { do { $obj->load_module($mod) } } or do { if ($@ =~ /Can't locate|need to install/u) { if ($obj->{"IGNORE_NO_MODULE"}) { return undef; } else { die qq[Can't load module "$mod".\n]; } ; } else { die $@; } } 11 0 11
222 0 ▶ if ($@ =~ /Can't locate|need to install/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /Can't locate|need to install/u) { } 0 0 0
223 0 ▶ if ($obj->{IGNORE_NO_MODULE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'IGNORE_NO_MODULE'}) { } 0 0 0
224 0 return undef;
225 } else {
226 0 die "Can't load module \"$mod\".\n";
227 }
228 } else {
229 0 die $@;
230 }
231 };
232  
233 11 shift @$argv;
234  
235 11 ▶ if ($call) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call) 0 11 11
236 0 $bucket->call(join '::', $bucket->module, $call);
237 }
238  
239 ##
240 ## If &getopt is defined in module, call it and replace @ARGV.
241 ##
242 11 $bucket->run_inits($argv);
243  
244 11 $bucket;
245 }
246  
247 26 ▶sub expand {
Subroutine expand: called CC=13 SCAR=26.6
Pod undocumented
248 26 my $obj = shift;
249 26 my $argv = shift;
250  
251 ##
252 ## Insert module defaults.
253 ##
254 unshift @$argv, map {
255 26 ▶ if (my @s = $_->default()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@s) = $_->default) { } 14 6 20
256 14 my @modules = $obj->modopt(\@s);
257 0 [ @s, map { $_->default } @modules ];
258 } else {
259 6 ();
260 }
261 } $obj->buckets;
262  
263 ##
264 ## Expand user defined option.
265 ##
266 ARGV:
267 26 ▶ for (my $i = 0; $i < @$argv; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$argv) 92 26 118
268  
269 119 ▶ last if $argv->[$i] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $argv->[$i] eq "--" 0 119 119
270 119 my $current = $argv->[$i];
271  
272 119 for my $bucket ($obj->buckets) {
273  
274 130 my @s;
275 130 ▶ if (ref $current eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $current eq 'ARRAY') { } 14 116 130
276 ##
277 ## Expand defaults.
278 ##
279 14 @s = @$current;
280 14 $current = 'DEFAULT';
281 }
282 else {
283 ##
284 ## Try entire string match, and check --option=value.
285 ##
286 116 @s = $bucket->getopt($current);
287 116 ▶ if (not @s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@s) 103 13 116
288 103 ▶ $current =~ /^(.+?)=(.*)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
$current =~ /^(.+?)=(.*)/u or next 6 97 103
289 6 ▶ @s = $bucket->getopt($1) or next;
Branch: 1 branch
BranchTrueFalseTotal
@s = $bucket->getopt($1) or next 0 6 6
290 0 splice @$argv, $i, 1, ($1, $2);
291 }
292 }
293  
294 27 my @follow = splice @$argv, $i;
295  
296 ##
297 ## $<n>
298 ##
299 0 s/\$<(-?\d+)>/$follow[$1]/ge foreach @s;
300  
301 27 shift @follow;
302  
303 27 debug_argv({color=>'<red3>'}, $argv, undef, \@s, \@follow);
304  
305 ##
306 ## $<shift>, $<move>, $<remove>, $<copy>, $<ignore>
307 ##
308 27 my $modified;
309 27 ▶ @s = map sub {
Subroutine __ANON__: called CC=10 SCAR=24.0
310 27 ▶ $modified += s/\$<shift>/@follow ? shift @follow : ''/ge;
Branch: 1 branch
BranchTrueFalseTotal
@follow ? : 4 0 4
311 27 ▶ m{\A \$ < # $<
Branch: 1 branch
BranchTrueFalseTotal
/\A \$ < # $< (?<cmd> move|remove|copy|ignore ) # command (?: \( (?<off> -?\d+ ) ? # (off (?: ,(?<len> -?\d+ ))? \) )? # ,len) > \z # > /ux or return $_ 5 22 27
312 (?<cmd> move|remove|copy|ignore ) # command
313 (?: \( (?<off> -?\d+ ) ? # (off
314 (?: ,(?<len> -?\d+ ))? \) )? # ,len)
315 > \z # >
316 }x or return $_;
317 5 $modified++;
318 5 ▶ return () if $+{cmd} eq 'ignore';
Branch: 1 branch
BranchTrueFalseTotal
if $+{"cmd"} eq "ignore" 1 4 5
319 my $p = ($+{cmd} eq 'copy')
320 4 ▶ ? do { my @new = @follow; \@new }
Branch: 1 branch
BranchTrueFalseTotal
$+{'cmd'} eq 'copy' ? : 1 3 4
321 : \@follow;
322 my @arg = @$p == 0 ? ()
323 : defined $+{len} ? splice @$p, $+{off}//0, $+{len}
324 4 ▶ : splice @$p, $+{off}//0;
Branch: 2 branches
BranchTrueFalseTotal
@$p == 0 ? : 0 4 4
defined $+{'len'} ? : 4 0 4
Condition25%1/4
$+{"off"} // 0
l!l
40
$+{"off"} // 0
l!l
00
MC/DC0%0/1
$+{"off"} // 0
$+{"off"}
MC/DC0%0/1
$+{"off"} // 0
$+{"off"}
Truth table50%1/2
A
A= $+{"off"}
Aresult
11
00
Truth table0%0/2
A
A= $+{"off"}
Aresult
11
00
325 4 ▶ ($+{cmd} eq 'remove') ? () : @arg;
Branch: 1 branch
BranchTrueFalseTotal
$+{'cmd'} eq 'remove' ? : 1 3 4
326 27 }->(), @s;
327  
328 27 @s = $bucket->expand_args(@s);
329 27 ▶ debug_argv({color=>'<blue4>'}, $argv, undef, \@s, \@follow) if $modified;
Branch: 1 branch
BranchTrueFalseTotal
if $modified 9 18 27
330  
331 27 my(@module, @default);
332 27 ▶ if (@module = $obj->modopt(\@s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@module = $obj->modopt(\@s)) 0 27 27
333 0 @default = grep { @$_ } map { [ $_->default ] } @module;
334 0 debug_argv({color=>'<green4>'}, $argv, \@default, \@s, \@follow);
335 }
336 27 push @$argv, @default, @s, @follow;
337  
338 27 ▶ redo ARGV if $i < @$argv;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @$argv 27 0 27
339 }
340 }
341 }
342  
343 47 ▶sub debug_argv {
Subroutine debug_argv: called CC=8 SCAR=40.5
Pod undocumented
344 47 ▶ $debug or return;
Branch: 1 branch
BranchTrueFalseTotal
$Getopt::EX::Loader::debug or return 0 47 47
345 0 ▶ my $opt = ref $_[0] eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
346 0 my($before, $default, $working, $follow) = @_;
347 0 ▶ my $color = $opt->{color} // '<red3>';
Condition0%0/2
$opt->{"color"} // "<red3>"
l!l
00
MC/DC0%0/1
$opt->{"color"} // "<red3>"
$opt->{"color"}
Truth table0%0/2
A
A= $opt->{"color"}
Aresult
11
00
348 printf STDERR
349 "\@ARGV = %s\n",
350 array_to_str(
351 0 ▶ pairmap {
Subroutine __ANON__: not called CC=2 SCAR=17.9
352 0 ▶ if (@$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$a > 0) { } 0 0 0
353 0 colorize($b, array_to_str(@$a));
354 } else {
355 0 ();
356 }
357 }
358 0 ▶ $before // [], "L20",
Condition0%0/8
$before // []
l!l
00
$default // []
l!l
00
$working // []
l!l
00
$follow // []
l!l
00
MC/DC0%0/1
$before // []
$before
MC/DC0%0/1
$default // []
$default
MC/DC0%0/1
$working // []
$working
MC/DC0%0/1
$follow // []
$follow
Truth table0%0/2
A
A= $before
Aresult
11
00
Truth table0%0/2
A
A= $default
Aresult
11
00
Truth table0%0/2
A
A= $working
Aresult
11
00
Truth table0%0/2
A
A= $follow
Aresult
11
00
359 $default // [], "$color;U",
360 $working // [], "$color;",
361 $follow // [], "N");
362 }
363  
364 0 ▶sub array_to_str {
Subroutine array_to_str: not called CC=3 SCAR=24.8
Pod undocumented
365 join ' ', map {
366 0 ▶ if (ref eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 0 0 0
elsif (length $_ == 0) { } 0 0 0
367 0 join ' ', '[', array_to_str(@$_), ']';
368 } elsif (length == 0) {
369 0 "''";
370 } else {
371 0 $_;
372 }
373 } @_;
374 }
375  
376 0 ▶sub modules {
Subroutine modules: not called CC=5 SCAR=34.0
Pod undocumented
377 0 my $obj = shift;
378 0 ▶ my $class = $obj->baseclass // return ();
Condition0%0/2
$obj->baseclass // (return ())
l!l
00
MC/DC0%0/1
$obj->baseclass // (return ())
$obj->baseclass
Truth table0%0/2
A
A= $obj->baseclass
Aresult
11
00
379 0 ▶ my @base = ref $class eq 'ARRAY' ? @$class : ($class);
Branch: 1 branch
BranchTrueFalseTotal
ref $class eq 'ARRAY' ? : 0 0 0
380 0 for (@base) {
381 0 s/::/\//g;
382 0 ▶ $_ = "/$_" if $_ ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne "" 0 0 0
383 }
384  
385 map {
386 0 my $base = $_;
387 0 grep { /^[a-z]/ }
388 0 map { /(\w+)\.pm$/ }
389 0 map { glob $_ . $base . "/*.pm" }
390 @INC;
391 } @base;
392 }
393  
394 8 1;
395  
396 =head1 NAME
397  
398 Getopt::EX::Loader - RC/Module loader
399  
400 =head1 SYNOPSIS
401  
402 use Getopt::EX::Loader;
403  
404 my $loader = Getopt::EX::Loader->new(
405 BASECLASS => 'App::example',
406 );
407  
408 $loader->load_file("$ENV{HOME}/.examplerc");
409  
410 $loader->deal_with(\@ARGV);
411  
412 my $parser = Getopt::Long::Parser->new;
413 $parser->getoptions(... , $loader->builtins);
414 or
415 $parser->getoptions(\%hash, ... , $loader->hashed_builtins(\%hash));
416  
417 =head1 DESCRIPTION
418  
419 This is the main interface to use L<Getopt::EX> modules. You can
420 create a loader object, load user-defined rc files, load modules
421 specified by command arguments, substitute user-defined options and
422 insert default options defined in rc files or modules, and get module-defined
423 built-in option definitions for the option parser.
424  
425 Most of the work is done in the C<deal_with> method. It parses command
426 arguments and loads modules specified by the B<-M> option by default. Then
427 it scans options and substitutes them according to the definitions in the
428 rc file or modules. If the RC file and modules define default options, they
429 are inserted into the arguments.
430  
431 Modules can define built-in options which should be handled by the option
432 parser. They can be retrieved by the C<builtins> method, so you should pass
433 them to the option parser.
434  
435 If option values are stored in a hash, use C<hashed_builtins> with the
436 hash reference. Actually, C<builtins> works even for hash storage in
437 the current version of the B<Getopt::Long> module, but it is not
438 documented.
439  
440 If C<App::example> is given as a C<BASECLASS> of the loader object, it
441 is prepended to all module names. So command line
442  
443 % example -Mfoo
444  
445 will load C<App::example::foo> module.
446  
447 In this case, if the module C<App::example::default> exists, it is loaded
448 automatically without explicit indication. The default module can be used
449 just like a startup RC file.
450  
451  
452 =head1 METHODS
453  
454 =over 4
455  
456 =item B<configure> I<name> => I<value>, ...
457  
458 =over 4
459  
460 =item RCFILE
461  
462 Define the name of startup file.
463  
464 =item BASECLASS
465  
466 Define the base class for user-defined modules. Use an array reference to
467 specify multiple base classes; they are tried to be loaded in order.
468  
469 =item MODULE_OPT
470  
471 Define the module option string. String C<-M> is set by default.
472  
473 =item DEFAULT
474  
475 Define the default module name. The string C<default> is set by default. Set to
476 C<undef> if you don't want to load any default module.
477  
478 =item PARSE_MODULE_OPT
479  
480 Defaults to true, and parses module options given to the C<deal_with> method.
481 When disabled, module options in command line arguments are not
482 processed, but module options given in rc or module files are still
483 effective.
484  
485 =item IGNORE_NO_MODULE
486  
487 Defaults to false, and the process dies when a given module was not found on the
488 system. When set to true, the program ignores non-existing modules and stops
489 parsing at that point, leaving the argument untouched.
490  
491 =item IGNORE_NO_FILE
492  
493 Defaults to true for historical reasons, and silently ignores when the
494 specified RC file does not exist. When set to false, the process dies
495 if the file is not found.
496  
497 =back
498  
499 =item B<buckets>
500  
501 Returns the loaded L<Getopt::EX::Module> object list.
502  
503 =item B<load_file>
504  
505 Loads the specified file.
506  
507 =item B<load_module>
508  
509 Loads the specified module.
510  
511 =back
« EX/Module.pm ↑ Summary EX/LabeledParam.pm »