is $c->three, "three", "attr default set from role";
{
- package Deux; use Moo; with 'One::P1';
- ::like(
- ::exception { has two => (is => 'ro', default => sub { 'II' }); },
- qr{^You cannot overwrite a locally defined method \(two\) with a reader},
- 'overwriting accesssors with roles fails'
- );
+ package Deux; use Moo; with 'One::P1';
+ ::like(
+ ::exception { has two => (is => 'ro', default => sub { 'II' }); },
+ qr{^You cannot overwrite a locally defined method \(two\) with a reader},
+ 'overwriting accesssors with roles fails'
+ );
}
{
- package Two; use Moo; with 'One::P1';
- has '+two' => (is => 'ro', default => sub { 'II' });
+ package Two; use Moo; with 'One::P1';
+ has '+two' => (is => 'ro', default => sub { 'II' });
}
is(Two->new->two, 'II', "overwriting accessors using +attr works");
use_ok('UnderscoreClass');
is(
- UnderscoreClass->c1,
- 'c1',
+ UnderscoreClass->c1,
+ 'c1',
);
is(
- UnderscoreClass->r1,
- 'r1',
+ UnderscoreClass->r1,
+ 'r1',
);
is(
- ClobberUnderscore::h1(),
- 'h1',
+ ClobberUnderscore::h1(),
+ 'h1',
);
done_testing;
# Compile-time exceptions, so need stringy eval; hence not Test::Fatal.
{
- local $@;
- ok not eval q { package XXX; use Moo; use Moo::Role; 1; };
- like $@, qr{Cannot import Moo::Role into a Moo class};
+ local $@;
+ ok not eval q { package XXX; use Moo; use Moo::Role; 1; };
+ like $@, qr{Cannot import Moo::Role into a Moo class};
}
{
- local $@;
- ok not eval q { package YYY; use Moo::Role; use Moo; 1; };
- like $@, qr{Cannot import Moo into a role};
+ local $@;
+ ok not eval q { package YYY; use Moo::Role; use Moo; 1; };
+ like $@, qr{Cannot import Moo into a role};
}
done_testing;
my $codified = 0;
{
- package Dark::Side;
- use overload
- q[&{}] => sub { $codified++; shift->to_code },
- fallback => 1;
- sub new {
- my $class = shift;
- my $code = shift;
- bless \$code, $class;
- }
- sub to_code {
- my $self = shift;
- eval "sub { $$self }";
- }
+ package Dark::Side;
+ use overload
+ q[&{}] => sub { $codified++; shift->to_code },
+ fallback => 1;
+ sub new {
+ my $class = shift;
+ my $code = shift;
+ bless \$code, $class;
+ }
+ sub to_code {
+ my $self = shift;
+ eval "sub { $$self }";
+ }
}
{
- package The::Force;
- use Sub::Quote;
- use base 'Dark::Side';
- sub to_code {
- my $self = shift;
- return quote_sub $$self;
- }
+ package The::Force;
+ use Sub::Quote;
+ use base 'Dark::Side';
+ sub to_code {
+ my $self = shift;
+ return quote_sub $$self;
+ }
}
my $darkside = Dark::Side->new('my $dummy = "join the dark side"; $_[0] * 2');
my $luke = The::Force->new('my $z = "I am your father"');
{
- package Doubleena;
- use Moo;
- has a => (is => "rw", coerce => $darkside, isa => sub { 1 });
- has b => (is => "rw", coerce => $theforce, isa => $luke);
+ package Doubleena;
+ use Moo;
+ has a => (is => "rw", coerce => $darkside, isa => sub { 1 });
+ has b => (is => "rw", coerce => $theforce, isa => $luke);
}
my $o = Doubleena->new(a => 11, b => 12);
require Scalar::Util;
is(
- Scalar::Util::refaddr($luke),
- Scalar::Util::refaddr(
- Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"isa"}
- ),
- '$spec->{isa} reference is not mutated',
+ Scalar::Util::refaddr($luke),
+ Scalar::Util::refaddr(
+ Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"isa"}
+ ),
+ '$spec->{isa} reference is not mutated',
);
is(
- Scalar::Util::refaddr($theforce),
- Scalar::Util::refaddr(
- Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"coerce"}
- ),
- '$spec->{coerce} reference is not mutated',
+ Scalar::Util::refaddr($theforce),
+ Scalar::Util::refaddr(
+ Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"coerce"}
+ ),
+ '$spec->{coerce} reference is not mutated',
);
done_testing;