Class-Tiny-Antlers
view release on metacpan or search on metacpan
t/03defaults.t view on Meta::CPAN
=pod
=encoding utf-8
=head1 PURPOSE
Test lazy defaults.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{
package WWW;
use Class::Tiny::Antlers;
use constant STYLE => 'non-coderef default with explicit lazy => 1';
has aaa => (is => 'ro', lazy => 1, default => 11);
has bbb => (is => 'rw', lazy => 1, default => 12);
has ccc => (is => 'rwp', lazy => 1, default => 13);
}
{
package XXX;
use Class::Tiny::Antlers;
use constant STYLE => 'coderef default with explicit lazy => 1';
has aaa => (is => 'ro', lazy => 1, default => sub { 11 });
has bbb => (is => 'rw', lazy => 1, default => sub { 12 });
has ccc => (is => 'rwp', lazy => 1, default => sub { 13 });
}
{
package YYY;
use Class::Tiny::Antlers;
use constant STYLE => 'non-coderef default with implicit lazy => 1';
has aaa => (is => 'ro', default => 11);
has bbb => (is => 'rw', default => 12);
has ccc => (is => 'rwp', default => 13);
}
{
package ZZZ;
use Class::Tiny::Antlers;
use constant STYLE => 'coderef default with implicit lazy => 1';
has aaa => (is => 'ro', default => sub { 11 });
has bbb => (is => 'rw', default => sub { 12 });
has ccc => (is => 'rwp', default => sub { 13 });
}
for my $class (qw/ WWW XXX YYY ZZZ /)
{
subtest sprintf('Class %s, %s', $class, $class->STYLE), sub {
subtest "A new $class object setting nothing in the constructor" => sub {
my $obj = new_ok $class;
subtest "ro attribute" => sub {
is($obj->{aaa}, undef, 'default is lazy');
is($obj->aaa, 11, 'returns correct value');
is($obj->{aaa}, 11, 'stores into the hashref');
done_testing;
};
subtest "rw attribute" => sub {
( run in 0.734 second using v1.01-cache-2.11-cpan-54e63673c56 )