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 6 our $VERSION = "3.03";
4  
5 6 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 our @EXPORT = qw();
12 6 our %EXPORT_TAGS = ( );
13 6 our @EXPORT_OK = qw();
14  
15 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use List::Util qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use Getopt::EX::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use Getopt::EX::Func qw(parse_func);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use Getopt::EX::Colormap qw(colorize);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 our $debug = 0;
23  
24 10 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
25 10 my $class = shift;
26  
27 10 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 10 ▶ $obj->configure(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 10 0 10
38  
39 10 $obj;
40 }
41  
42 6 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 10 ▶sub configure {
Subroutine configure: called CC=8 SCAR=20.9
Pod documented
53 10 my $obj = shift;
54 10 my %opt = @_;
55  
56 10 for my $opt (@OPTIONS) {
57 70 ▶ next if $opt eq 'RCFILE';
Branch: 1 branch
BranchTrueFalseTotal
if $opt eq "RCFILE" 10 60 70
58 60 ▶ if (exists $opt{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt{$opt}) 10 50 60
59 10 $obj->{$opt} = delete $opt{$opt};
60 }
61 }
62  
63 10 ▶ if (my $rc = delete $opt{RCFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = delete $opt{"RCFILE"}) 1 9 10
64 1 ▶ my @rc = ref $rc eq 'ARRAY' ? @$rc : $rc;
Branch: 1 branch
BranchTrueFalseTotal
ref $rc eq 'ARRAY' ? : 0 1 1
65 1 for (@rc) {
66 1 $obj->load(FILE => $_);
67 }
68 }
69  
70 10 ▶ warn "Unknown option: ", Dumper \%opt if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 10 10
71  
72 10 $obj;
73 }
74  
75 46 ▶sub baseclass {
Subroutine baseclass: called CC=2 SCAR=7.2
Pod undocumented
76 46 my $obj = shift;
77 @_ ? $obj->{BASECLASS} = shift
78 46 ▶ : $obj->{BASECLASS};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 46 46
79 }
80  
81 127 ▶sub buckets {
Subroutine buckets: called CC=1 SCAR=0.0
Pod documented
82 127 my $obj = shift;
83 127 @{ $obj->{BUCKETS} };
84 }
85  
86 12 ▶sub append {
Subroutine append: called CC=1 SCAR=0.0
Pod undocumented
87 12 my $obj = shift;
88 12 push @{ $obj->{BUCKETS} }, @_;
89 }
90  
91 22 ▶sub load {
Subroutine load: called CC=4 SCAR=14.0
Pod undocumented
92 22 my $obj = shift;
93 22 my %arg = @_;
94 22 ▶ if ($obj->{IGNORE_NO_FILE} and my $file = $arg{FILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"IGNORE_NO_FILE"} and my $file = $arg{"FILE"}) 2 20 22
Condition66%2/3
$obj->{"IGNORE_NO_FILE"} and my $file = $arg{"FILE"}
!ll&&!rl&&r
0202
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 2 ▶ return undef unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 2 2
96 }
97 22 my $bucket =
98 Getopt::EX::Module->new(@_, BASECLASS => $obj->baseclass);
99 12 $obj->append($bucket);
100 12 $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 24 ▶sub load_module {
Subroutine load_module: called CC=2 SCAR=6.9
Pod documented
109 24 my $obj = shift;
110 24 my $name = shift;
111 24 ▶ if (my $mod = $obj->find_module($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod = $obj->find_module($name)) 4 20 24
112 4 return $mod;
113 }
114 20 $obj->load(MODULE => $name);
115 }
116  
117 24 ▶sub find_module {
Subroutine find_module: called CC=5 SCAR=16.1
Pod undocumented
118 24 my $obj = shift;
119 24 my $name = shift;
120 24 my $base = $obj->baseclass;
121 24 ▶ my @class = ref $base ? @$base : $base;
Branch: 1 branch
BranchTrueFalseTotal
ref $base ? : 2 22 24
122 24 for my $class (@class) {
123 27 my $module = "$class\::$name";
124 27 for ($obj->buckets) {
125 11 ▶ if ($_->module eq $module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->module eq $module) 4 7 11
126 4 return $_;
127 }
128 }
129 }
130 20 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 3 ▶sub builtins {
Subroutine builtins: called CC=1 SCAR=0.0
Pod undocumented
144 3 my $obj = shift;
145 3 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 10 ▶sub deal_with {
Subroutine deal_with: called CC=5 SCAR=17.8
Pod undocumented
159 10 my $obj = shift;
160 10 my $argv = shift;
161  
162 10 ▶ if (my $default = $obj->{DEFAULT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $default = $obj->{"DEFAULT"}) 10 0 10
163 10 ▶ if (my $bucket = eval { $obj->load_module($default) }) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $bucket = eval { do { $obj->load_module($default) } }) { } 0 10 10
elsif (not $@ =~ /Can't locate|need to install/u) { } 0 10 10
164 0 $bucket->run_inits($argv);
165 } elsif ($@ !~ /Can't locate|need to install/) {
166 0 die $@;
167 }
168 }
169 10 ▶ $obj->modopt($argv) if $obj->{PARSE_MODULE_OPT};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"PARSE_MODULE_OPT"} 10 0 10
170 10 $obj->expand($argv);
171 10 $obj;
172 }
173  
174 35 ▶sub modopt {
Subroutine modopt: called CC=6 SCAR=18.2
Pod undocumented
175 35 my $obj = shift;
176 35 my $argv = shift;
177  
178 35 ▶ my $start = $obj->{MODULE_OPT} // return ();
Condition50%1/2
$obj->{"MODULE_OPT"} // (return ())
l!l
350
MC/DC0%0/1
$obj->{"MODULE_OPT"} // (return ())
$obj->{"MODULE_OPT"}
Truth table50%1/2
A
A= $obj->{"MODULE_OPT"}
Aresult
11
00
179 35 ▶ $start eq '' and return ();
Branch: 1 branch
BranchTrueFalseTotal
$start eq "" and return () 0 35 35
180 35 my $start_re = qr/\Q$start\E/;
181 35 my @modules;
182 35 ▶ while (@$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$argv) 43 3 46
183 43 ▶ if (my($modpart) = ($argv->[0] =~ /^$start_re(.+)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($modpart) = $argv->[0] =~ /^$start_re(.+)/u) 11 32 43
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 32 last;
193 }
194 35 @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 10 ▶sub expand {
Subroutine expand: called CC=13 SCAR=26.6
Pod undocumented
248 10 my $obj = shift;
249 10 my $argv = shift;
250  
251 ##
252 ## Insert module defaults.
253 ##
254 unshift @$argv, map {
255 10 ▶ if (my @s = $_->default()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@s) = $_->default) { } 6 6 12
256 6 my @modules = $obj->modopt(\@s);
257 6 [ @s, map { $_->default } @modules ];
258 } else {
259 6 ();
260 }
261 } $obj->buckets;
262  
263 ##
264 ## Expand user defined option.
265 ##
266 ARGV:
267 10 ▶ for (my $i = 0; $i < @$argv; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$argv) 68 10 78
268  
269 87 ▶ last if $argv->[$i] eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $argv->[$i] eq "--" 0 87 87
270 87 my $current = $argv->[$i];
271  
272 87 for my $bucket ($obj->buckets) {
273  
274 106 my @s;
275 106 ▶ if (ref $current eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $current eq 'ARRAY') { } 6 100 106
276 ##
277 ## Expand defaults.
278 ##
279 6 @s = @$current;
280 6 $current = 'DEFAULT';
281 }
282 else {
283 ##
284 ## Try entire string match, and check --option=value.
285 ##
286 100 @s = $bucket->getopt($current);
287 100 ▶ if (not @s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@s) 87 13 100
288 87 ▶ $current =~ /^(.+?)=(.*)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
$current =~ /^(.+?)=(.*)/u or next 6 81 87
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 19 my @follow = splice @$argv, $i;
295  
296 ##
297 ## $<n>
298 ##
299 19 s/\$<(-?\d+)>/$follow[$1]/ge foreach @s;
300  
301 19 shift @follow;
302  
303 19 debug_argv({color=>'<red3>'}, $argv, undef, \@s, \@follow);
304  
305 ##
306 ## $<shift>, $<move>, $<remove>, $<copy>, $<ignore>
307 ##
308 19 my $modified;
309 19 ▶ @s = map sub {
Subroutine __ANON__: called CC=10 SCAR=24.0
310 19 ▶ $modified += s/\$<shift>/@follow ? shift @follow : ''/ge;
Branch: 1 branch
BranchTrueFalseTotal
@follow ? : 4 0 4
311 19 ▶ m{\A \$ < # $<
Branch: 1 branch
BranchTrueFalseTotal
/\A \$ < # $< (?<cmd> move|remove|copy|ignore ) # command (?: \( (?<off> -?\d+ ) ? # (off (?: ,(?<len> -?\d+ ))? \) )? # ,len) > \z # > /ux or return $_ 5 14 19
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 19 }->(), @s;
327  
328 19 @s = $bucket->expand_args(@s);
329 19 ▶ debug_argv({color=>'<blue4>'}, $argv, undef, \@s, \@follow) if $modified;
Branch: 1 branch
BranchTrueFalseTotal
if $modified 9 10 19
330  
331 19 my(@module, @default);
332 19 ▶ if (@module = $obj->modopt(\@s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@module = $obj->modopt(\@s)) 0 19 19
333 0 @default = grep { @$_ } map { [ $_->default ] } @module;
334 0 debug_argv({color=>'<green4>'}, $argv, \@default, \@s, \@follow);
335 }
336 19 push @$argv, @default, @s, @follow;
337  
338 19 ▶ redo ARGV if $i < @$argv;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @$argv 19 0 19
339 }
340 }
341 }
342  
343 39 ▶sub debug_argv {
Subroutine debug_argv: called CC=8 SCAR=40.5
Pod undocumented
344 39 ▶ $debug or return;
Branch: 1 branch
BranchTrueFalseTotal
$Getopt::EX::Loader::debug or return 0 39 39
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 6 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 »