diff --git a/lib/Zonemaster/Backend/Errors.pm b/lib/Zonemaster/Backend/Errors.pm index 9d310e99d..cc25cf877 100644 --- a/lib/Zonemaster/Backend/Errors.pm +++ b/lib/Zonemaster/Backend/Errors.pm @@ -65,8 +65,7 @@ has '+code' => ( has 'reason' => ( isa => 'Str', - is => 'rw', - initializer => 'reason', + is => 'ro' ); has 'method' => ( @@ -89,24 +88,16 @@ sub _build_method { return $c[3]; } -around 'reason' => sub { - my $orig = shift; - my $self = shift; - - my ( $value, $setter, $attr ) = @_; - - # reader - return $self->$orig if not $value; +around 'BUILDARGS', sub { + my ($orig, $class, %args) = @_; - # trim new lines - $value =~ s/\n/ /g; - $value =~ s/^\s+|\s+$//g; - - # initializer - return $setter->($value) if $setter; + if(exists $args{reason}) { + # trim new lines + $args{reason} =~ s/\n/ /g; + $args{reason} =~ s/^\s+|\s+$//g; + } - # writer - $self->$orig($value); + $class->$orig(%args); }; sub as_string {