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


In reply to Re^8: I don't understand UNIVERSAL::DOES() by demerphq
in thread I don't understand UNIVERSAL::DOES() by rlb3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.