Well you can always use things like Class::Object, Class::Classless, and the like.

There was also talk of having support for truly anonymous classes. (In fact Simon Cozens tried to single-handedly add support for that to Perl 5 and was told not to.) I have no idea what current plans for that are supposed to be.

As for better ways, well I like the way that Smalltalk does it (and other languages have borrowed it - I am more familiar with the way it works in Ruby than Smalltalk). In Smalltalk a class is an object. Any variable can hold a class, but normally you would want your classes to be held in global variables. An object belongs to a class. The methods of an object are accessed through a lookup on the class. There is a distinction here between class methods (ie methods of the class object) and object methods (ie methods of the object that is a member of the class).

For instance Ruby has a File class. File has methods relating to files but not a specific file, for instance it has methods for various file tests. When you call File.open you get an instance of class File. This instance has methods appropriate to handling a file, you can read, print, and so on. However it makes no sense to ask a file whether another file exists, so you can't. That isn't an object method. It makes no sense to ask the concept of a File to read the next line. So you can't. That isn't a class method.

Perl confuses object and class methods in a most unfortunate way. However if you wanted to, you could create the above structure in Perl. You could probably do it fairly efficiently. These classes would usually be anonymous. Hmm....

But I won't. Yet.


In reply to Re (tilly) 1: Hiding Internal Classes ? by tilly
in thread Hiding Internal Classes ? by John M. Dlugosz

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.