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
|
# 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 MooseX::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 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
$ENV{COLUMNS} = 80;
{
package MyClass;
use strict; use warnings;
use Moose;
with 'MooseX::Getopt';
has $_ => (
is => 'ro', isa => 'Str',
traits => ['Getopt'],
documentation => 'Documentation for "' . $_ . '"',
) foreach qw(foo bar baz);
}
my $obj = MyClass->new_with_options();
like(
$obj->usage->text,
qr/\A\Qusage: 110_sort_usage_by_attr_order.t [-?h] [long options...]\E
\s+.*--help.+Prints this usage information\..*
\s+--foo (STR)?\s+Documentation for "foo"
\s+--bar (STR)?\s+Documentation for "bar"
\s+--baz (STR)?\s+Documentation for "baz"\Z/ms,
'Usage text has nicely sorted options',
);
done_testing;
|