Created
May 7, 2021 13:38
-
-
Save blabos-zz/da3ad7ee4e9334c268cf224428fe1818 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
package Parent; | |
use Moo; | |
has 'parent' => ( 'is' => 'ro' ); | |
sub core_attrs { | |
my ($self) = @_; | |
my $specs = 'Moo'->_constructor_maker_for('Parent')->all_attribute_specs; | |
my @attr_names = keys %{$specs}; | |
return ( map { $_ => $self->$_ } @attr_names ); | |
} | |
############################################################################## | |
package Foo; | |
use Moo; | |
extends 'Parent'; | |
has 'foo' => ( 'is' => 'ro' ); | |
############################################################################## | |
package Bar; | |
use Moo; | |
extends 'Parent'; | |
has 'bar' => ( 'is' => 'ro' ); | |
############################################################################## | |
package main; | |
use v5.32; | |
my $f = Foo->new( parent => 42, foo => 123 ); | |
my $b = Bar->new( $f->core_attrs, bar => '456' ); | |
use Data::Dumper; | |
say Dumper( $f, $b, { $f->core_attrs } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment