in reply to Re^3: I don't understand UNIVERSAL::DOES()
in thread I don't understand UNIVERSAL::DOES()

Wouldn't it be better if the role names matched the ref? I.e. CODE,ARRAY,HASH,REGEX ?

No. For reasons i explained in my reply to chromatic. And 'REGEX' isnt a type. You will never see it returned from ref() or reftype(). Also, your code doesnt solve the "can i deref this item in a particular way" problem, nor the "does this reference contain regexp magic" problem.

As for code, yeah, once i get it done ill post it. Currently its a work in progress.

---
$world=~s/war/peace/g

  • Comment on Re^4: I don't understand UNIVERSAL::DOES()

Replies are listed 'Best First'.
Re^5: I don't understand UNIVERSAL::DOES()
by eric256 (Parson) on Mar 10, 2007 at 15:03 UTC

    I wasn't thinking of those as types (and it wasn't meant as a final product, just an example of the way i was thinking about roles and does), I was thinking of them as roles since we are talking about does, and does talks about roles. If something reports that it does a role then its that somethings responsibility to insure it does. SO if i create a class that claims it does 'ARRAY' then it is my class's responsibility to insure that it can do everything that role entails. I see now reading your reply to chromatic that you aren't realy talking about roles at all which is where the disconnect is.

    If we assume that DOES is for roles, why not overload ->can to do what you want?. You do a role, but you can a method. So if you wanted to ask if you can dereference it as an array you ask if it <cdoe>->can($obj, '@{}')</code> to me that seems to follow your overloading style better as it doesn't imply that '@()' is a role, but actually that it is a method, which it is if you've overloaded it.


    ___________
    Eric Hodges

      I wasn't thinking of those as types (and it wasn't meant as a final product, just an example of the way i was thinking about roles and does), I was thinking of them as roles since we are talking about does, and does talks about roles.

      A given mode of dereferencing an object is merely an interface to that object. And as its an interface its a role. "Can i treat reference $x as a reference to an array?" could equally be thought of "can $x play the role of an array?".

      ---
      $world=~s/war/peace/g

        I always thought of roles as abstract sets of characteristics and not the individual characteritics. So all regexs would be do the REGEX (or Regexp if you want to split hairs) role. That implies that it can be used as a regex just like things that do the ARRAY role are arrays. Dereferencing isn't a role, its a part of a role and it all then depends on how you actualy define the roles. If you as anything that reports to do ARRAY has to be able to be dereferenced as an array then you don't need @{} and ARRAY you just need ARRAY. Like i said before if you are asking about one specific method (derferncing or otherwise) wouldn't you wan to use 'can'? I think a generic "what do you claim to do?" and can is a "what have you actualy implemented" and i think joining the two concepts is more magical and confusing than needed.


        ___________
        Eric Hodges