Subject: | Year option doesn't accept argument |
*$ software-license --year=2011 --license=BSD
Option year does not take an argument
usage: software-license [-?h] [long options...]
-h -? --usage --help Prints this usage information.
--holder
--year
--license
--configfile
--type
It says year doesn't take an argument,
but I don't know what "--year" should do without one.
I think MooseX::Getopt doesn't recognize the "Maybe" type.
Dropping that and using a predicate seems to work.
Subject: | app-software-license-year.patch |
diff --git a/lib/App/Software/License.pm b/lib/App/Software/License.pm
index de9e9fc..79a2eea 100644
--- a/lib/App/Software/License.pm
+++ b/lib/App/Software/License.pm
@@ -23,8 +23,8 @@ has holder => (
has year => (
is => 'ro',
- isa => Maybe[Num],
- default => undef,
+ isa => Num,
+ predicate => 'has_year',
);
@@ -64,7 +64,7 @@ sub _build__software_license {
Class::MOP::load_class($class);
return $class->new({
holder => $self->holder,
- year => $self->year,
+ ($self->has_year ? (year => $self->year) : ()),
});
}
diff --git a/t/options.t b/t/options.t
new file mode 100644
index 0000000..2de6b73
--- /dev/null
+++ b/t/options.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+use Test::More 0.88;
+use File::Spec::Functions qw( catfile ); # core
+
+use App::Software::License;
+
+my $holder = 'A.Holder';
+my $year = (localtime)[5] + 1900;
+
+sub test_opts {
+ my ($argv, $re, $desc) = @_;
+ local @ARGV = @$argv;
+ my $holder = 'A.Holder';
+ like(
+ App::Software::License->new_with_options->_software_license->notice,
+ $re,
+ $desc,
+ );
+}
+
+test_opts(
+ [qw( --holder=A.Holder --license=BSD )],
+ qr/^\QThis software is Copyright (c) $year by $holder.\E/,
+ 'basic args',
+);
+
+test_opts(
+ [qw( --holder=A.Holder BSD )],
+ qr/^\QThis software is Copyright (c) $year by $holder.\E/,
+ 'license as last (non-option) argument',
+);
+
+test_opts(
+ [qw( --year=2000 --holder=A.Holder BSD )],
+ qr/^\QThis software is Copyright (c) 2000 by $holder.\E/,
+ 'specify year',
+);
+
+done_testing;