First off, the test program doesn't compile as posted -- there's no semi-colon at the end of the line for "my $test=new round...". Apart from that, you are using curly braces around the args being passed to "new round", which means you are passing an anonymous hash to the the "new" method for this object. Inside the object's "new" method, you are taking the first arg received after the class name as the value to assign to _round; since your test code is passing a reference to an anonymous hash as its first and only arg, this is what the "roundnum" method will return.
On the other hand, if you were to use parens (like you're supposed to) instead of curlies around the args that you pass to "new round", you might still not get what you want, because your test code is now passing a list that looks like a "key=>value" pair, whereas the "new" method seems to be expecting just a list of values (no keys). So by just replacing curlies with parens, the test output is the string "roundnum", not the value "1". So make up your mind what sort of calling protocol you want, and write both the object and the test to use the same protocol.
Hope that helps.
In reply to Re: OO Simple THing
by graff
in thread OO Simple THing
by gpmartinson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |