Acme-Has-Tiny

 view release on metacpan or  search on metacpan

t/01basic.t  view on Meta::CPAN

my $alice = "Person"->new(name => "Alice", age => 32);
isa_ok($alice, "Person", '$alice');
can_ok($alice, $_) for qw(name age has_name has_age _set_age);

my $bob = "Employee"->new(name => "Bob", id => 123456);
isa_ok($bob, "Person", '$bob');
isa_ok($bob, "Employee", '$bob');
can_ok($bob, $_) for qw(name age has_name has_age _set_age id);
like(exception { $bob->_set_age("x") }, qr{^Value "x" did not pass type constraint "Num"}, 'type constraint');
ok(!$bob->has_age, 'not $bob->has_age');
is($bob->age, undef, '$bob->age undef');
is($bob->_set_age(42), 42, 'setter returns value');
ok($bob->has_age, '$bob->has_age');
is($bob->age, 42, 'getter returns value');

my $e = exception { "Employee"->new(name => undef) };
like($e, qr{^Attribute id is required by Employee}, 'required attribute exception');

done_testing;

t/02more.t  view on Meta::CPAN

my $alice = "Person"->new(name => "Alice", age => 32);
isa_ok($alice, "Person", '$alice');
can_ok($alice, $_) for qw(name age has_name has_age _set_age);

my $bob = "Employee"->new(name => "Bob", id => 123456);
isa_ok($bob, "Person", '$bob');
isa_ok($bob, "Employee", '$bob');
can_ok($bob, $_) for qw(name age has_name has_age _set_age id);
like(exception { $bob->_set_age("x") }, qr{^Value "x" did not pass type constraint "Num"}, 'type constraint');
ok(!$bob->has_age, 'not $bob->has_age');
is($bob->age, undef, '$bob->age undef');
is($bob->_set_age(42), 42, 'setter returns value');
ok($bob->has_age, '$bob->has_age');
is($bob->age, 42, 'getter returns value');

my $e = exception { "Employee"->new(name => undef) };
like($e, qr{^Attribute id is required by Employee}, 'required attribute exception');

done_testing;



( run in 1.971 second using v1.01-cache-2.11-cpan-d80b1682f3f )