Make the accessors private, and then provide a wrapper for the accessor. Something like this:
subtype 'TkRef', as 'ScalarRef';
coerce 'TkRef', from 'Str', via { my $r = $_; return \$r };
has _some_val => (
is => 'rw',
isa => 'TkRef',
coerce => 1,
init_arg => 'some_val',
default => 'default value',
);
sub some_val {
my $self = shift;
if (@_ and not ref $_[0]) {
${$self->_some_val} = shift;
}
elsif (@_ and ref $_[0]) {
${$self->_some_val} = ${+shift};
}
$self->_some_val(@_);
}