>>>>> "DC" == Damian Conway <[EMAIL PROTECTED]> writes:


  DC> The C<is> is actually optional wherever it can be inferred, which is handy
  DC> for chained properties:

  DC>         my $bar is Persistent Public Logged;
  DC>         ...
  DC>         return $bar is Open Smoking("non") Theme($theme);

  DC> and can also improve the euphony (eulecty???) of code:

  DC>         return undef Because($borked);

hmm, that is poor code as returning a real undef will break in a list
context. so how would a value property be attached passed back to an
empty list? what happens below:

        sub reason {

                return is Because('i said so') ;
        }

        @excuses = reason() ;
        $excuse = reason() ;
        $first_excuse = shift @excuses ;

do any of those have a Because value property?

BTW i think the clarification of permanent and value properties was well
timed. now we need to come up with both a keyword/syntax and some
standard english descriptions for them. i use value property in the
above and it works for me -it's succinct, easy to understand, and
accurate. there have been several descriptions of (my so-called)
permanent properties and none jump out at me. those are the compile time
ones for variables and subs and other non-values.

but that brings up a point, what kind of properties does an anonymous
sub carry, permanent or value? explain this code (with correct damian
syntax i hope):

        my $st_cmp = sub is SortCode('ST') { $a->[0] cmp $b->[0] } ;

        $st_cmp is SortCode('GRT') ;

what does that do or mean?

  DC> As the last example shows, within such overriding methods, there has to
  DC> be some way of accessing the actual property we're repackaging. We do
  DC> that via the builtin C<prop> property, which returns a reference to a
  DC> hash containing all the properties of a value or variable:

  DC>         $foo = 1 is Number("loneliest") Heard("ever");

  DC>         print $foo.Number;              # prints "loneliest"
  DC>         print $foo.prop{Number};        # ditto

  DC>         print keys $foo.prop;           # prints "NumberHeard"
  DC>         print values $foo.prop;         # prints "loneliestever"

and what if $foo had a method named 'prop'? shouldn't there be an out of
band way of accessing that propery hash? why not also have a special
function (not using method/prop syntax)

        $foo_prop = value_props( $foo ) ;
        $foo_var_prop = perm_props( $foo ) ;

those return hash refs to the value and permanent (variable/sub)
props. in a hash or list context they return the key/value list.

also these can be used to access individual properties with the property
name as the optional second argument and the value(s) as the optional
list after that.

        $sort_code = value_props( $foo, 'SortCode' ) ;
        perm_props( $foo, 'SortCode', 'ST' ) ;
        perm_props( $foo, 'SortCode' ) = 'ST' ;

the last one assigns the prop value with an lvalue call.

most of the time the . form should used but having these funcs supported
means you can always be explicit about what you want and you can bypass
any bizarro names that are in your object tree.


  DC>         my $var is Purpose("var demo") = 1 is Purpose("val demo");

  DC>         print $var.Purpose;     # prints "var demo", not "val demo"
  DC> the variable first:

or use perm_props( $foo, 'Purpose' ) ;


  DC>         print (+$var).Purpose;  # prints "val demo", not "var demo"

or use value_props( $foo, 'Purpose' ) ;

uri

-- 
Uri Guttman  ---------  [EMAIL PROTECTED]  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html

Reply via email to