Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/usr/share/doc/perl-Moose/t/attributes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/usr/share/doc/perl-Moose/t/attributes/chained_coercion.t
use strict;
use warnings;

use Test::More;

{
    package Baz;
    use Moose;
    use Moose::Util::TypeConstraints;

    coerce 'Baz' => from 'HashRef' => via { Baz->new($_) };

    has 'hello' => (
        is      => 'ro',
        isa     => 'Str',
    );

    package Bar;
    use Moose;
    use Moose::Util::TypeConstraints;

    coerce 'Bar' => from 'HashRef' => via { Bar->new($_) };

    has 'baz' => (
        is      => 'ro',
        isa     => 'Baz',
        coerce  => 1
    );

    package Foo;
    use Moose;

    has 'bar' => (
        is      => 'ro',
        isa     => 'Bar',
        coerce  => 1,
    );
}

my $foo = Foo->new(bar => { baz => { hello => 'World' } });
isa_ok($foo, 'Foo');
isa_ok($foo->bar, 'Bar');
isa_ok($foo->bar->baz, 'Baz');
is($foo->bar->baz->hello, 'World', '... this all worked fine');

done_testing;

Hry