package Class::Trait::TSetter; use strict; use warnings; use Carp; our $VERSION = '0.03'; use Class::Trait 'base'; #this doesnt work as expected #our %OVERLOADS = ( '=' => "set" ); sub set { my $self = shift; my $value = shift; if ( my $sub = $self->{validate} ) { if ( &$sub ($value) ) { #print "assign $value to $self->{property}\n"; $self->{object}->{$self->{property}} = $value; } else { croak "Illegal value assigned for property $self->{property}"; } } else { #print "assign $value to $self->{property}\n"; $self->{object}->{$self->{property}} = $value; } } 1;