{
package example;
-
+
use Moose;
use Moose::Util::TypeConstraints;
with qw(
MooseX::Getopt
);
-
- subtype 'ResultSet'
+
+ subtype 'ResultSet'
=> as 'DBIx::Class::ResultSet';
-
- subtype 'ResultList'
+
+ subtype 'ResultList'
=> as 'ArrayRef[Int]';
MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
'ResultList' => '=s',
);
-
- coerce 'ResultList'
- => from 'Str'
+
+ coerce 'ResultList'
+ => from 'Str'
=> via {
return [ grep { m/^\d+$/ } split /\D/,$_ ]; # <- split string into arrayref
};
-
+
has 'results' => (
is => 'rw',
isa => 'ResultList | ResultSet', # <- union constraint
coerce => 1,
);
-
+
has 'other' => (
is => 'rw',
isa => 'Str',
local @ARGV = ('--results','1234,5678,9012','--other','test');
my $example = example->new_with_options;
isa_ok($example, 'example');
-
+
explain($example->results);
is($example->other,'test');
cmp_deeply($example->results, [qw(1234 5678 9012)], 'result as expected');
-}
\ No newline at end of file
+}