Created
July 7, 2022 15:08
-
-
Save dakkar/aa813843e1b6dd3c21b187a4909a78c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.26; | |
use strict; | |
use warnings; | |
package My::Thing { | |
use Moo; | |
has value => ( is => 'ro', required => 1 ); | |
}; | |
package My::Class { | |
use Moo; | |
use Types::Standard qw(InstanceOf); | |
has thing => ( | |
is => 'ro', | |
isa => (InstanceOf['My::Thing'])->plus_constructors, | |
coerce => 1, | |
required => 1, | |
); | |
sub talk { | |
say 'my thing has value '.$_[0]->thing->value; | |
} | |
}; | |
my $o = My::Class->new({thing=>{value=>42}}); | |
$o->talk; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment