Hello,
I'm trying to apply some processing on an attribute value when it is
set. I thought creating custom subtype and a coercion is the way to do
it, but cannot figure it out.
The coersion is not run.
See my code below.
What am I doing wrong?
I need this filtering to appear seamlessly on the subject attribute due
to backwards compatibility.
subtype 'Subject'
=> as 'Str';
coerce 'Subject'
=> from 'Str'
=> via {
my $sanitized = sanitize_input($_);
$sanitized;
};
subtype MaybeSubject => as 'Maybe[Subject]';
coerce 'MaybeSubject'
=> from 'Subject'
=> via {
my $sanitized =sanitize_input($_);
$sanitized;
};
has 'subject' => (
is => 'rw',
isa => 'MaybeSubject',
predicate => 'has_subject',
coerce => 1,
);