1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
# The usage information prints the 'documentation' value for all Getopt
# attributes, except the order is not deterministic (rather, it uses the order
# in which the attributes are stored in the metaclass 'attributes' hash).
# Let's sort them by insertion order, which should lead to nicer output:
# If MouseX::Getopt is applied early, the help options will be on top
# the help options will always be on top (assuming this role is applied
# early), followed by options added by parent classes and roles, and then
# options added by this class.
use strict; use warnings;
use Test::More tests => 1;
use Test::Exception;
{
package MyClass;
use strict; use warnings;
use Mouse;
with 'MouseX::Getopt';
has $_ => (
is => 'ro', isa => 'Str',
traits => ['Getopt'],
documentation => 'Documentation for "' . $_ . '"',
) foreach qw(foo bar baz);
}
my $obj = MyClass->new_with_options();
my $expected = <<'USAGE';
usage: 110_sort_usage_by_attr_order.t [-?] [long options...]
-? --usage --help Prints this usage information.
--foo Documentation for "foo"
--bar Documentation for "bar"
--baz Documentation for "baz"
USAGE
if ( $Getopt::Long::Descriptive::VERSION == 0.099 )
{
$expected = <<'USAGE';
usage: 110_sort_usage_by_attr_order.t [-?] [long options...]
-? --usage --help Prints this usage information.
--foo STR Documentation for "foo"
--bar STR Documentation for "bar"
--baz STR Documentation for "baz"
USAGE
}
if ( $Getopt::Long::Descriptive::VERSION >= 0.100 )
{
$expected = <<'USAGE';
usage: 110_sort_usage_by_attr_order.t [-?] [long options...]
-? --usage --help Prints this usage information.
--foo STR Documentation for "foo"
--bar STR Documentation for "bar"
--baz STR Documentation for "baz"
USAGE
}
if ( $Getopt::Long::Descriptive::VERSION >= 0.103 )
{
$expected = <<'USAGE';
usage: 110_sort_usage_by_attr_order.t [-?] [long options...]
-? --[no-]usage --[no-]help Prints this usage information.
--foo STR Documentation for "foo"
--bar STR Documentation for "bar"
--baz STR Documentation for "baz"
USAGE
}
# Note: Getopt::Long::Descriptive 0.106 not supported
if ( $Getopt::Long::Descriptive::VERSION >= 0.107 )
{
$expected = <<'USAGE';
usage: 110_sort_usage_by_attr_order.t [-?] [long options...]
--[no-]help (or -?) Prints this usage information.
aka --usage
--foo STR Documentation for "foo"
--bar STR Documentation for "bar"
--baz STR Documentation for "baz"
USAGE
}
$expected =~ s/^[ ]{4}/\t/xmsg unless $Getopt::Long::Descriptive::VERSION >= 0.113;
is($obj->usage->text, $expected, 'Usage text has nicely sorted options');
|