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

Roles are interfaces. Thats it. There is nothing more to them than that. Dereferencability of an object is simply an interface into that object. Therefore its a role the object can play.

So all regexs would be do the REGEX (or Regexp if you want to split hairs) role.

Its not splitting hairs. Whether a reference contains regexp magic is orthagonal to whether it is a member of any given class. Historically we marked all such references as being in class 'Regexp', however there is no requirement that this is true. A reblessed qr// unless the programmer does it deliberately is not isa('Regexp'). Therefore class is an inappropriate way to determine if an object can fulfil this role.

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.

Except that again this is not a necessary requirement, and indeed is one that is potentially dangerous. If I create an object that overloads array dereferencing then it can be used an array, regardless as to whether it has an isa relationship to the class 'ARRAY', in fact unblessed arrays themselves have NO isa relationship to 'ARRAY', this is an artifical artifact of how UNIVERSAL::isa() behaves. In addition /any/ object regardless of is type can be a member or subclass of 'ARRAY' without being dereferencable as an array, therefore 'ARRAY' is an inappropriate test to see if you can dereference an object as an array.

my $nasty = bless sub{},'ARRAY'; my $anon = []; if (UNIVERSAL::isa($anon,'ARRAY') == $nasty->isa('ARRAY')) { print "isa says both are related to 'ARRRAY'" }

Now if you happened to actually define an 'ARRAY' class then perhaps this question would make sense, maybe there would be a reason to bless a subroutine into the class 'ARRAY', maybe you are using blessed closures as the implementation of a custom 'ARRAY' class. Whatever, the point is that being isa() 'ARRAY' isnt going to tell you with an certainty if the item actually can be dereferenced as an array. Or in other words does not tell you whether the array can play the role of an array reference.

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