Skip to content

Instantly share code, notes, and snippets.

@dakkar
Created July 7, 2022 15:08
Show Gist options
  • Save dakkar/aa813843e1b6dd3c21b187a4909a78c2 to your computer and use it in GitHub Desktop.
Save dakkar/aa813843e1b6dd3c21b187a4909a78c2 to your computer and use it in GitHub Desktop.
#!/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