Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOES vs ISA in UNIVERSAL

Tags:

oop

perl

I've never seen DOES in a Perl program before, and yet there it is in the docs on universal.

I don't understand completely what the difference between DOES and ISA is, though. The specification speaks of roles, perhaps accomplished through aggregation, delegation and mocking. The only kind of class relationship that I know about in Perl is inheritance through the @ISA array (or by using parent or base), and I think of roles as only being available with Moose and the like. The documentation also says that most of the time DOES and ISA will be the same thing.

Can you give an example where DOES and ISA return the different values? What is the practical difference between these two methods?

like image 229
Nate Glenn Avatar asked Nov 09 '13 00:11

Nate Glenn


1 Answers

When you use roles. UNIVERSAL::DOES behaves the same as UNIVERSAL::isa, but Moose, Mouse, and Moo all provide DOES methods on their object classes that return true for classes that consume a given role.

like image 196
hobbs Avatar answered Oct 04 '22 15:10

hobbs