The first argument passed to an object method is always
The originally blessed reference
Whatever the first argument was when you invoked the method
Can you have method names with the same names as built-in functions, or of already-defined subroutines?
Yes, but it's difficult, as noted in Hour 8, "Functions."
Yes, and there are no concerns really.
Does the constructor subroutine in a class have to be called new?
b. The reference that was blessed in the constructor is returned to each method. In this way the method gets a handle back to the object, and can use it to do its work.
b. It's not really a problem because Perl can always tell that you meant the method—and not the built-in—because it will appear on the right-hand side of a -> operator.
b. No. That's just the convention. If you use a different subroutine name, users of your class might get confused.
In the Q&A section, question 3 explained the AUTOLOAD method. How do you think you could construct an AUTOLOAD method that would only be able to access some of the properties within the object and not others? For a hint, see the perltoot manual page.
Sketch out a DirectoryInfo class. It would be a bit different than a FileInfo class. What methods would you need? What kinds of properties would you need to store?
The TYPFileInfoOO class recomputes the file size and line count each time the byte and lines methods are called. Is this a good idea? If you wanted to store those values so that subsequent calls would fetch the cached values instead of recomputing them each time, how would you do it?
© 2000- NIV