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