note
TheDamian
The <code>is</code> keyword tells a declaration that it has certain properties. The behaviour of each of those properties is specified as a distinct class (hereafter called a "property class"). A property class has certain special methods (hereafter called "property methods") that determine what effect the property has on the referent to which it is applied.
<p>So, for example, a built-in property class like <code>class dim</code> has property methods that modify the dimensionality of the underlying <code>Array</code> referent that an <code>is dim</code> property is applied to.
<p>Whereas a built-in property class like <code>class constant</code> has property methods that modify the writeability of the referent that the property is applied to.
<p>Similarly, a user-defined class such as <code>class Persistent</code> might have user-defined property methods that modify the persistence behaviour of any referent to which the <code>is Persistent</code> property is applied.
<p>If a user-defined class (say, <code>class Foo</code>) <i>doesn't</i> have explicit property methods, it automatically has implicit property methods (which it inherits from the <code>Class</code> meta-class). Those inherited methods cause <code>class Foo</code> to modify -- in one of two ways -- any referent to which the <code>is Foo</code> property is applied.
<p>If <code>is Foo</code> is applied to a <b>class</b> (say <code>Bar</code>), <code>class Foo</code>'s property methods add <code>Foo</code> to the list of <code>class Bar</code>'s ancestors.
Thus:
<code>
class Bar is Foo {...}
</code>
is how we do inheritance.
<p>On the other hand, if <code>is Foo</code> is applied to a <b>non-type</b> (say <code>$bar</code>), <code>Foo</code>'s property methods replace the implementation type of <code>$bar</code> (i.e. <code>Scalar</code>) with the implementation type <code>Foo</code>.
Thus:
<code>
my $bar is Foo;
</code>
is how we do tying.
<p>So this one property mechanism gives us a wide range of useful language features (i.e. type qualification, referent modification, inheritance, tying) from a single underlying behaviour (namely, apply certain methods of this property class to the referent of this declaration).
285042
285042