Dave Cross: Still Munging Data With Perl: Online event - Mar 17 Learn more

#!/usr/bin/env perl
use 5.006002;
use strict;
use Getopt::Long 2.25;
our $VERSION = '0.000_015';
my %opt;
GetOptions( \%opt,
version => sub {
print <<"EOD";
$0 version $VERSION
Perl version $]
EOD
exit;
},
help => sub { pod2usage( { -verbose => 2 } ) },
) and @ARGV or pod2usage( { -verbose => 0 } );
my $item = shift @ARGV;
my $code;
if ( $code = __PACKAGE__->can( "call_$item" ) ) {
$code->( @ARGV );
} elsif ( $code = Date::Tolkien::Shire::Data->can( "__$item" ) ) {
my @rslt = grep { defined } $code->( @ARGV );
local $" = ', ';
print "__$item( @ARGV ) = @rslt\n";
} else {
die "Do not know how to call __$item()\n";
}
sub call_format {
my $tplt = shift @ARGV;
my %hash = @ARGV;
my $rslt = Date::Tolkien::Shire::Data::__format( \%hash, $tplt );
print "__format( \%hash, '$tplt' ) = '$rslt'\n";
return;
}
__END__
=head1 TITLE
display - Display results of Shire calendar routines
=head1 SYNOPSIS
display date_to_day_of_year 1419 3 25
display weekday_name 0 2
display -help
display -version
=head1 OPTIONS
=head2 -help
This option displays the documentation for this script. The script then
exits.
=head2 -version
This option displays the version of this script. The script then exits.
=head1 DETAILS
This Perl script lets you play around with the subroutines in
C<Date::Tolkien::Shire::Data>. The command line arguments are the name
of the subroutine to call (without the leading double underscore), and
subsequent command line arguments are the subroutine arguments.
Generally, the subroutine is called in list context, and the results
displayed. An exception is raised if the first argument does not
specify an existing subroutine.
In the case of C<on_date_accented>, standard output may contain
non-ASCII characters, encoded in UTF-8. The only way I know of to get
this to work under Perl 5.6.2 is to run this script as
C<perl -C eg/display>. Unfortunately putting the C<-C> in the shebang
line does B<not> work. I would have done
C<binmode STDOUT, ':encoding(utf-8)>, but that requires Perl 5.8. Caveat
user.
The following subroutines have special-case code to handle them:
=head2 __format
For C<__format()>, the first command argument after C<'format'> is the
template to use. Subsequent arguments specify the date to format, as
nane/value pairs. These are made into a hash, and passed as the date
argument of C<__format()>. The result of formatting the given date using
the given template are displayed.
=head1 AUTHOR
Thomas R. Wyant, III F<wyant at cpan dot org>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2017 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl 5.10.0. For more details, see the full text
of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.
=cut
# ex: set textwidth=72 :