3 ms·
I don't really get what is different with Perl and the other scripting languages for types, but check Moose. E.g. http://search.cpan.org/~ether/Moose-2.1210/li
by BugBrother 12y ago
I don't really get what is different with Perl and the other scripting languages for types, but check Moose.
E.g. http://search.cpan.org/~ether/Moose-2.1210/lib/Moose/Cookbook/Basics/Company_Subtypes.pod http://search.cpan.org/~ether/Moose-2.1210/lib/Moose/Cookboo...
Quite OK for one of the scripting languages, imho.
has 'employees' => (
is => 'rw',
isa => 'ArrayRef[Employee]'
default => sub { [] },
);
- krylon 12y agoYeah, learning Moose has been on my todo-list for a while now. Back when I still used Perl almost exclusively, I hardly did any object-oriented programming in it, and when I did, it felt awkward. Moose looks like a game changer, both for OOP in Perl and for typing. Right now, I have a lot on my plate, but once my schedule clears up a little, I will look into it. Thanks for the hint! (For sysadmin-scripting, non-OOP Perl is entirely sufficient, though.)
- simcop2387 12y agoYou should also check out Moo[2] and Mouse[1]. They both try to be simpler versions of Moose without the compile-time (and runtime) performance issues of Moose. They do that by dropping some things like metaobject protocols and other things that are great for introspection but may not be something you really care too much about. They both try hard to keep syntactically the same as Moose when possible so that you can most of the time use them all interchangeably. [1]http://search.cpan.org/~gfuji/Mouse-2.3.0/lib/Mouse.pm http://search.cpan.org/~gfuji/Mouse-2.3.0/lib/Mouse.pm [2]http://search.cpan.org/~haarg/Moo-1.005000/lib/Moo.pm http://search.cpan.org/~haarg/Moo-1.005000/lib/Moo.pm
- kbenson 12y agoAdditionally, Moops[1] may be useful to get some extra sugar going. It's a meta module that includes a few other modules to give you a sane (Moose/Moo) object model, plus function and method signatures through Method::Signatures. For example: use Moops; role NamedThing { has name => (is => "ro", isa => Str); } class Person with NamedThing; class Company with NamedThing; class Employee extends Person { has job_title => (is => "rwp", isa => Str); has employer => (is => "rwp", isa => InstanceOf["Company"]); method change_job ( Object $employer, Str $title ) { $self->_set_job_title($title); $self->_set_employer($employer); } method promote ( Str $title ) { $self->_set_job_title($title); } } [1] https://metacpan.org/pod/Moops https://metacpan.org/pod/Moops