#!perl

use strict;
use warnings;

use vars '$name', '$gender';
use ScriptX (
    'Getopt::Long' => {
        spec => ['name=s' => \$name, 'gender=s' => \$gender],
    },
    'Run',
);

sub run {
    my ($self, $stash) = @_;

    unless ($name) {
        print "Please specify --name!\n";
        exit 1;
    }
    unless ($gender) {
        print "Please specify --gender!\n";
        exit 1;
    }
    unless ($gender =~ /\A[mf]\z/i) {
        print "Invalid value in --gender, please specify m|f!\n";
        exit 1;
    }

    print "Hello, ", ($gender =~ /m/i ? "Mr." : "Mrs."), " $name!\n";
}

ScriptX->run;

# ABSTRACT: Parse command-line options using simple heuristics (demos debugging by dumping stash)
# PODNAME: scriptx-eg-getopt-long

__END__

=pod

=encoding UTF-8

=head1 NAME

scriptx-eg-getopt-long - Parse command-line options using simple heuristics (demos debugging by dumping stash)

=head1 VERSION

This document describes version 0.000 of scriptx-eg-getopt-long (from Perl distribution ScriptX), released on 2020-09-03.

=head1 SYNOPSIS

 % script-eg-getopt-specless
 Please specify --name!

 % script-eg-getopt-specless --name=Budi
 Please specify --gender!

 % script-eg-getopt-specless --name=Budi --gender=x
 Invalid value in --gender, please specify m|f!

 % script-eg-getopt-specless --name=Budi --gender=m
 Hello, Mr. Budi!

=head1 DESCRIPTION

This script demonstrates the use of L<ScriptX::Getopt::Long> which, admittedly,
does not do much. It's okay if you want to load and use L<Getopt::Long>
directly.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/ScriptX>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-ScriptX>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=ScriptX>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 SEE ALSO

L<scriptx-eg-getopt-specless>

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
