Commit | Line | Data |
fd56ddb6 |
1 | |
2 | use warnings FATAL => 'all'; |
3 | use strict; |
4 | |
5 | package Foo; |
6 | use Moose; |
7 | with 'MooseX::Getopt'; |
8 | use MooseX::Types::Path::Class; |
9 | |
10 | has 'dir' => ( |
11 | is => 'ro', |
12 | isa => 'Path::Class::Dir', |
13 | required => 1, |
14 | coerce => 1, |
15 | ); |
16 | |
17 | has 'file' => ( |
18 | is => 'ro', |
19 | isa => 'Path::Class::File', |
20 | required => 1, |
21 | coerce => 1, |
22 | ); |
23 | |
24 | package Bar; |
25 | use Moose; |
26 | with 'MooseX::Getopt'; |
27 | use MooseX::Types::Path::Class qw( Dir File ); |
28 | |
29 | has 'dir' => ( |
30 | is => 'ro', |
31 | isa => Dir, |
32 | required => 1, |
33 | coerce => 1, |
34 | ); |
35 | |
36 | has 'file' => ( |
37 | is => 'ro', |
38 | isa => File, |
39 | required => 1, |
40 | coerce => 1, |
41 | ); |
42 | |
43 | package main; |
44 | |
45 | use Test::More; |
46 | plan tests => 20; |
47 | |
48 | my $check = sub { |
49 | my $o = shift; |
50 | isa_ok( $o->dir, 'Path::Class::Dir' ); |
51 | cmp_ok( $o->dir, 'eq', '/tmp', 'dir is /tmp' ); |
52 | isa_ok( $o->file, 'Path::Class::File' ); |
53 | cmp_ok( $o->file, 'eq', '/tmp/foo', 'file is /tmp/foo' ); |
54 | }; |
55 | |
56 | for my $class (qw(Foo Bar)) { |
57 | my $o; |
58 | |
59 | $o = $class->new( dir => '/tmp', file => [ '', 'tmp', 'foo' ] ); |
60 | isa_ok( $o, $class ); |
61 | $check->($o); |
62 | @ARGV = qw( |
63 | --dir |
64 | /tmp |
65 | --file |
66 | /tmp/foo |
67 | ); |
68 | $o = $class->new_with_options; |
69 | isa_ok( $o, $class ); |
70 | $check->($o); |
71 | } |
72 | |