File Coverage

blib/lib/Getopt/App.pm
Criterion Covered Total %
statement 203 210 96.6
branch 91 114 79.8
condition 31 41 75.6
subroutine 28 28 100.0
pod 5 5 100.0
total 358 398 89.9


line stmt bran cond sub pod time code
1             package Getopt::App;
2 7     7   1592159 use feature qw(:5.16);
  7         51  
  7         1161  
3 7     7   46 use strict;
  7         15  
  7         148  
4 7     7   33 use warnings;
  7         23  
  7         214  
5 7     7   49 use utf8;
  7         13  
  7         35  
6              
7 7     7   241 use Carp qw(croak);
  7         15  
  7         332  
8 7     7   5103 use Getopt::Long ();
  7         75279  
  7         271  
9 7     7   64 use List::Util qw(first);
  7         15  
  7         20978  
10              
11             our $VERSION = '0.12';
12              
13             our ($OPT_COMMENT_RE, $OPTIONS, $SUBCOMMAND, $SUBCOMMANDS, %APPS) = (qr{\s+\#\s+});
14              
15             our $call_maybe = sub {
16             my ($app, $m) = (shift, shift);
17             local $Getopt::App::APP_CLASS;
18             $m = $app->can($m) || __PACKAGE__->can("_$m");
19             return $m ? $app->$m(@_) : undef;
20             };
21              
22             sub bundle {
23 1     1 1 6959 my ($class, $script, $OUT) = (@_, \*STDOUT);
24 1         3 my ($package, @script);
25              
26 1 50       43 open my $SCRIPT, '<', $script or croak "Can't read $script: $!";
27 1         31 while (my $line = readline $SCRIPT) {
28 2 100       16 if ($line =~ m!^\s*package\s+\S+\s*;!) { # look for app class name
    50          
29 1         14 $package .= $line;
30 1         3 last;
31             }
32             elsif ($. == 1) { # look for hashbang
33 1 50       6 $line =~ m/^#!/ ? print {$OUT} $line : do { print {$OUT} "#!$^X\n"; push @script, $line };
  1         8  
  0         0  
  0         0  
  0         0  
34             }
35             else {
36 0         0 push @script, $line;
37 0 0       0 last if $line =~ m!^[^#]+;!;
38             }
39             }
40              
41 1         7 my $out_line = '';
42 1 50       43 open my $SELF, '<', __FILE__ or croak "Can't read Getopt::App: $!";
43 1         35 while (my $line = readline $SELF) {
44 279 100       1663 next if $line =~ m!(?:\bVERSION\s|^\s*$)!; # TODO: Should version get skipped?
45 228 100       433 next if $line =~ m!^sub bundle\s\{! .. $line =~ m!^}$!; # skip bundle()
46 185 100       297 last if $line =~ m!^1;\s*$!; # do not include POD
47              
48 184         220 chomp $line;
49 184 100       323 if ($line =~ m!^sub\s!) {
    100          
50 15 100       26 print {$OUT} $out_line, "\n" if $out_line;
  1         4  
51 15 100       44 $line =~ m!\}$! ? print {$OUT} $line, "\n" : ($out_line = $line);
  2         7  
52             }
53             elsif ($line =~ m!^}$!) {
54 13         15 print {$OUT} $out_line, $line, "\n";
  13         33  
55 13         38 $out_line = '';
56             }
57             else {
58 156         397 $line =~ s!^[ ]{2,}!!; # remove leading white space
59 156         240 $line =~ s!\#\s.*!!; # remove comments
60 156         425 $out_line .= $line;
61             }
62             }
63              
64 1         2 print {$OUT} qq(BEGIN{\$INC{'Getopt/App.pm'}='BUNDLED'}\n);
  1         3  
65 1   50     2 print {$OUT} +($package || "package main\n");
  1         4  
66 1         2 print {$OUT} @script;
  1         2  
67 1         6 print {$OUT} $_ while readline $SCRIPT;
  2         37  
68             }
69              
70             sub capture {
71 23     23 1 60639 my ($app, $argv) = @_;
72              
73 23         4217 require File::Temp;
74 23         88251 my ($STDOUT_CAPTURE, $STDERR_CAPTURE) = (File::Temp->new, File::Temp->new);
75 23 50       17300 open my $STDOUT_ORIG, '>&STDOUT' or die "Can't remember original STDOUT: $!";
76 23 50       484 open my $STDERR_ORIG, '>&STDERR' or die "Can't remember original STDERR: $!";
77              
78             my $restore = sub {
79 23 50   23   560 open STDERR, '>&', fileno($STDERR_ORIG) or die "Can't restore STDERR: $!";
80 23 50       442 open STDOUT, '>&', fileno($STDOUT_ORIG) or die "Can't restore STDOUT: $!";
81 23 50       92 die $_[0] if $_[0];
82 23         176 };
83              
84 23 50       588 open STDOUT, '>&', fileno($STDOUT_CAPTURE) or $restore->("Can't capture STDOUT: $!");
85 23 50       485 open STDERR, '>&', fileno($STDERR_CAPTURE) or $restore->("Can't capture STDERR: $!");
86              
87 23         55 my $exit_value;
88 23 100 100     44 unless (eval { $exit_value = $app->($argv || [@ARGV]); 1; }) {
  23         117  
  19         127  
89 4         210 print STDERR $@;
90 4         43 $exit_value = int $!;
91             }
92              
93 23         175 STDERR->flush;
94 23         76 STDOUT->flush;
95 23         74 $restore->();
96 23         174 seek $STDERR_CAPTURE, 0, 0;
97 23         181 seek $STDOUT_CAPTURE, 0, 0;
98              
99 23         1722 return [join('', <$STDOUT_CAPTURE>), join('', <$STDERR_CAPTURE>), $exit_value];
100             }
101              
102             sub extract_usage {
103 4     4 1 25 my %pod2usage;
104 4         12 $pod2usage{'-sections'} = shift;
105 4   33     29 $pod2usage{'-input'} = shift || (caller)[1];
106 4 100       29 $pod2usage{'-verbose'} = 99 if $pod2usage{'-sections'};
107              
108 4         1131 require Pod::Usage;
109 4     2   80203 open my $USAGE, '>', \my $usage;
  2         17  
  2         4  
  2         17  
110 4         1859 Pod::Usage::pod2usage(-exitval => 'noexit', -output => $USAGE, %pod2usage);
111 4         13906 close $USAGE;
112              
113 4   100     26 $usage //= '';
114 4 100       23 $usage =~ s!^(.*?)\n!!s if $pod2usage{'-sections'};
115 4         18 $usage =~ s!^Usage:\n\s+([A-Z])!$1!s; # Remove "Usage" header if SYNOPSIS has a description
116 4         19 $usage =~ s!^ !!gm;
117              
118 4   100     35 return join '', $usage, _usage_for_subcommands($SUBCOMMANDS || []), _usage_for_options($OPTIONS || []);
      50        
119             }
120              
121             sub import {
122 20     20   18471 my ($class, @flags) = @_;
123 20         52 my $caller = caller;
124              
125 20         475 $_->import for qw(strict warnings utf8);
126 20         1916 feature->import(':5.16');
127              
128 20         47 my $skip_default;
129 7     7   66 no strict qw(refs);
  7         31  
  7         17007  
130 20         80 while (my $flag = shift @flags) {
131 10 100       62 if ($flag eq '-capture') {
    100          
    50          
    50          
132 6         14 *{"$caller\::capture"} = \&capture;
  6         35  
133 6         25 $skip_default = 1;
134             }
135             elsif ($flag eq '-complete') {
136 2         466 require Getopt::App::Complete;
137 2         8 *{"$caller\::generate_completion_script"} = \&Getopt::App::Complete::generate_completion_script;
  2         21  
138             }
139             elsif ($flag eq '-signatures') {
140 0         0 require experimental;
141 0         0 experimental->import(qw(signatures));
142             }
143             elsif ($flag !~ /^-/) {
144 2 100       211 croak "package definition required - cannot extend main with $flag!" if $caller eq 'main';
145 1 50       105 croak "require $flag FAIL $@" unless eval "require $flag;1";
146 1         7 push @{"${caller}::ISA"}, $flag;
  1         17  
147             }
148             }
149              
150 19 100       12046 unless ($skip_default) {
151 13 50       171 *{"$caller\::extract_usage"} = \&extract_usage unless $caller->can('extract_usage');
  13         61  
152 13 50       92 *{"$caller\::new"} = \&new unless $caller->can('new');
  13         45  
153 13         32 *{"$caller\::run"} = \&run;
  13         1400  
154             }
155             }
156              
157             sub new {
158 49     49 1 2367 my $class = shift;
159 49 100 33     284 bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
  1 100       9  
160             }
161              
162             sub run {
163 57     57 1 273 my @rules = @_;
164 57   66     187 my $class = $Getopt::App::APP_CLASS || caller;
165 45     45   8641 return sub { local $Getopt::App::APP_CLASS = $class; run(@_, @rules) }
  45         133  
166 57 100 66     324 if !$Getopt::App::APP_CLASS and defined wantarray;
167              
168 45         82 my $cb = pop @rules;
169 45 50       166 my $argv = ref $rules[0] eq 'ARRAY' ? shift @rules : [@ARGV];
170 45         105 local $OPTIONS = [@rules];
171 45         88 @rules = map {s!$OPT_COMMENT_RE.*$!!r} @rules;
  76         533  
172              
173 45         211 my $app = $class->new;
174 45 100 66     177 return $app->$call_maybe('getopt_complete_reply') if defined $ENV{COMP_POINT} and defined $ENV{COMP_LINE};
175              
176 35         122 $app->$call_maybe(getopt_pre_process_argv => $argv);
177              
178 35         155 local $SUBCOMMANDS = $app->$call_maybe('getopt_subcommands');
179 35 100       358 my $exit_value = $SUBCOMMANDS ? _subcommand_run_maybe($app, $SUBCOMMANDS, $argv) : undef;
180 31 100       74 return _exit($app, $exit_value) if defined $exit_value;
181              
182 24         48 my @configure = $app->$call_maybe('getopt_configure');
183 24         105 my $prev = Getopt::Long::Configure(@configure);
184 24 100       1813 my $valid = Getopt::Long::GetOptionsFromArray($argv, $app, @rules) ? 1 : 0;
185 24         5203 Getopt::Long::Configure($prev);
186 24         494 $app->$call_maybe(getopt_post_process_argv => $argv, {valid => $valid});
187              
188 22 100       247 return _exit($app, $valid ? $app->$cb(@$argv) : 1);
189             }
190              
191 10     10   36 sub _getopt_complete_reply { Getopt::App::Complete::complete_reply(@_) }
192              
193 22     22   87 sub _getopt_configure {qw(bundling no_auto_abbrev no_ignore_case pass_through require_order)}
194              
195             sub _getopt_load_subcommand {
196 6     6   15 my ($app, $subcommand, $argv) = @_;
197 6 50       20 return $subcommand->[1] if ref $subcommand->[1] eq 'CODE';
198              
199 6         19 ($@, $!) = ('', 0);
200 6 100       2739 croak "Unable to load subcommand $subcommand->[0]: $@ ($!)" unless my $code = do $subcommand->[1];
201 5         25 return $code;
202             }
203              
204             sub _getopt_post_process_argv {
205 21     21   47 my ($app, $argv, $state) = @_;
206 21 50       93 return unless $state->{valid};
207 21 100 100     107 return unless $argv->[0] and $argv->[0] =~ m!^-!;
208 1         4 $! = 1;
209 1         15 die "Invalid argument or argument order: @$argv\n";
210             }
211              
212             sub _getopt_unknown_subcommand {
213 1     1   25 my ($app, $argv) = @_;
214 1         5 $! = 2;
215 1         14 die "Unknown subcommand: $argv->[0]\n";
216             }
217              
218             sub _exit {
219 29     29   173 my ($app, $exit_value) = @_;
220 29   100     62 $exit_value = $app->$call_maybe(getopt_post_process_exit_value => $exit_value) // $exit_value;
221 29 100 100     195 $exit_value = 0 unless $exit_value and $exit_value =~ m!^\d{1,3}$!;
222 29 100       78 $exit_value = 255 unless $exit_value < 255;
223 29 50       60 exit $exit_value unless $Getopt::App::APP_CLASS;
224 29         251 return $exit_value;
225             }
226              
227             sub _subcommand_run {
228 11     11   25 my ($app, $subcommand, $argv) = @_;
229 11         20 local $Getopt::App::SUBCOMMAND = $subcommand;
230 11 100       37 unless ($APPS{$subcommand->[1]}) {
231 6         17 $APPS{$subcommand->[1]} = $app->$call_maybe(getopt_load_subcommand => $subcommand, $argv);
232 5 50       25 croak "$subcommand->[0] did not return a code ref" unless ref $APPS{$subcommand->[1]} eq 'CODE';
233             }
234              
235 10         75 return $APPS{$subcommand->[1]}->([@$argv[1 .. $#$argv]]);
236             }
237              
238             sub _subcommand_run_maybe {
239 15     15   38 my ($app, $subcommands, $argv) = @_;
240 15 100 100     93 return undef unless $argv->[0] and $argv->[0] =~ m!^\w!;
241             return $app->$call_maybe(getopt_unknown_subcommand => $argv)
242 12 100   35   78 unless my $subcommand = first { $_->[0] eq $argv->[0] } @$subcommands;
  35         66  
243 8         37 return _subcommand_run($app, $subcommand, $argv);
244             }
245              
246             sub _usage_for_options {
247 4     4   10 my ($rules) = @_;
248 4 100       71 return '' unless @$rules;
249              
250 3         10 my ($len, @options) = (0);
251 3         8 for (@$rules) {
252 8         53 my @o = split $OPT_COMMENT_RE, $_, 2;
253 8         36 $o[0] =~ s/(=[si][@%]?|\!|\+)$//;
254 8 100       34 $o[0] = join ', ', map { length($_) == 1 ? "-$_" : "--$_" } sort { length($b) <=> length($a) } split /\|/, $o[0];
  10         43  
  2         11  
255 8   100     29 $o[1] //= '';
256              
257 8         14 my $l = length $o[0];
258 8 100       19 $len = $l if $l > $len;
259 8         19 push @options, \@o;
260             }
261              
262 3         7 return "Options:\n" . join('', map { sprintf " %-${len}s %s\n", @$_ } @options) . "\n";
  8         251  
263             }
264              
265             sub _usage_for_subcommands {
266 4     4   13 my ($subcommands) = @_;
267 4 100       28 return '' unless @$subcommands;
268              
269 1         3 my ($len, @cmds) = (0);
270 1         3 for my $s (@$subcommands) {
271 5         8 my $l = length $s->[0];
272 5 100       12 $len = $l if $l > $len;
273 5   50     17 push @cmds, [$s->[0], $s->[2] // ''];
274             }
275              
276 1         3 return "Subcommands:\n" . join('', map { sprintf " %-${len}s %s\n", @$_ } @cmds) . "\n";
  5         28  
277             }
278              
279             1;
280              
281             =encoding utf8
282              
283             =head1 NAME
284              
285             Getopt::App - Write and test your script with ease
286              
287             =head1 SYNOPSIS
288              
289             =head2 The script file
290              
291             #!/usr/bin/env perl
292             package My::Script;
293             use Getopt::App -complete, -signatures;
294              
295             # See "APPLICATION METHODS"
296             sub getopt_post_process_argv ($app, $argv, $state) { ... }
297             sub getopt_configure ($app) { ... }
298              
299             # run() must be the last statement in the script
300             run(
301              
302             # Specify your Getopt::Long options and optionally a help text
303             'h|help # Output help',
304             'v+ # Verbose output',
305             'name=s # Specify a name',
306             'completion-script # Print autocomplete script',
307              
308             # Here is the main sub that will run the script
309             sub ($app, @extra) {
310             return print generate_completion_script() if $app->{'completion-script'};
311             return print extract_usage() if $app->{h};
312             say $app->{name} // 'no name'; # Access command line options
313             return 42; # Reture value is used as exit code
314             }
315             );
316              
317             =head2 Running the script
318              
319             The example script above can be run like any other script:
320              
321             $ my-script --name superwoman; # prints "superwoman"
322             $ echo $? # 42
323              
324             =head2 Testing
325              
326             use Test::More;
327             use Cwd qw(abs_path);
328             use Getopt::App -capture;
329              
330             # Sourcing the script returns a callback
331             my $app = do(abs_path('./bin/myapp'));
332              
333             # The callback can be called with any @ARGV
334             subtest name => sub {
335             my $got = capture($app, [qw(--name superwoman)]);
336             is $got->[0], "superwoman\n", 'stdout';
337             is $got->[1], '', 'stderr';
338             is $got->[2], 42, 'exit value';
339             };
340              
341             done_testing;
342              
343             =head2 Subcommands
344              
345             #!/usr/bin/env perl
346             # Define a package to avoid mixing methods after loading the subcommand script
347             package My::App::main;
348             use Getopt::App -complete;
349              
350             # getopt_subcommands() is called by Getopt::App
351             sub getopt_subcommands {
352             my $app = shift;
353              
354             return [
355             ['find', '/path/to/subcommand/find.pl', 'Find things'],
356             ['update', '/path/to/subcommand/update.pl', 'Update things'],
357             ];
358             }
359              
360             # run() is only called if there are no matching sub commands
361             run(
362             'h # Print help',
363             'completion-script # Print autocomplete script',
364             sub {
365             my ($app, @args) = @_;
366             return print generate_completion_script() if $app->{'completion-script'};
367             return print extract_usage();
368             }
369             );
370              
371             See L and L
372             for more details.
373              
374             =head1 DESCRIPTION
375              
376             L is a module that helps you structure your scripts and integrates
377             L with a very simple API. In addition it makes it very easy to
378             test your script, since the script file can be sourced without actually being
379             run.
380              
381             L also supports infinite nested L
382             and a method for L this module with your script to prevent
383             depending on a module from CPAN.
384              
385             =head1 APPLICATION METHODS
386              
387             These methods are optional, but can be defined in your script to override the
388             default behavior.
389              
390             =head2 getopt_complete_reply
391              
392             $app->getopt_complete_reply;
393              
394             This method will be called instead of the L callback when the
395             C and C environment variables are set. The default
396             implementation will call L.
397              
398             See also "Completion" under L.
399              
400             =head2 getopt_configure
401              
402             @configure = $app->getopt_configure;
403              
404             This method can be defined if you want L to be set up
405             differently. The default return value is:
406              
407             qw(bundling no_auto_abbrev no_ignore_case pass_through require_order)
408              
409             The default return value is currently EXPERIMENTAL.
410              
411             =head2 getopt_load_subcommand
412              
413             $code = $app->getopt_load_subcommand($subcommand, [@ARGV]);
414              
415             Takes the subcommand found in the L list and the command
416             line arguments and must return a CODE block. The default implementation is
417             simply:
418              
419             $code = do($subcommand->[1]);
420              
421             =head2 getopt_post_process_argv
422              
423             $bool = $app->getopt_post_process_argv([@ARGV], {%state});
424              
425             This method can be used to post process the options. C<%state> contains a key
426             "valid" which is true or false, depending on the return value from
427             L.
428              
429             This method can C and optionally set C<$!> to avoid calling the function
430             passed to L.
431              
432             The default behavior is to check if the first item in C<$argv> starts with a
433             hyphen, and C with an error message if so:
434              
435             Invalid argument or argument order: @$argv\n
436              
437             =head2 getopt_post_process_exit_value
438              
439             $exit_value = $app->getopt_post_process_exit_value($exit_value);
440              
441             A method to be called after the L function has been called.
442             C<$exit_value> holds the return value from L which could be any value,
443             not just 0-255. This value can then be changed to change the exit value from
444             the program.
445              
446             sub getopt_post_process_exit_value ($app, $exit_value) {
447             return int(1 + rand 10);
448             }
449              
450             =head2 getopt_pre_process_argv
451              
452             $app->getopt_pre_process_argv($argv);
453              
454             This method can be defined to pre-process C<$argv> before it is passed on to
455             L. Example:
456              
457             sub getopt_pre_process_argv ($app, $argv) {
458             $app->{first_non_option} = shift @$argv if @$argv and $argv->[0] =~ m!^[a-z]!;
459             }
460              
461             This method can C and optionally set C<$!> to avoid calling the actual
462             L function.
463              
464             =head2 getopt_subcommands
465              
466             $subcommands = $app->getopt_subcommands;
467              
468             This method must be defined in the script to enable sub commands. The return
469             value must be either C to disable subcommands or an array-ref of
470             array-refs like this:
471              
472             [["subname", "/abs/path/to/sub-command-script", "help text"], ...]
473              
474             The first element in each array-ref "subname" will be matched against the first
475             argument passed to the script, and when matched the "sub-command-script" will
476             be sourced and run inside the same perl process. The sub command script must
477             also use L for this to work properly.
478              
479             The sub-command will have C<$Getopt::App::SUBCOMMAND> set to the item found in
480             the list.
481              
482             See L for a working
483             example.
484              
485             =head2 getopt_unknown_subcommand
486              
487             $exit_value = $app->getopt_unknown_subcommand($argv);
488              
489             Will be called when L is defined but C<$argv> does not
490             match an item in the list. Default behavior is to C with an error message:
491              
492             Unknown subcommand: $argv->[0]\n
493              
494             Returning C instead of dying or a number (0-255) will cause the L
495             callback to be called.
496              
497             =head1 EXPORTED FUNCTIONS
498              
499             =head2 capture
500              
501             use Getopt::App -capture;
502             my $app = do '/path/to/bin/myapp';
503             my $array_ref = capture($app, [@ARGV]); # [$stdout, $stderr, $exit_value]
504              
505             Used to run an C<$app> and capture STDOUT, STDERR and the exit value in that
506             order in C<$array_ref>. This function will also capture C. C<$@> will be
507             set and captured in the second C<$array_ref> element, and C<$exit_value> will
508             be set to C<$!>.
509              
510             This function is a very slimmed down alternative to L.
511             The main reason why L exists in this package is that if something
512             inside the C<$app> throws an exception, then it will be part of the captured
513             C<$stderr> instead of making C throw an exception.
514              
515             L is however more robust than this function, so please
516             try L out in case you find an edge case.
517              
518             =head2 extract_usage
519              
520             # Default to "SYNOPSIS" from current file
521             my $str = extract_usage($section, $file);
522             my $str = extract_usage($section);
523             my $str = extract_usage();
524              
525             Will extract a C<$section> from POD C<$file> and append command line option
526             descriptions when called from inside of L. Command line options can
527             optionally have a description with "spaces-hash-spaces-description", like this:
528              
529             run(
530             'o|option # Some description',
531             'v|verbose # Enable verbose output',
532             sub {
533             ...
534             },
535             );
536              
537             This function will I be exported if a function with the same name already
538             exists in the script.
539              
540             =head2 new
541              
542             my $obj = new($class, %args);
543             my $obj = new($class, \%args);
544              
545             This function is exported into the caller package so we can construct a new
546             object:
547              
548             my $app = Application::Class->new(\%args);
549              
550             This function will I be exported if a function with the same name already
551             exists in the script.
552              
553             =head2 run
554              
555             # Run a code block on valid @ARGV
556             run(@rules, sub ($app, @extra) { ... });
557              
558             # For testing
559             my $cb = run(@rules, sub ($app, @extra) { ... });
560             my $exit_value = $cb->([@ARGV]);
561              
562             L can be used to call a callback when valid command line options is
563             provided. On invalid arguments, warnings will be issued and the program exit
564             with C<$?> set to 1.
565              
566             C<$app> inside the callback is a hash blessed to the caller package. The keys
567             in the hash are the parsed command line options, while C<@extra> is the extra
568             unparsed command line options.
569              
570             C<@rules> are the same options as L can take. Example:
571              
572             # app.pl -vv --name superwoman -o OptX cool beans
573             run(qw(h|help v+ name=s o=s@), sub ($app, @extra) {
574             die "No help here" if $app->{h};
575             warn $app->{v}; # 2
576             warn $app->{name}; # "superwoman"
577             warn @{$app->{o}}; # "OptX"
578             warn @extra; # "cool beans"
579             return 0; # Used as exit code
580             });
581              
582             In the example above, C<@extra> gets populated, since there is a non-flag value
583             "cool" after a list of valid command line options.
584              
585             =head1 METHODS
586              
587             =head2 bundle
588              
589             Getopt::App->bundle($path_to_script);
590             Getopt::App->bundle($path_to_script, $fh);
591              
592             This method can be used to combine L and C<$path_to_script> into a
593             a single script that does not need to have L installed from CPAN.
594             This is for example useful for sysadmin scripts that otherwise only depends on
595             core Perl modules.
596              
597             The script will be printed to C<$fh>, which defaults to C.
598              
599             Example usage:
600              
601             perl -MGetopt::App -e'Getopt::App->bundle(shift)' ./src/my-script.pl > ./bin/my-script;
602              
603             =head2 import
604              
605             use Getopt::App;
606             use Getopt::App 'My::Script::Base', -signatures;
607             use Getopt::App -capture;
608              
609             =over 2
610              
611             =item * Default
612              
613             use Getopt::App;
614              
615             Passing in no flags will export the default functions L,
616             L and L. In addition it will save you from a lot of typing, since
617             it will also import the following:
618              
619             use strict;
620             use warnings;
621             use utf8;
622             use feature ':5.16';
623              
624             =item * Completion
625              
626             use Getopt::App -complete;
627              
628             Same as L, but will also load L and import
629             L.
630              
631             =item * Signatures
632              
633             use Getopt::App -signatures;
634              
635             Same as L, but will also import L. This
636             requires Perl 5.20+.
637              
638             =item * Class name
639              
640             package My::Script::Foo;
641             use Getopt::App 'My::Script';
642              
643             Same as L but will also make C inherit from
644             L. Note that a package definition is required.
645              
646             =item * Capture
647              
648             use Getopt::App -capture;
649              
650             This will only export L.
651              
652             =back
653              
654             =head1 COPYRIGHT AND LICENSE
655              
656             This library is free software. You can redistribute it and/or modify it under
657             the same terms as Perl itself.
658              
659             =head1 AUTHOR
660              
661             Jan Henning Thorsen - C
662              
663             =cut