8 my $FilePath = sub { die "does not pass the type constraint" if $_[0] eq '/' };
21 my ( $self, $params ) = @_;
22 die $params->{path} . " does not exist"
23 unless -e $params->{path};
26 # Defining this causes the FIRST call to Baz->new w/o param to fail,
27 # if no call to ANY Moo::Object->new was done before.
44 my ( $self, $params ) = @_;
45 die $params->{path} . " does not exist"
46 unless -e $params->{path};
49 # Defining this causes the FIRST call to Qee->new w/o param to fail...
50 # if no call to ANY Moo::Object->new was done before.
67 my ( $self, $params ) = @_;
68 die $params->{path} . " does not exist"
69 unless -e $params->{path};
72 # Having no DEMOLISH, everything works as expected...
75 check_em ( 'Baz' ); # 'Baz plain' will fail, aka NO error
76 check_em ( 'Qee' ); # ok
77 check_em ( 'Foo' ); # ok
79 check_em ( 'Qee' ); # 'Qee plain' will fail, aka NO error
80 check_em ( 'Baz' ); # ok
81 check_em ( 'Foo' ); # ok
83 check_em ( 'Foo' ); # ok
84 check_em ( 'Baz' ); # ok !
85 check_em ( 'Qee' ); # ok
92 # Uncomment to see, that it is really any first call.
93 # Subsequents calls will not fail, aka giving the correct error.
96 my $obj = eval { $pkg->new; };
97 ::like( $@, qr/Missing required argument/, "... $pkg plain" );
98 ::is( $obj, undef, "... the object is undef" );
102 my $obj = eval { $pkg->new(); };
103 ::like( $@, qr/Missing required argument/, "... $pkg empty" );
104 ::is( $obj, undef, "... the object is undef" );
108 my $obj = eval { $pkg->new ( notanattr => 1 ); };
109 ::like( $@, qr/Missing required argument/, "... $pkg undef" );
110 ::is( $obj, undef, "... the object is undef" );
115 my $obj = eval { $pkg->new ( %param ); };
116 ::like( $@, qr/Missing required argument/, "... $pkg undef param" );
117 ::is( $obj, undef, "... the object is undef" );
121 my $obj = eval { $pkg->new ( path => '/' ); };
122 ::like( $@, qr/does not pass the type constraint/, "... $pkg root path forbidden" );
123 ::is( $obj, undef, "... the object is undef" );
127 my $obj = eval { $pkg->new ( path => '/this_path/does/not_exist' ); };
128 ::like( $@, qr/does not exist/, "... $pkg non existing path" );
129 ::is( $obj, undef, "... the object is undef" );
133 my $obj = eval { $pkg->new ( path => $FindBin::Bin ); };
134 ::is( $@, '', "... $pkg no error" );
135 ::isa_ok( $obj, $pkg );
136 ::isa_ok( $obj, 'Moo::Object' );
137 ::is( $obj->path, $FindBin::Bin, "... $pkg got the right value" );