Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1347 lines
52 KiB

  1. =head1 NAME
  2. perltootc - Tom's OO Tutorial for Class Data in Perl
  3. =head1 DESCRIPTION
  4. When designing an object class, you are sometimes faced with the situation
  5. of wanting common state shared by all objects of that class.
  6. Such I<class attributes> act somewhat like global variables for the entire
  7. class, but unlike program-wide globals, class attributes have meaning only to
  8. the class itself.
  9. Here are a few examples where class attributes might come in handy:
  10. =over 4
  11. =item *
  12. to keep a count of the objects you've created, or how many are
  13. still extant.
  14. =item *
  15. to extract the name or file descriptor for a logfile used by a debugging
  16. method.
  17. =item *
  18. to access collective data, like the total amount of cash dispensed by
  19. all ATMs in a network in a given day.
  20. =item *
  21. to access the last object created by a class, or the most accessed object,
  22. or to retrieve a list of all objects.
  23. =back
  24. Unlike a true global, class attributes should not be accessed directly.
  25. Instead, their state should be inspected, and perhaps altered, only
  26. through the mediated access of I<class methods>. These class attributes
  27. accessor methods are similar in spirit and function to accessors used
  28. to manipulate the state of instance attributes on an object. They provide a
  29. clear firewall between interface and implementation.
  30. You should allow access to class attributes through either the class
  31. name or any object of that class. If we assume that $an_object is of
  32. type Some_Class, and the &Some_Class::population_count method accesses
  33. class attributes, then these two invocations should both be possible,
  34. and almost certainly equivalent.
  35. Some_Class->population_count()
  36. $an_object->population_count()
  37. The question is, where do you store the state which that method accesses?
  38. Unlike more restrictive languages like C++, where these are called
  39. static data members, Perl provides no syntactic mechanism to declare
  40. class attributes, any more than it provides a syntactic mechanism to
  41. declare instance attributes. Perl provides the developer with a broad
  42. set of powerful but flexible features that can be uniquely crafted to
  43. the particular demands of the situation.
  44. A class in Perl is typically implemented in a module. A module consists
  45. of two complementary feature sets: a package for interfacing with the
  46. outside world, and a lexical file scope for privacy. Either of these
  47. two mechanisms can be used to implement class attributes. That means you
  48. get to decide whether to put your class attributes in package variables
  49. or to put them in lexical variables.
  50. And those aren't the only decisions to make. If you choose to use package
  51. variables, you can make your class attribute accessor methods either ignorant
  52. of inheritance or sensitive to it. If you choose lexical variables,
  53. you can elect to permit access to them from anywhere in the entire file
  54. scope, or you can limit direct data access exclusively to the methods
  55. implementing those attributes.
  56. =head1 Class Data in a Can
  57. One of the easiest ways to solve a hard problem is to let someone else
  58. do it for you! In this case, Class::Data::Inheritable (available on a
  59. CPAN near you) offers a canned solution to the class data problem
  60. using closures. So before you wade into this document, consider
  61. having a look at that module.
  62. =head1 Class Data as Package Variables
  63. Because a class in Perl is really just a package, using package variables
  64. to hold class attributes is the most natural choice. This makes it simple
  65. for each class to have its own class attributes. Let's say you have a class
  66. called Some_Class that needs a couple of different attributes that you'd
  67. like to be global to the entire class. The simplest thing to do is to
  68. use package variables like $Some_Class::CData1 and $Some_Class::CData2
  69. to hold these attributes. But we certainly don't want to encourage
  70. outsiders to touch those data directly, so we provide methods
  71. to mediate access.
  72. In the accessor methods below, we'll for now just ignore the first
  73. argument--that part to the left of the arrow on method invocation, which
  74. is either a class name or an object reference.
  75. package Some_Class;
  76. sub CData1 {
  77. shift; # XXX: ignore calling class/object
  78. $Some_Class::CData1 = shift if @_;
  79. return $Some_Class::CData1;
  80. }
  81. sub CData2 {
  82. shift; # XXX: ignore calling class/object
  83. $Some_Class::CData2 = shift if @_;
  84. return $Some_Class::CData2;
  85. }
  86. This technique is highly legible and should be completely straightforward
  87. to even the novice Perl programmer. By fully qualifying the package
  88. variables, they stand out clearly when reading the code. Unfortunately,
  89. if you misspell one of these, you've introduced an error that's hard
  90. to catch. It's also somewhat disconcerting to see the class name itself
  91. hard-coded in so many places.
  92. Both these problems can be easily fixed. Just add the C<use strict>
  93. pragma, then pre-declare your package variables. (The C<our> operator
  94. will be new in 5.6, and will work for package globals just like C<my>
  95. works for scoped lexicals.)
  96. package Some_Class;
  97. use strict;
  98. our($CData1, $CData2); # our() is new to perl5.6
  99. sub CData1 {
  100. shift; # XXX: ignore calling class/object
  101. $CData1 = shift if @_;
  102. return $CData1;
  103. }
  104. sub CData2 {
  105. shift; # XXX: ignore calling class/object
  106. $CData2 = shift if @_;
  107. return $CData2;
  108. }
  109. As with any other global variable, some programmers prefer to start their
  110. package variables with capital letters. This helps clarity somewhat, but
  111. by no longer fully qualifying the package variables, their significance
  112. can be lost when reading the code. You can fix this easily enough by
  113. choosing better names than were used here.
  114. =head2 Putting All Your Eggs in One Basket
  115. Just as the mindless enumeration of accessor methods for instance attributes
  116. grows tedious after the first few (see L<perltoot>), so too does the
  117. repetition begin to grate when listing out accessor methods for class
  118. data. Repetition runs counter to the primary virtue of a programmer:
  119. Laziness, here manifesting as that innate urge every programmer feels
  120. to factor out duplicate code whenever possible.
  121. Here's what to do. First, make just one hash to hold all class attributes.
  122. package Some_Class;
  123. use strict;
  124. our %ClassData = ( # our() is new to perl5.6
  125. CData1 => "",
  126. CData2 => "",
  127. );
  128. Using closures (see L<perlref>) and direct access to the package symbol
  129. table (see L<perlmod>), now clone an accessor method for each key in
  130. the %ClassData hash. Each of these methods is used to fetch or store
  131. values to the specific, named class attribute.
  132. for my $datum (keys %ClassData) {
  133. no strict "refs"; # to register new methods in package
  134. *$datum = sub {
  135. shift; # XXX: ignore calling class/object
  136. $ClassData{$datum} = shift if @_;
  137. return $ClassData{$datum};
  138. }
  139. }
  140. It's true that you could work out a solution employing an &AUTOLOAD
  141. method, but this approach is unlikely to prove satisfactory. Your
  142. function would have to distinguish between class attributes and object
  143. attributes; it could interfere with inheritance; and it would have to
  144. careful about DESTROY. Such complexity is uncalled for in most cases,
  145. and certainly in this one.
  146. You may wonder why we're rescinding strict refs for the loop. We're
  147. manipulating the package's symbol table to introduce new function names
  148. using symbolic references (indirect naming), which the strict pragma
  149. would otherwise forbid. Normally, symbolic references are a dodgy
  150. notion at best. This isn't just because they can be used accidentally
  151. when you aren't meaning to. It's also because for most uses
  152. to which beginning Perl programmers attempt to put symbolic references,
  153. we have much better approaches, like nested hashes or hashes of arrays.
  154. But there's nothing wrong with using symbolic references to manipulate
  155. something that is meaningful only from the perspective of the package
  156. symbol table, like method names or package variables. In other
  157. words, when you want to refer to the symbol table, use symbol references.
  158. Clustering all the class attributes in one place has several advantages.
  159. They're easy to spot, initialize, and change. The aggregation also
  160. makes them convenient to access externally, such as from a debugger
  161. or a persistence package. The only possible problem is that we don't
  162. automatically know the name of each class's class object, should it have
  163. one. This issue is addressed below in L<"The Eponymous Meta-Object">.
  164. =head2 Inheritance Concerns
  165. Suppose you have an instance of a derived class, and you access class
  166. data using an inherited method call. Should that end up referring
  167. to the base class's attributes, or to those in the derived class?
  168. How would it work in the earlier examples? The derived class inherits
  169. all the base class's methods, including those that access class attributes.
  170. But what package are the class attributes stored in?
  171. The answer is that, as written, class attributes are stored in the package into
  172. which those methods were compiled. When you invoke the &CData1 method
  173. on the name of the derived class or on one of that class's objects, the
  174. version shown above is still run, so you'll access $Some_Class::CData1--or
  175. in the method cloning version, C<$Some_Class::ClassData{CData1}>.
  176. Think of these class methods as executing in the context of their base
  177. class, not in that of their derived class. Sometimes this is exactly
  178. what you want. If Feline subclasses Carnivore, then the population of
  179. Carnivores in the world should go up when a new Feline is born.
  180. But what if you wanted to figure out how many Felines you have apart
  181. from Carnivores? The current approach doesn't support that.
  182. You'll have to decide on a case-by-case basis whether it makes any sense
  183. for class attributes to be package-relative. If you want it to be so,
  184. then stop ignoring the first argument to the function. Either it will
  185. be a package name if the method was invoked directly on a class name,
  186. or else it will be an object reference if the method was invoked on an
  187. object reference. In the latter case, the ref() function provides the
  188. class of that object.
  189. package Some_Class;
  190. sub CData1 {
  191. my $obclass = shift;
  192. my $class = ref($obclass) || $obclass;
  193. my $varname = $class . "::CData1";
  194. no strict "refs"; # to access package data symbolically
  195. $$varname = shift if @_;
  196. return $$varname;
  197. }
  198. And then do likewise for all other class attributes (such as CData2,
  199. etc.) that you wish to access as package variables in the invoking package
  200. instead of the compiling package as we had previously.
  201. Once again we temporarily disable the strict references ban, because
  202. otherwise we couldn't use the fully-qualified symbolic name for
  203. the package global. This is perfectly reasonable: since all package
  204. variables by definition live in a package, there's nothing wrong with
  205. accessing them via that package's symbol table. That's what it's there
  206. for (well, somewhat).
  207. What about just using a single hash for everything and then cloning
  208. methods? What would that look like? The only difference would be the
  209. closure used to produce new method entries for the class's symbol table.
  210. no strict "refs";
  211. *$datum = sub {
  212. my $obclass = shift;
  213. my $class = ref($obclass) || $obclass;
  214. my $varname = $class . "::ClassData";
  215. $varname->{$datum} = shift if @_;
  216. return $varname->{$datum};
  217. }
  218. =head2 The Eponymous Meta-Object
  219. It could be argued that the %ClassData hash in the previous example is
  220. neither the most imaginative nor the most intuitive of names. Is there
  221. something else that might make more sense, be more useful, or both?
  222. As it happens, yes, there is. For the "class meta-object", we'll use
  223. a package variable of the same name as the package itself. Within the
  224. scope of a package Some_Class declaration, we'll use the eponymously
  225. named hash %Some_Class as that class's meta-object. (Using an eponymously
  226. named hash is somewhat reminiscent of classes that name their constructors
  227. eponymously in the Python or C++ fashion. That is, class Some_Class would
  228. use &Some_Class::Some_Class as a constructor, probably even exporting that
  229. name as well. The StrNum class in Recipe 13.14 in I<The Perl Cookbook>
  230. does this, if you're looking for an example.)
  231. This predictable approach has many benefits, including having a well-known
  232. identifier to aid in debugging, transparent persistence,
  233. or checkpointing. It's also the obvious name for monadic classes and
  234. translucent attributes, discussed later.
  235. Here's an example of such a class. Notice how the name of the
  236. hash storing the meta-object is the same as the name of the package
  237. used to implement the class.
  238. package Some_Class;
  239. use strict;
  240. # create class meta-object using that most perfect of names
  241. our %Some_Class = ( # our() is new to perl5.6
  242. CData1 => "",
  243. CData2 => "",
  244. );
  245. # this accessor is calling-package-relative
  246. sub CData1 {
  247. my $obclass = shift;
  248. my $class = ref($obclass) || $obclass;
  249. no strict "refs"; # to access eponymous meta-object
  250. $class->{CData1} = shift if @_;
  251. return $class->{CData1};
  252. }
  253. # but this accessor is not
  254. sub CData2 {
  255. shift; # XXX: ignore calling class/object
  256. no strict "refs"; # to access eponymous meta-object
  257. __PACKAGE__ -> {CData2} = shift if @_;
  258. return __PACKAGE__ -> {CData2};
  259. }
  260. In the second accessor method, the __PACKAGE__ notation was used for
  261. two reasons. First, to avoid hardcoding the literal package name
  262. in the code in case we later want to change that name. Second, to
  263. clarify to the reader that what matters here is the package currently
  264. being compiled into, not the package of the invoking object or class.
  265. If the long sequence of non-alphabetic characters bothers you, you can
  266. always put the __PACKAGE__ in a variable first.
  267. sub CData2 {
  268. shift; # XXX: ignore calling class/object
  269. no strict "refs"; # to access eponymous meta-object
  270. my $class = __PACKAGE__;
  271. $class->{CData2} = shift if @_;
  272. return $class->{CData2};
  273. }
  274. Even though we're using symbolic references for good not evil, some
  275. folks tend to become unnerved when they see so many places with strict
  276. ref checking disabled. Given a symbolic reference, you can always
  277. produce a real reference (the reverse is not true, though). So we'll
  278. create a subroutine that does this conversion for us. If invoked as a
  279. function of no arguments, it returns a reference to the compiling class's
  280. eponymous hash. Invoked as a class method, it returns a reference to
  281. the eponymous hash of its caller. And when invoked as an object method,
  282. this function returns a reference to the eponymous hash for whatever
  283. class the object belongs to.
  284. package Some_Class;
  285. use strict;
  286. our %Some_Class = ( # our() is new to perl5.6
  287. CData1 => "",
  288. CData2 => "",
  289. );
  290. # tri-natured: function, class method, or object method
  291. sub _classobj {
  292. my $obclass = shift || __PACKAGE__;
  293. my $class = ref($obclass) || $obclass;
  294. no strict "refs"; # to convert sym ref to real one
  295. return \%$class;
  296. }
  297. for my $datum (keys %{ _classobj() } ) {
  298. # turn off strict refs so that we can
  299. # register a method in the symbol table
  300. no strict "refs";
  301. *$datum = sub {
  302. use strict "refs";
  303. my $self = shift->_classobj();
  304. $self->{$datum} = shift if @_;
  305. return $self->{$datum};
  306. }
  307. }
  308. =head2 Indirect References to Class Data
  309. A reasonably common strategy for handling class attributes is to store
  310. a reference to each package variable on the object itself. This is
  311. a strategy you've probably seen before, such as in L<perltoot> and
  312. L<perlbot>, but there may be variations in the example below that you
  313. haven't thought of before.
  314. package Some_Class;
  315. our($CData1, $CData2); # our() is new to perl5.6
  316. sub new {
  317. my $obclass = shift;
  318. return bless my $self = {
  319. ObData1 => "",
  320. ObData2 => "",
  321. CData1 => \$CData1,
  322. CData2 => \$CData2,
  323. } => (ref $obclass || $obclass);
  324. }
  325. sub ObData1 {
  326. my $self = shift;
  327. $self->{ObData1} = shift if @_;
  328. return $self->{ObData1};
  329. }
  330. sub ObData2 {
  331. my $self = shift;
  332. $self->{ObData2} = shift if @_;
  333. return $self->{ObData2};
  334. }
  335. sub CData1 {
  336. my $self = shift;
  337. my $dataref = ref $self
  338. ? $self->{CData1}
  339. : \$CData1;
  340. $$dataref = shift if @_;
  341. return $$dataref;
  342. }
  343. sub CData2 {
  344. my $self = shift;
  345. my $dataref = ref $self
  346. ? $self->{CData2}
  347. : \$CData2;
  348. $$dataref = shift if @_;
  349. return $$dataref;
  350. }
  351. As written above, a derived class will inherit these methods, which
  352. will consequently access package variables in the base class's package.
  353. This is not necessarily expected behavior in all circumstances. Here's an
  354. example that uses a variable meta-object, taking care to access the
  355. proper package's data.
  356. package Some_Class;
  357. use strict;
  358. our %Some_Class = ( # our() is new to perl5.6
  359. CData1 => "",
  360. CData2 => "",
  361. );
  362. sub _classobj {
  363. my $self = shift;
  364. my $class = ref($self) || $self;
  365. no strict "refs";
  366. # get (hard) ref to eponymous meta-object
  367. return \%$class;
  368. }
  369. sub new {
  370. my $obclass = shift;
  371. my $classobj = $obclass->_classobj();
  372. bless my $self = {
  373. ObData1 => "",
  374. ObData2 => "",
  375. CData1 => \$classobj->{CData1},
  376. CData2 => \$classobj->{CData2},
  377. } => (ref $obclass || $obclass);
  378. return $self;
  379. }
  380. sub ObData1 {
  381. my $self = shift;
  382. $self->{ObData1} = shift if @_;
  383. return $self->{ObData1};
  384. }
  385. sub ObData2 {
  386. my $self = shift;
  387. $self->{ObData2} = shift if @_;
  388. return $self->{ObData2};
  389. }
  390. sub CData1 {
  391. my $self = shift;
  392. $self = $self->_classobj() unless ref $self;
  393. my $dataref = $self->{CData1};
  394. $$dataref = shift if @_;
  395. return $$dataref;
  396. }
  397. sub CData2 {
  398. my $self = shift;
  399. $self = $self->_classobj() unless ref $self;
  400. my $dataref = $self->{CData2};
  401. $$dataref = shift if @_;
  402. return $$dataref;
  403. }
  404. Not only are we now strict refs clean, using an eponymous meta-object
  405. seems to make the code cleaner. Unlike the previous version, this one
  406. does something interesting in the face of inheritance: it accesses the
  407. class meta-object in the invoking class instead of the one into which
  408. the method was initially compiled.
  409. You can easily access data in the class meta-object, making
  410. it easy to dump the complete class state using an external mechanism such
  411. as when debugging or implementing a persistent class. This works because
  412. the class meta-object is a package variable, has a well-known name, and
  413. clusters all its data together. (Transparent persistence
  414. is not always feasible, but it's certainly an appealing idea.)
  415. There's still no check that object accessor methods have not been
  416. invoked on a class name. If strict ref checking is enabled, you'd
  417. blow up. If not, then you get the eponymous meta-object. What you do
  418. with--or about--this is up to you. The next two sections demonstrate
  419. innovative uses for this powerful feature.
  420. =head2 Monadic Classes
  421. Some of the standard modules shipped with Perl provide class interfaces
  422. without any attribute methods whatsoever. The most commonly used module
  423. not numbered amongst the pragmata, the Exporter module, is a class with
  424. neither constructors nor attributes. Its job is simply to provide a
  425. standard interface for modules wishing to export part of their namespace
  426. into that of their caller. Modules use the Exporter's &import method by
  427. setting their inheritance list in their package's @ISA array to mention
  428. "Exporter". But class Exporter provides no constructor, so you can't
  429. have several instances of the class. In fact, you can't have any--it
  430. just doesn't make any sense. All you get is its methods. Its interface
  431. contains no statefulness, so state data is wholly superfluous.
  432. Another sort of class that pops up from time to time is one that supports
  433. a unique instance. Such classes are called I<monadic classes>, or less
  434. formally, I<singletons> or I<highlander classes>.
  435. If a class is monadic, where do you store its state, that is,
  436. its attributes? How do you make sure that there's never more than
  437. one instance? While you could merely use a slew of package variables,
  438. it's a lot cleaner to use the eponymously named hash. Here's a complete
  439. example of a monadic class:
  440. package Cosmos;
  441. %Cosmos = ();
  442. # accessor method for "name" attribute
  443. sub name {
  444. my $self = shift;
  445. $self->{name} = shift if @_;
  446. return $self->{name};
  447. }
  448. # read-only accessor method for "birthday" attribute
  449. sub birthday {
  450. my $self = shift;
  451. die "can't reset birthday" if @_; # XXX: croak() is better
  452. return $self->{birthday};
  453. }
  454. # accessor method for "stars" attribute
  455. sub stars {
  456. my $self = shift;
  457. $self->{stars} = shift if @_;
  458. return $self->{stars};
  459. }
  460. # oh my - one of our stars just went out!
  461. sub supernova {
  462. my $self = shift;
  463. my $count = $self->stars();
  464. $self->stars($count - 1) if $count > 0;
  465. }
  466. # constructor/initializer method - fix by reboot
  467. sub bigbang {
  468. my $self = shift;
  469. %$self = (
  470. name => "the world according to tchrist",
  471. birthday => time(),
  472. stars => 0,
  473. );
  474. return $self; # yes, it's probably a class. SURPRISE!
  475. }
  476. # After the class is compiled, but before any use or require
  477. # returns, we start off the universe with a bang.
  478. __PACKAGE__ -> bigbang();
  479. Hold on, that doesn't look like anything special. Those attribute
  480. accessors look no different than they would if this were a regular class
  481. instead of a monadic one. The crux of the matter is there's nothing
  482. that says that $self must hold a reference to a blessed object. It merely
  483. has to be something you can invoke methods on. Here the package name
  484. itself, Cosmos, works as an object. Look at the &supernova method. Is that
  485. a class method or an object method? The answer is that static analysis
  486. cannot reveal the answer. Perl doesn't care, and neither should you.
  487. In the three attribute methods, C<%$self> is really accessing the %Cosmos
  488. package variable.
  489. If like Stephen Hawking, you posit the existence of multiple, sequential,
  490. and unrelated universes, then you can invoke the &bigbang method yourself
  491. at any time to start everything all over again. You might think of
  492. &bigbang as more of an initializer than a constructor, since the function
  493. doesn't allocate new memory; it only initializes what's already there.
  494. But like any other constructor, it does return a scalar value to use
  495. for later method invocations.
  496. Imagine that some day in the future, you decide that one universe just
  497. isn't enough. You could write a new class from scratch, but you already
  498. have an existing class that does what you want--except that it's monadic,
  499. and you want more than just one cosmos.
  500. That's what code reuse via subclassing is all about. Look how short
  501. the new code is:
  502. package Multiverse;
  503. use Cosmos;
  504. @ISA = qw(Cosmos);
  505. sub new {
  506. my $protoverse = shift;
  507. my $class = ref($protoverse) || $protoverse;
  508. my $self = {};
  509. return bless($self, $class)->bigbang();
  510. }
  511. 1;
  512. Because we were careful to be good little creators when we designed our
  513. Cosmos class, we can now reuse it without touching a single line of code
  514. when it comes time to write our Multiverse class. The same code that
  515. worked when invoked as a class method continues to work perfectly well
  516. when invoked against separate instances of a derived class.
  517. The astonishing thing about the Cosmos class above is that the value
  518. returned by the &bigbang "constructor" is not a reference to a blessed
  519. object at all. It's just the class's own name. A class name is, for
  520. virtually all intents and purposes, a perfectly acceptable object.
  521. It has state, behavior, and identify, the three crucial components
  522. of an object system. It even manifests inheritance, polymorphism,
  523. and encapsulation. And what more can you ask of an object?
  524. To understand object orientation in Perl, it's important to recognize the
  525. unification of what other programming languages might think of as class
  526. methods and object methods into just plain methods. "Class methods"
  527. and "object methods" are distinct only in the compartmentalizing mind
  528. of the Perl programmer, not in the Perl language itself.
  529. Along those same lines, a constructor is nothing special either, which
  530. is one reason why Perl has no pre-ordained name for them. "Constructor"
  531. is just an informal term loosely used to describe a method that returns
  532. a scalar value that you can make further method calls against. So long
  533. as it's either a class name or an object reference, that's good enough.
  534. It doesn't even have to be a reference to a brand new object.
  535. You can have as many--or as few--constructors as you want, and you can
  536. name them whatever you care to. Blindly and obediently using new()
  537. for each and every constructor you ever write is to speak Perl with
  538. such a severe C++ accent that you do a disservice to both languages.
  539. There's no reason to insist that each class have but one constructor,
  540. or that that constructor be named new(), or that that constructor be
  541. used solely as a class method and not an object method.
  542. The next section shows how useful it can be to further distance ourselves
  543. from any formal distinction between class method calls and object method
  544. calls, both in constructors and in accessor methods.
  545. =head2 Translucent Attributes
  546. A package's eponymous hash can be used for more than just containing
  547. per-class, global state data. It can also serve as a sort of template
  548. containing default settings for object attributes. These default
  549. settings can then be used in constructors for initialization of a
  550. particular object. The class's eponymous hash can also be used to
  551. implement I<translucent attributes>. A translucent attribute is one
  552. that has a class-wide default. Each object can set its own value for the
  553. attribute, in which case C<< $object->attribute() >> returns that value.
  554. But if no value has been set, then C<< $object->attribute() >> returns
  555. the class-wide default.
  556. We'll apply something of a copy-on-write approach to these translucent
  557. attributes. If you're just fetching values from them, you get
  558. translucency. But if you store a new value to them, that new value is
  559. set on the current object. On the other hand, if you use the class as
  560. an object and store the attribute value directly on the class, then the
  561. meta-object's value changes, and later fetch operations on objects with
  562. uninitialized values for those attributes will retrieve the meta-object's
  563. new values. Objects with their own initialized values, however, won't
  564. see any change.
  565. Let's look at some concrete examples of using these properties before we
  566. show how to implement them. Suppose that a class named Some_Class
  567. had a translucent data attribute called "color". First you set the color
  568. in the meta-object, then you create three objects using a constructor
  569. that happens to be named &spawn.
  570. use Vermin;
  571. Vermin->color("vermilion");
  572. $ob1 = Vermin->spawn(); # so that's where Jedi come from
  573. $ob2 = Vermin->spawn();
  574. $ob3 = Vermin->spawn();
  575. print $obj3->color(); # prints "vermilion"
  576. Each of these objects' colors is now "vermilion", because that's the
  577. meta-object's value that attribute, and these objects do not have
  578. individual color values set.
  579. Changing the attribute on one object has no effect on other objects
  580. previously created.
  581. $ob3->color("chartreuse");
  582. print $ob3->color(); # prints "chartreuse"
  583. print $ob1->color(); # prints "vermilion", translucently
  584. If you now use $ob3 to spawn off another object, the new object will
  585. take the color its parent held, which now happens to be "chartreuse".
  586. That's because the constructor uses the invoking object as its template
  587. for initializing attributes. When that invoking object is the
  588. class name, the object used as a template is the eponymous meta-object.
  589. When the invoking object is a reference to an instantiated object, the
  590. &spawn constructor uses that existing object as a template.
  591. $ob4 = $ob3->spawn(); # $ob3 now template, not %Vermin
  592. print $ob4->color(); # prints "chartreuse"
  593. Any actual values set on the template object will be copied to the
  594. new object. But attributes undefined in the template object, being
  595. translucent, will remain undefined and consequently translucent in the
  596. new one as well.
  597. Now let's change the color attribute on the entire class:
  598. Vermin->color("azure");
  599. print $ob1->color(); # prints "azure"
  600. print $ob2->color(); # prints "azure"
  601. print $ob3->color(); # prints "chartreuse"
  602. print $ob4->color(); # prints "chartreuse"
  603. That color change took effect only in the first pair of objects, which
  604. were still translucently accessing the meta-object's values. The second
  605. pair had per-object initialized colors, and so didn't change.
  606. One important question remains. Changes to the meta-object are reflected
  607. in translucent attributes in the entire class, but what about
  608. changes to discrete objects? If you change the color of $ob3, does the
  609. value of $ob4 see that change? Or vice-versa. If you change the color
  610. of $ob4, does then the value of $ob3 shift?
  611. $ob3->color("amethyst");
  612. print $ob3->color(); # prints "amethyst"
  613. print $ob4->color(); # hmm: "chartreuse" or "amethyst"?
  614. While one could argue that in certain rare cases it should, let's not
  615. do that. Good taste aside, we want the answer to the question posed in
  616. the comment above to be "chartreuse", not "amethyst". So we'll treat
  617. these attributes similar to the way process attributes like environment
  618. variables, user and group IDs, or the current working directory are
  619. treated across a fork(). You can change only yourself, but you will see
  620. those changes reflected in your unspawned children. Changes to one object
  621. will propagate neither up to the parent nor down to any existing child objects.
  622. Those objects made later, however, will see the changes.
  623. If you have an object with an actual attribute value, and you want to
  624. make that object's attribute value translucent again, what do you do?
  625. Let's design the class so that when you invoke an accessor method with
  626. C<undef> as its argument, that attribute returns to translucency.
  627. $ob4->color(undef); # back to "azure"
  628. Here's a complete implementation of Vermin as described above.
  629. package Vermin;
  630. # here's the class meta-object, eponymously named.
  631. # it holds all class attributes, and also all instance attributes
  632. # so the latter can be used for both initialization
  633. # and translucency.
  634. our %Vermin = ( # our() is new to perl5.6
  635. PopCount => 0, # capital for class attributes
  636. color => "beige", # small for instance attributes
  637. );
  638. # constructor method
  639. # invoked as class method or object method
  640. sub spawn {
  641. my $obclass = shift;
  642. my $class = ref($obclass) || $obclass;
  643. my $self = {};
  644. bless($self, $class);
  645. $class->{PopCount}++;
  646. # init fields from invoking object, or omit if
  647. # invoking object is the class to provide translucency
  648. %$self = %$obclass if ref $obclass;
  649. return $self;
  650. }
  651. # translucent accessor for "color" attribute
  652. # invoked as class method or object method
  653. sub color {
  654. my $self = shift;
  655. my $class = ref($self) || $self;
  656. # handle class invocation
  657. unless (ref $self) {
  658. $class->{color} = shift if @_;
  659. return $class->{color}
  660. }
  661. # handle object invocation
  662. $self->{color} = shift if @_;
  663. if (defined $self->{color}) { # not exists!
  664. return $self->{color};
  665. } else {
  666. return $class->{color};
  667. }
  668. }
  669. # accessor for "PopCount" class attribute
  670. # invoked as class method or object method
  671. # but uses object solely to locate meta-object
  672. sub population {
  673. my $obclass = shift;
  674. my $class = ref($obclass) || $obclass;
  675. return $class->{PopCount};
  676. }
  677. # instance destructor
  678. # invoked only as object method
  679. sub DESTROY {
  680. my $self = shift;
  681. my $class = ref $self;
  682. $class->{PopCount}--;
  683. }
  684. Here are a couple of helper methods that might be convenient. They aren't
  685. accessor methods at all. They're used to detect accessibility of data
  686. attributes. The &is_translucent method determines whether a particular
  687. object attribute is coming from the meta-object. The &has_attribute
  688. method detects whether a class implements a particular property at all.
  689. It could also be used to distinguish undefined properties from non-existent
  690. ones.
  691. # detect whether an object attribute is translucent
  692. # (typically?) invoked only as object method
  693. sub is_translucent {
  694. my($self, $attr) = @_;
  695. return !defined $self->{$attr};
  696. }
  697. # test for presence of attribute in class
  698. # invoked as class method or object method
  699. sub has_attribute {
  700. my($self, $attr) = @_;
  701. my $class = ref $self if $self;
  702. return exists $class->{$attr};
  703. }
  704. If you prefer to install your accessors more generically, you can make
  705. use of the upper-case versus lower-case convention to register into the
  706. package appropriate methods cloned from generic closures.
  707. for my $datum (keys %{ +__PACKAGE__ }) {
  708. *$datum = ($datum =~ /^[A-Z]/)
  709. ? sub { # install class accessor
  710. my $obclass = shift;
  711. my $class = ref($obclass) || $obclass;
  712. return $class->{$datum};
  713. }
  714. : sub { # install translucent accessor
  715. my $self = shift;
  716. my $class = ref($self) || $self;
  717. unless (ref $self) {
  718. $class->{$datum} = shift if @_;
  719. return $class->{$datum}
  720. }
  721. $self->{$datum} = shift if @_;
  722. return defined $self->{$datum}
  723. ? $self -> {$datum}
  724. : $class -> {$datum}
  725. }
  726. }
  727. Translations of this closure-based approach into C++, Java, and Python
  728. have been left as exercises for the reader. Be sure to send us mail as
  729. soon as you're done.
  730. =head1 Class Data as Lexical Variables
  731. =head2 Privacy and Responsibility
  732. Unlike conventions used by some Perl programmers, in the previous
  733. examples, we didn't prefix the package variables used for class attributes
  734. with an underscore, nor did we do so for the names of the hash keys used
  735. for instance attributes. You don't need little markers on data names to
  736. suggest nominal privacy on attribute variables or hash keys, because these
  737. are B<already> notionally private! Outsiders have no business whatsoever
  738. playing with anything within a class save through the mediated access of
  739. its documented interface; in other words, through method invocations.
  740. And not even through just any method, either. Methods that begin with
  741. an underscore are traditionally considered off-limits outside the class.
  742. If outsiders skip the documented method interface to poke around the
  743. internals of your class and end up breaking something, that's not your
  744. fault--it's theirs.
  745. Perl believes in individual responsibility rather than mandated control.
  746. Perl respects you enough to let you choose your own preferred level of
  747. pain, or of pleasure. Perl believes that you are creative, intelligent,
  748. and capable of making your own decisions--and fully expects you to
  749. take complete responsibility for your own actions. In a perfect world,
  750. these admonitions alone would suffice, and everyone would be intelligent,
  751. responsible, happy, and creative. And careful. One probably shouldn't
  752. forget careful, and that's a good bit harder to expect. Even Einstein
  753. would take wrong turns by accident and end up lost in the wrong part
  754. of town.
  755. Some folks get the heebie-jeebies when they see package variables
  756. hanging out there for anyone to reach over and alter them. Some folks
  757. live in constant fear that someone somewhere might do something wicked.
  758. The solution to that problem is simply to fire the wicked, of course.
  759. But unfortunately, it's not as simple as all that. These cautious
  760. types are also afraid that they or others will do something not so
  761. much wicked as careless, whether by accident or out of desperation.
  762. If we fire everyone who ever gets careless, pretty soon there won't be
  763. anybody left to get any work done.
  764. Whether it's needless paranoia or sensible caution, this uneasiness can
  765. be a problem for some people. We can take the edge off their discomfort
  766. by providing the option of storing class attributes as lexical variables
  767. instead of as package variables. The my() operator is the source of
  768. all privacy in Perl, and it is a powerful form of privacy indeed.
  769. It is widely perceived, and indeed has often been written, that Perl
  770. provides no data hiding, that it affords the class designer no privacy
  771. nor isolation, merely a rag-tag assortment of weak and unenforcible
  772. social conventions instead. This perception is demonstrably false and
  773. easily disproven. In the next section, we show how to implement forms
  774. of privacy that are far stronger than those provided in nearly any
  775. other object-oriented language.
  776. =head2 File-Scoped Lexicals
  777. A lexical variable is visible only through the end of its static scope.
  778. That means that the only code able to access that variable is code
  779. residing textually below the my() operator through the end of its block
  780. if it has one, or through the end of the current file if it doesn't.
  781. Starting again with our simplest example given at the start of this
  782. document, we replace our() variables with my() versions.
  783. package Some_Class;
  784. my($CData1, $CData2); # file scope, not in any package
  785. sub CData1 {
  786. shift; # XXX: ignore calling class/object
  787. $CData1 = shift if @_;
  788. return $CData1;
  789. }
  790. sub CData2 {
  791. shift; # XXX: ignore calling class/object
  792. $CData2 = shift if @_;
  793. return $CData2;
  794. }
  795. So much for that old $Some_Class::CData1 package variable and its brethren!
  796. Those are gone now, replaced with lexicals. No one outside the
  797. scope can reach in and alter the class state without resorting to the
  798. documented interface. Not even subclasses or superclasses of
  799. this one have unmediated access to $CData1. They have to invoke the &CData1
  800. method against Some_Class or an instance thereof, just like anybody else.
  801. To be scrupulously honest, that last statement assumes you haven't packed
  802. several classes together into the same file scope, nor strewn your class
  803. implementation across several different files. Accessibility of those
  804. variables is based uniquely on the static file scope. It has nothing to
  805. do with the package. That means that code in a different file but
  806. the same package (class) could not access those variables, yet code in the
  807. same file but a different package (class) could. There are sound reasons
  808. why we usually suggest a one-to-one mapping between files and packages
  809. and modules and classes. You don't have to stick to this suggestion if
  810. you really know what you're doing, but you're apt to confuse yourself
  811. otherwise, especially at first.
  812. If you'd like to aggregate your class attributes into one lexically scoped,
  813. composite structure, you're perfectly free to do so.
  814. package Some_Class;
  815. my %ClassData = (
  816. CData1 => "",
  817. CData2 => "",
  818. );
  819. sub CData1 {
  820. shift; # XXX: ignore calling class/object
  821. $ClassData{CData1} = shift if @_;
  822. return $ClassData{CData1};
  823. }
  824. sub CData2 {
  825. shift; # XXX: ignore calling class/object
  826. $ClassData{CData2} = shift if @_;
  827. return $ClassData{CData2};
  828. }
  829. To make this more scalable as other class attributes are added, we can
  830. again register closures into the package symbol table to create accessor
  831. methods for them.
  832. package Some_Class;
  833. my %ClassData = (
  834. CData1 => "",
  835. CData2 => "",
  836. );
  837. for my $datum (keys %ClassData) {
  838. no strict "refs";
  839. *$datum = sub {
  840. shift; # XXX: ignore calling class/object
  841. $ClassData{$datum} = shift if @_;
  842. return $ClassData{$datum};
  843. };
  844. }
  845. Requiring even your own class to use accessor methods like anybody else is
  846. probably a good thing. But demanding and expecting that everyone else,
  847. be they subclass or superclass, friend or foe, will all come to your
  848. object through mediation is more than just a good idea. It's absolutely
  849. critical to the model. Let there be in your mind no such thing as
  850. "public" data, nor even "protected" data, which is a seductive but
  851. ultimately destructive notion. Both will come back to bite at you.
  852. That's because as soon as you take that first step out of the solid
  853. position in which all state is considered completely private, save from the
  854. perspective of its own accessor methods, you have violated the envelope.
  855. And, having pierced that encapsulating envelope, you shall doubtless
  856. someday pay the price when future changes in the implementation break
  857. unrelated code. Considering that avoiding this infelicitous outcome was
  858. precisely why you consented to suffer the slings and arrows of obsequious
  859. abstraction by turning to object orientation in the first place, such
  860. breakage seems unfortunate in the extreme.
  861. =head2 More Inheritance Concerns
  862. Suppose that Some_Class were used as a base class from which to derive
  863. Another_Class. If you invoke a &CData method on the derived class or
  864. on an object of that class, what do you get? Would the derived class
  865. have its own state, or would it piggyback on its base class's versions
  866. of the class attributes?
  867. The answer is that under the scheme outlined above, the derived class
  868. would B<not> have its own state data. As before, whether you consider
  869. this a good thing or a bad one depends on the semantics of the classes
  870. involved.
  871. The cleanest, sanest, simplest way to address per-class state in a
  872. lexical is for the derived class to override its base class's version
  873. of the method that accesses the class attributes. Since the actual method
  874. called is the one in the object's derived class if this exists, you
  875. automatically get per-class state this way. Any urge to provide an
  876. unadvertised method to sneak out a reference to the %ClassData hash
  877. should be strenuously resisted.
  878. As with any other overridden method, the implementation in the
  879. derived class always has the option of invoking its base class's
  880. version of the method in addition to its own. Here's an example:
  881. package Another_Class;
  882. @ISA = qw(Some_Class);
  883. my %ClassData = (
  884. CData1 => "",
  885. );
  886. sub CData1 {
  887. my($self, $newvalue) = @_;
  888. if (@_ > 1) {
  889. # set locally first
  890. $ClassData{CData1} = $newvalue;
  891. # then pass the buck up to the first
  892. # overridden version, if there is one
  893. if ($self->can("SUPER::CData1")) {
  894. $self->SUPER::CData1($newvalue);
  895. }
  896. }
  897. return $ClassData{CData1};
  898. }
  899. Those dabbling in multiple inheritance might be concerned
  900. about there being more than one override.
  901. for my $parent (@ISA) {
  902. my $methname = $parent . "::CData1";
  903. if ($self->can($methname)) {
  904. $self->$methname($newvalue);
  905. }
  906. }
  907. Because the &UNIVERSAL::can method returns a reference
  908. to the function directly, you can use this directly
  909. for a significant performance improvement:
  910. for my $parent (@ISA) {
  911. if (my $coderef = $self->can($parent . "::CData1")) {
  912. $self->$coderef($newvalue);
  913. }
  914. }
  915. =head2 Locking the Door and Throwing Away the Key
  916. As currently implemented, any code within the same scope as the
  917. file-scoped lexical %ClassData can alter that hash directly. Is that
  918. ok? Is it acceptable or even desirable to allow other parts of the
  919. implementation of this class to access class attributes directly?
  920. That depends on how careful you want to be. Think back to the Cosmos
  921. class. If the &supernova method had directly altered $Cosmos::Stars or
  922. C<$Cosmos::Cosmos{stars}>, then we wouldn't have been able to reuse the
  923. class when it came to inventing a Multiverse. So letting even the class
  924. itself access its own class attributes without the mediating intervention of
  925. properly designed accessor methods is probably not a good idea after all.
  926. Restricting access to class attributes from the class itself is usually
  927. not enforcible even in strongly object-oriented languages. But in Perl,
  928. you can.
  929. Here's one way:
  930. package Some_Class;
  931. { # scope for hiding $CData1
  932. my $CData1;
  933. sub CData1 {
  934. shift; # XXX: unused
  935. $CData1 = shift if @_;
  936. return $CData1;
  937. }
  938. }
  939. { # scope for hiding $CData2
  940. my $CData2;
  941. sub CData2 {
  942. shift; # XXX: unused
  943. $CData2 = shift if @_;
  944. return $CData2;
  945. }
  946. }
  947. No one--absolutely no one--is allowed to read or write the class
  948. attributes without the mediation of the managing accessor method, since
  949. only that method has access to the lexical variable it's managing.
  950. This use of mediated access to class attributes is a form of privacy far
  951. stronger than most OO languages provide.
  952. The repetition of code used to create per-datum accessor methods chafes
  953. at our Laziness, so we'll again use closures to create similar
  954. methods.
  955. package Some_Class;
  956. { # scope for ultra-private meta-object for class attributes
  957. my %ClassData = (
  958. CData1 => "",
  959. CData2 => "",
  960. );
  961. for my $datum (keys %ClassData ) {
  962. no strict "refs";
  963. *$datum = sub {
  964. use strict "refs";
  965. my ($self, $newvalue) = @_;
  966. $ClassData{$datum} = $newvalue if @_ > 1;
  967. return $ClassData{$datum};
  968. }
  969. }
  970. }
  971. The closure above can be modified to take inheritance into account using
  972. the &UNIVERSAL::can method and SUPER as shown previously.
  973. =head2 Translucency Revisited
  974. The Vermin class demonstrates translucency using a package variable,
  975. eponymously named %Vermin, as its meta-object. If you prefer to
  976. use absolutely no package variables beyond those necessary to appease
  977. inheritance or possibly the Exporter, this strategy is closed to you.
  978. That's too bad, because translucent attributes are an appealing
  979. technique, so it would be valuable to devise an implementation using
  980. only lexicals.
  981. There's a second reason why you might wish to avoid the eponymous
  982. package hash. If you use class names with double-colons in them, you
  983. would end up poking around somewhere you might not have meant to poke.
  984. package Vermin;
  985. $class = "Vermin";
  986. $class->{PopCount}++;
  987. # accesses $Vermin::Vermin{PopCount}
  988. package Vermin::Noxious;
  989. $class = "Vermin::Noxious";
  990. $class->{PopCount}++;
  991. # accesses $Vermin::Noxious{PopCount}
  992. In the first case, because the class name had no double-colons, we got
  993. the hash in the current package. But in the second case, instead of
  994. getting some hash in the current package, we got the hash %Noxious in
  995. the Vermin package. (The noxious vermin just invaded another package and
  996. sprayed their data around it. :-) Perl doesn't support relative packages
  997. in its naming conventions, so any double-colons trigger a fully-qualified
  998. lookup instead of just looking in the current package.
  999. In practice, it is unlikely that the Vermin class had an existing
  1000. package variable named %Noxious that you just blew away. If you're
  1001. still mistrustful, you could always stake out your own territory
  1002. where you know the rules, such as using Eponymous::Vermin::Noxious or
  1003. Hieronymus::Vermin::Boschious or Leave_Me_Alone::Vermin::Noxious as class
  1004. names instead. Sure, it's in theory possible that someone else has
  1005. a class named Eponymous::Vermin with its own %Noxious hash, but this
  1006. kind of thing is always true. There's no arbiter of package names.
  1007. It's always the case that globals like @Cwd::ISA would collide if more
  1008. than one class uses the same Cwd package.
  1009. If this still leaves you with an uncomfortable twinge of paranoia,
  1010. we have another solution for you. There's nothing that says that you
  1011. have to have a package variable to hold a class meta-object, either for
  1012. monadic classes or for translucent attributes. Just code up the methods
  1013. so that they access a lexical instead.
  1014. Here's another implementation of the Vermin class with semantics identical
  1015. to those given previously, but this time using no package variables.
  1016. package Vermin;
  1017. # Here's the class meta-object, eponymously named.
  1018. # It holds all class data, and also all instance data
  1019. # so the latter can be used for both initialization
  1020. # and translucency. it's a template.
  1021. my %ClassData = (
  1022. PopCount => 0, # capital for class attributes
  1023. color => "beige", # small for instance attributes
  1024. );
  1025. # constructor method
  1026. # invoked as class method or object method
  1027. sub spawn {
  1028. my $obclass = shift;
  1029. my $class = ref($obclass) || $obclass;
  1030. my $self = {};
  1031. bless($self, $class);
  1032. $ClassData{PopCount}++;
  1033. # init fields from invoking object, or omit if
  1034. # invoking object is the class to provide translucency
  1035. %$self = %$obclass if ref $obclass;
  1036. return $self;
  1037. }
  1038. # translucent accessor for "color" attribute
  1039. # invoked as class method or object method
  1040. sub color {
  1041. my $self = shift;
  1042. # handle class invocation
  1043. unless (ref $self) {
  1044. $ClassData{color} = shift if @_;
  1045. return $ClassData{color}
  1046. }
  1047. # handle object invocation
  1048. $self->{color} = shift if @_;
  1049. if (defined $self->{color}) { # not exists!
  1050. return $self->{color};
  1051. } else {
  1052. return $ClassData{color};
  1053. }
  1054. }
  1055. # class attribute accessor for "PopCount" attribute
  1056. # invoked as class method or object method
  1057. sub population {
  1058. return $ClassData{PopCount};
  1059. }
  1060. # instance destructor; invoked only as object method
  1061. sub DESTROY {
  1062. $ClassData{PopCount}--;
  1063. }
  1064. # detect whether an object attribute is translucent
  1065. # (typically?) invoked only as object method
  1066. sub is_translucent {
  1067. my($self, $attr) = @_;
  1068. $self = \%ClassData if !ref $self;
  1069. return !defined $self->{$attr};
  1070. }
  1071. # test for presence of attribute in class
  1072. # invoked as class method or object method
  1073. sub has_attribute {
  1074. my($self, $attr) = @_;
  1075. return exists $ClassData{$attr};
  1076. }
  1077. =head1 NOTES
  1078. Inheritance is a powerful but subtle device, best used only after careful
  1079. forethought and design. Aggregation instead of inheritance is often a
  1080. better approach.
  1081. We use the hypothetical our() syntax for package variables. It works
  1082. like C<use vars>, but looks like my(). It should be in this summer's
  1083. major release (5.6) of perl--we hope.
  1084. You can't use file-scoped lexicals in conjunction with the SelfLoader
  1085. or the AutoLoader, because they alter the lexical scope in which the
  1086. module's methods wind up getting compiled.
  1087. The usual mealy-mouthed package-mungeing doubtless applies to setting
  1088. up names of object attributes. For example, C<< $self->{ObData1} >>
  1089. should probably be C<< $self->{ __PACKAGE__ . "_ObData1" } >>, but that
  1090. would just confuse the examples.
  1091. =head1 SEE ALSO
  1092. L<perltoot>, L<perlobj>, L<perlmod>, and L<perlbot>.
  1093. The Tie::SecureHash and Class::Data::Inheritable modules from CPAN are
  1094. worth checking out.
  1095. =head1 AUTHOR AND COPYRIGHT
  1096. Copyright (c) 1999 Tom Christiansen.
  1097. All rights reserved.
  1098. When included as part of the Standard Version of Perl, or as part of
  1099. its complete documentation whether printed or otherwise, this work
  1100. may be distributed only under the terms of Perl's Artistic License.
  1101. Any distribution of this file or derivatives thereof I<outside>
  1102. of that package require that special arrangements be made with
  1103. copyright holder.
  1104. Irrespective of its distribution, all code examples in this file
  1105. are hereby placed into the public domain. You are permitted and
  1106. encouraged to use this code in your own programs for fun
  1107. or for profit as you see fit. A simple comment in the code giving
  1108. credit would be courteous but is not required.
  1109. =head1 ACKNOWLEDGEMENTS
  1110. Russ Albery, Jon Orwant, Randy Ray, Larry Rosler, Nat Torkington,
  1111. and Stephen Warren all contributed suggestions and corrections to this
  1112. piece. Thanks especially to Damian Conway for his ideas and feedback,
  1113. and without whose indirect prodding I might never have taken the time
  1114. to show others how much Perl has to offer in the way of objects once
  1115. you start thinking outside the tiny little box that today's "popular"
  1116. object-oriented languages enforce.
  1117. =head1 HISTORY
  1118. Last edit: Sun Feb 4 20:50:28 EST 2001