I concur with haukex that you should make a SSCCE to demonstrate/research your issue. Something very simple like:
This will show you the error clearly. Output:# 1210614.pl package MyClass { use Moose; has FileName => (is => 'rw', isa => 'Str', writer => 'SetFileName' +); sub SetFileName { my $self = shift; my $arg = shift; warn "I am here with $arg"; } }; package main { my $obj = MyClass->new; $obj->SetFileName('/foo/bar'); };
$ perl 1210614.pl You are overwriting a locally defined method (SetFileName) with an acc +essor ...
As you can see this is not what specifying a custom writer does. As far as I understand it, specifying a custom writer property for an attribute simply changes the name of the writer from the default.
Output:# 1210614-1.pl package MyClass { use Moose; has FileName => (is => 'rw', isa => 'Str', writer => 'SetFileName' +); }; package main { my $obj = MyClass->new; $obj->SetFileName('/foo/bar'); warn $obj->FileName; };
$ perl 1210614-1.pl /foo/bar at 1210614-1.pl line 9.
For what you are doing your code should use a custom type check, or a coercion, or a trigger instead.
Output:# 1210614-2.pl package MyClass { use Moose; has FileName => (is => 'rw', isa => 'Str', trigger => \&SetFileNam +e); sub SetFileName { my $self = shift; my $arg = shift; warn "I am here with $arg"; } }; package main { my $obj = MyClass->new; $obj->SetFileName('/foo/bar'); };
$ perl 1210614-2.pl I am here with /foo/bar at 1210614-2.pl line 7.
Hope this helps!
In reply to Re: Perl/Moose calling writer doesnt work
by 1nickt
in thread Perl/Moose calling writer doesnt work
by jorba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |