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