in reply to Moose attribute modification

G'day learning.moose,

Is this the type of thing you had in mind?

#!/usr/bin/env perl -l use strict; use warnings; # Role: TextHolder { package TextHolder; use Moose::Role; has text => ( is => 'rw', isa => 'Str', ); } # Class: TextReference { package TextReference; use Moose; with 'TextHolder'; sub read_text { my $self = shift; return $self->text; } } my $tref_early = TextReference::->new({text => 'early'}); my $tref_late = TextReference::->new; $tref_late->text('late'); print 'Early: ', $tref_early->read_text; print 'Late: ', $tref_late->read_text;

Output:

$ pm_1124686_moose_role_attrs.pl Early: early Late: late

-- Ken

Replies are listed 'Best First'.
Re^2: Moose attribute modification
by learning.moose (Novice) on Apr 27, 2015 at 12:21 UTC
    Wow this is so awesome! Didn't know that attributes from roles can be accessed in class so directly. Thank you