Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Course;
- use Moose;
- has 'students' => (
- is => 'ro',
- isa => 'ArrayRef[Student]',
- default => sub { [] },
- );
- sub add_student {
- my $self = shift;
- my @new_students = @_;
- $self->meta->get_attribute('students')
- ->type_constraint->assert_valid(\@new_students);
- $_->learns_at( $self ) for @new_students;
- push $self->students, @new_students;
- }
- package Student;
- use Moose;
- has 'name', is => 'ro', required => 1;
- has 'learns_at', is => 'rw', weak_ref => 1;
- package main;
- my $c = Course->new;
- $c->add_student( Student->new( name => 'Mike') );
- warn $c->dump;
Add Comment
Please, Sign In to add comment