Ok, so what is the recommended way of generating accessor/mutator methods? ^This seems to be the prevailing idiom , and I *really* don't want to code them by hand (or write a program that codes them by hand) since very time I add/remove a parameter I'll have to add/remove the accessor.

My first thought, was to set it so it does not ignor the calling class/object like so:

*$datum = sub { my self = shift; $self->{$datum} = shift if @_; return $self->{$datum}; };

This didn't work.

Then, I tried doing this without the self:

*$datum = sub { $self->{$datum} = shift if @_; return $self->{$datum}; };

Again, no change in result.

Then I tried without the reference to self:

*$datum = sub { $datum = shift if @_; return $datum; };

Surprise, this had no affect either.

Then, I tried doing this without the typeglob. (I'm basically pissing into the wind at this point so what do I have to loose)

$datum = sub { my self = shift; $self->{$datum} = shift if @_; return $self->{$datum}; };

Not surprisingly, no change again...
Here's what really stumps me, through all of these changes I would expect to see an error at least, but the program behaves *identically* through all of the changes.

The immediate fix is to look at the XXX comment and make that generated method not close over $self.

I guess I don't understand what you mean. How do you reference the object without referencing the object? (Which is what $self is right? a reference to the object.)

really, thank you for all of your help.


In reply to Re^4: Problem with Inheriting a Super Class by PyrexKidd
in thread Problem with Inheriting a Super Class by PyrexKidd

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.