So I'm just trying to do a very simple thing: define a custom reader accessor for a moose attribute. So I try this:
has 'compiled_regex' => (
isa => 'RegexpRef',
is => 'rw',
reader => 'get_compiled',
);
but get_compiled
never gets called, presumably because compiled_regex
is read/write. Ok, no problem. I next try this:
has 'compiled_regex' => (
isa => 'RegexpRef',
writer => '_compile',
reader => 'get_compiled',
);
and that produces the following error:
Can't locate object method "compiled_regex" via package "PrettyRegex" at ../lib/Pretty/Regexs.pm line 39.
which refers to this line which is in the _compile
method:
$self->compiled_regex(qr/$self->regex/);
Now I haven't gotten much sleep in the past 3 days so maybe I'm confused, but it seems that even if this did work, it would create an infinite regress since I've defined the writer as _compile
... so what am I missing here?
tried Sinan answer but still getting:
Can't locate object method "compiled_regex" via package "PrettyRegex" at ../lib/Pretty/Regexs.pm line 41.