{{$NEXT}}
- documentation and tests amended to prefer usage of 'trait' over 'metaclass'
as much as possible
+ - print_usage_text() exposed as a public method, to make it easier for
+ consuming classes to modify the behaviour when usage text is printed
0.47 2012-08-30 16:37:59 PDT-0700
- re-release to remove double $VERSION declarations
This accessor contains the boolean state of the --help, --usage and --?
options (true if any of these options were passed on the command line).
+=method B<print_usage_text>
+
+This method is called internally when the C<help_flag> state is true.
+It prints the text from the C<usage> object (see above) to stdout and then the
+program terminates normally. You can apply a method modification (see
+L<Moose::Manual::MethodModifiers>) if different behaviour is desired, for
+example to include additional text.
+
=method B<meta>
This returns the role meta object.
# did the user request usage information?
if ( $processed{usage} and $params->{help_flag} ) {
- $class->_getopt_full_usage($processed{usage});
+ $class->print_usage_text($processed{usage});
}
return MooseX::Getopt::ProcessedArgv->new(
die @$warnings, $exception;
}
-sub _getopt_full_usage {
+#(this is already documented in MooseX::Getopt. But FIXME later, via RT#82195)
+=for Pod::Coverage
+ print_usage_text
+=cut
+sub print_usage_text {
my ($self, $usage) = @_;
print $usage->text;
exit 0;
}
+# maintained for backwards compatibility only
+sub _getopt_full_usage { shift->print_usage_text(@_) }
sub _usage_format {
return "usage: %c %o";
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Test::Trap;
use Test::NoWarnings 1.04 ':early';
is($trap->die, join("\n", 'Unknown option: q', $usage), 'usage is printed on unknown option');
}
+{
+ Class::MOP::class_of('MyScript')->add_before_method_modifier(
+ print_usage_text => sub {
+ print "--- DOCUMENTATION ---\n";
+ },
+ );
+
+ local @ARGV = ('--help');
+ trap { MyScript->new_with_options };
+ is(
+ $trap->stdout,
+ join("\n", '--- DOCUMENTATION ---', $usage),
+ 'additional text included before normal usage string',
+ );
+}
+
END {
ok(!$fail_on_exit, 'getoptions() lives');
- # cancel the non-zero exit status from _getopt_full_usage()
+ # cancel the non-zero exit status from print_usage_text()
exit 0;
}