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