9 use Moose::Util::TypeConstraints;
13 # This used to try to _really_ check for a valid Unix or Windows
14 # path, but the regex wasn't quite right, and all we care about
15 # for the tests is that it rejects '/'
16 => where { $_ ne '/' };
20 use Moose::Util::TypeConstraints;
29 my ( $self, $params ) = @_;
30 confess $params->{path} . " does not exist"
31 unless -e $params->{path};
34 # Defining this causes the FIRST call to Baz->new w/o param to fail,
35 # if no call to ANY Moose::Object->new was done before.
44 use Moose::Util::TypeConstraints;
53 my ( $self, $params ) = @_;
54 confess $params->{path} . " does not exist"
55 unless -e $params->{path};
58 # Defining this causes the FIRST call to Qee->new w/o param to fail...
59 # if no call to ANY Moose::Object->new was done before.
68 use Moose::Util::TypeConstraints;
77 my ( $self, $params ) = @_;
78 confess $params->{path} . " does not exist"
79 unless -e $params->{path};
82 # Having no DEMOLISH, everything works as expected...
85 check_em ( 'Baz' ); # 'Baz plain' will fail, aka NO error
86 check_em ( 'Qee' ); # ok
87 check_em ( 'Foo' ); # ok
89 check_em ( 'Qee' ); # 'Qee plain' will fail, aka NO error
90 check_em ( 'Baz' ); # ok
91 check_em ( 'Foo' ); # ok
93 check_em ( 'Foo' ); # ok
94 check_em ( 'Baz' ); # ok !
95 check_em ( 'Qee' ); # ok
102 # Uncomment to see, that it is really any first call.
103 # Subsequents calls will not fail, aka giving the correct error.
106 my $obj = eval { $pkg->new; };
107 ::like( $@, qr/is required/, "... $pkg plain" );
108 ::is( $obj, undef, "... the object is undef" );
112 my $obj = eval { $pkg->new(); };
113 ::like( $@, qr/is required/, "... $pkg empty" );
114 ::is( $obj, undef, "... the object is undef" );
118 my $obj = eval { $pkg->new ( notanattr => 1 ); };
119 ::like( $@, qr/is required/, "... $pkg undef" );
120 ::is( $obj, undef, "... the object is undef" );
125 my $obj = eval { $pkg->new ( %param ); };
126 ::like( $@, qr/is required/, "... $pkg undef param" );
127 ::is( $obj, undef, "... the object is undef" );
131 my $obj = eval { $pkg->new ( path => '/' ); };
132 ::like( $@, qr/does not pass the type constraint/, "... $pkg root path forbidden" );
133 ::is( $obj, undef, "... the object is undef" );
137 my $obj = eval { $pkg->new ( path => '/this_path/does/not_exist' ); };
138 ::like( $@, qr/does not exist/, "... $pkg non existing path" );
139 ::is( $obj, undef, "... the object is undef" );
143 my $obj = eval { $pkg->new ( path => $FindBin::Bin ); };
144 ::is( $@, '', "... $pkg no error" );
145 ::isa_ok( $obj, $pkg );
146 ::isa_ok( $obj, 'Moose::Object' );
147 ::is( $obj->path, $FindBin::Bin, "... $pkg got the right value" );