scope the classes
[gitmo/MooseX-Types-Path-Class.git] / t / 01.basic.t
1
2 use warnings FATAL => 'all';
3 use strict;
4
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 }
46
47 package main;
48
49 use Test::More;
50 use Path::Class;
51 plan tests => 10;
52
53 my $dir = dir('', 'tmp');
54 my $file = file('', 'tmp', 'foo');
55
56 my $check = sub {
57     my $o = shift;
58     isa_ok( $o->dir, 'Path::Class::Dir' );
59     cmp_ok( $o->dir, 'eq', "$dir", "dir is $dir" );
60     isa_ok( $o->file, 'Path::Class::File' );
61     cmp_ok( $o->file, 'eq', "$file", "file is $file" );
62 };
63
64 for my $class (qw(Foo Bar)) {
65     my $o = $class->new( dir => "$dir", file => [ '', 'tmp', 'foo' ] );
66     isa_ok( $o, $class );
67     $check->($o);
68 }
69