X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F002_custom_option_type.t;fp=t%2F002_custom_option_type.t;h=881b0f6ee5676f3665c15dcffcca436615cc4ade;hb=8034a2324bcef31b91a45a83baec1508acee2763;hp=0000000000000000000000000000000000000000;hpb=5dac17c3fb3f25ba558e70565462826017f0c91c;p=gitmo%2FMooseX-Getopt.git diff --git a/t/002_custom_option_type.t b/t/002_custom_option_type.t new file mode 100644 index 0000000..881b0f6 --- /dev/null +++ b/t/002_custom_option_type.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 5; + +BEGIN { + use_ok('MooseX::Getopt'); +} + +{ + package App; + use Moose; + use Moose::Util::TypeConstraints; + + use Scalar::Util 'looks_like_number'; + + with 'MooseX::Getopt'; + + subtype 'ArrayOfInts' + => as 'ArrayRef' + => where { scalar (grep { looks_like_number($_) } @$_) }; + + MooseX::Getopt::OptionTypeMap->add_option_type_to_map( + 'ArrayOfInts' => '=i@' + ); + + has 'nums' => ( + is => 'ro', + isa => 'ArrayOfInts', + default => sub { [0] } + ); + +} + +{ + local @ARGV = (); + + my $app = App->new_with_options; + isa_ok($app, 'App'); + + is_deeply($app->nums, [0], '... nums is [0] as expected'); +} + +{ + local @ARGV = ('--nums', 3, '--nums', 5); + + my $app = App->new_with_options; + isa_ok($app, 'App'); + + is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); +} +