Stevan Little wrote: > Jonathan Lang wrote: > > OK. To help me get a better idea about what's going on here, what > > sorts of attributes and methods would ^Dog have? > > Well, a metaclass describes the behaviors and attributes of a class, > and ^Dog is an *instance* of the metaclass. So actually ^Dog would not > actually have attributes and methods since it is an instance.
Huh? A dog can bark; so the Dog class should have a method called 'bark'. Or does 'can' not mean what it seems to mean? > That said, I think ^Dog would probably respond to methods like > these (some of which are described in S12): OK; apparently, what I meant when I asked "what methods and attributes does ^Dog have?" is what you're talking about when you speak of which methods ^Dog will respond to. To me, an object has whatever methods that it responds to. > ^Dog.name # Dog > ^Dog.version # 0.0.1 (or something similiar of course) > ^Dog.authority # cpan:LWALL or email:[EMAIL PROTECTED] > > ^Dog.identifier # returns the string Dog-0.0.1-cpan:LWALL Would it be valid to speak of ^$spot? If so, what would ^$spot.name be? > I would like to see some methods like this: > > # dynamically add a method that > # Dog and $spot would respond to > ^Dog.add_method(bark => method () { ... }); > > Which would be like doing this in Perl 5: > > no strict 'refs'; > *{'Dog::bark'} = sub { ... }; IIRC, you can always create a new method for a class, even outside of its definition, simply by ensuring that the first parameter to be passed in will be an object of that type: method bark (Dog $_) { ... } or maybe method Dog.bark () { ... } > And of course if you can add a method, you will need to be able to > fetch and delete them as well, so a &get_method and &remove_method > would be in order as well. To fetch a method, why not have .can() return a reference to the method upon success? I might even go so far as to treat can() as an lvalue, using the assignment of a coderef as an alternate way of adding or changing the object's behavior on the fly: method bark (Dog $_:) { ... }; Dog.can("bark") = method () { ... }; # Teach the dog a new trick Dog.can("bark") = true; # inform the dog that it ought to know how to bark, without telling it how, yet; equivalent to a literal "= method { ... }". Dog.can("bark") = false; # tell the dog to forget how to bark. Dog.can("bark") = undef; # Ditto. (Doing this to Dog DWIMs to modifying the behavior of all dogs at once - you're declaring that "dogs can bark" or "this is how dogs bark", whereas doing it to $spot DWIMs to modifying the behavior of $spot only: "$brutus.can('bark') = false": my best friend's pet dog seems to have lost the capacity to bark in its old age; that doesn't mean that dogs in general can't bark.) Similar things might be done with .has (for attributes), .isa (for superclasses), and .does (for roles). -- Jonathan "Dataweaver" Lang