I concur with haukex that you should make a SSCCE to demonstrate/research your issue. Something very simple like:

# 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'); };
This will show you the error clearly. Output:
$ 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.

# 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; };
Output:
$ 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.

# 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'); };
Output:
$ perl 1210614-2.pl I am here with /foo/bar at 1210614-2.pl line 7.

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Perl/Moose calling writer doesnt work by 1nickt
in thread Perl/Moose calling writer doesnt work by jorba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.