2 use warnings FATAL => 'all';
4 use Test::More tests => 7;
12 with 'MooseX::Getopt';
14 has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' );
17 # FIXME - it looks like we have a spacing issue in Getopt::Long?
19 usage: 104_override_usage.t [-?h] [long options...]
20 \t-h -? --usage --help Prints this usage information.
25 local @ARGV = ('--foo', '1');
26 my $i = trap { MyScript->new_with_options };
27 is($i->foo, 1, 'attr is set');
28 is($trap->stdout, '', 'nothing printed when option is accepted');
32 local @ARGV = ('--help');
33 trap { MyScript->new_with_options };
34 is($trap->stdout, $usage, 'usage is printed on --help');
38 local @ARGV = ('-q'); # Does not exist
39 trap { MyScript->new_with_options };
40 is($trap->die, join("\n", 'Unknown option: q', $usage), 'usage is printed on unknown option');
44 Class::MOP::class_of('MyScript')->add_before_method_modifier(
45 print_usage_text => sub {
46 print "--- DOCUMENTATION ---\n";
50 local @ARGV = ('--help');
51 trap { MyScript->new_with_options };
54 join("\n", '--- DOCUMENTATION ---', $usage),
55 'additional text included before normal usage string',
63 with 'MooseX::Getopt';
64 has foo => ( isa => 'Int', is => 'ro', documentation => 'A foo' );
68 # some classes (e.g. ether's darkpan and Catalyst::Runtime) overrode
69 # _getopt_full_usage, so we need to keep it in the call stack so we don't
71 Class::MOP::class_of('MyScript2')->add_before_method_modifier(
72 _getopt_full_usage => sub {
73 print "--- DOCUMENTATION ---\n";
77 local @ARGV = ('--help');
78 trap { MyScript2->new_with_options };
81 join("\n", '--- DOCUMENTATION ---', $usage),
82 'additional text included before normal usage string',