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