1use warnings; 2use strict; 3use Test::More tests => 11; 4use Getopt::Attribute; 5 6BEGIN { 7 @ARGV = qw(--noverbose --all --size=23 --more --more --more --quiet 8 --library lib/stdlib --library lib/extlib --def2=4 9 --define os=linux --define vendor=redhat --man -- --more); 10} 11our $verbose : Getopt(verbose!); 12is($verbose, 0, 'turned-off boolean option'); 13our $all : Getopt(all); 14is($all, 1, 'turned-on boolean option'); 15our $size : Getopt(size=s); 16is($size, 23, 'string option'); 17our $more : Getopt(more+); 18is($more, 3, 'flag given several times'); 19our @library : Getopt(library=s); 20our $library = join ':' => @library; 21is($library, 'lib/stdlib:lib/extlib', 'array option'); 22our %defines : Getopt(define=s); 23our $defines = join ', ' => map "$_ => $defines{$_}" => keys %defines; 24ok( keys(%defines) == 2 25 && $defines{os} eq 'linux' 26 && $defines{vendor} eq 'redhat', 27 'hash option' 28); 29 30sub quiet : Getopt(quiet) { 31 our $quiet_msg = 'seen quiet'; 32} 33is(our $quiet_msg, 'seen quiet', 'option with code handler'); 34usage() if our $man : Getopt(man); 35sub usage { our $man_msg = 'seen man' } 36is(our $man_msg, 'seen man', 'another option with code handler'); 37ok(length(@ARGV) == 1 && $ARGV[0] eq '--more', 'non-option option-look-a-like'); 38our $def : Getopt(def=i 42); 39our $def2 : Getopt(def2=i 42); 40is($def, 42, 'defaulting'); 41is($def2, 4, 'setting other than default'); 42